-
Notifications
You must be signed in to change notification settings - Fork 297
Added DO Database endpoints #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MSAdministrator
wants to merge
2
commits into
koalalorenzo:main
Choose a base branch
from
MSAdministrator:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from .baseapi import BaseAPI, POST, DELETE, PUT | ||
|
|
||
| __SIZE_SLUG__ = [ | ||
| 'db-s-1vcpu-1gb', | ||
| 'db-s-1vcpu-2gb', | ||
| 'db-s-2vcpu-4gb', | ||
| 'db-s-4vcpu-8gb', | ||
| 'db-s-6vcpu-16gb', | ||
| 'db-s-8vcpu-32gb', | ||
| 'db-s-16vcpu-64gb' | ||
| ] | ||
|
|
||
| __DB_ENGINES__ = { | ||
| 'pq': { | ||
| 'versions': ['10','11'] | ||
| }, | ||
| 'mysql': { | ||
| 'versions': ['8'] | ||
| }, | ||
| 'redis':{ | ||
| 'versions': ['5'] | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class DatabaseCreate(BaseAPI): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(DatabaseCreate, self).__init__(*args, **kwargs) | ||
|
|
||
|
|
||
| def cluster(self, name, engine, size, region, num_nodes, version=None, tags=None): | ||
| if __DB_ENGINES__[engine]: | ||
| params = { | ||
| "name": name, | ||
| "engine": engine, | ||
| "size": size, | ||
| "region": region, | ||
| "num_nodes": int(num_nodes) | ||
| } | ||
| if version: | ||
| if version in __DB_ENGINES__[engine]['versions']: | ||
| params['version'] = version | ||
| else: | ||
| raise AttributeError('Please provide a valid database version') | ||
| if tags and isinstance(tags, list): | ||
| params['tags'] = tags | ||
|
|
||
| data = self.get_data('databases/', type=POST, params=params) | ||
|
|
||
| if data: | ||
| return data['database'] | ||
| else: | ||
| return 'Error creating database' | ||
|
|
||
| def replica(self, name, size, region=None, tags=None, db_id=None): | ||
| params = {} | ||
| params['name'] = name | ||
| if size in __SIZE_SLUG__: | ||
| params['size'] = size | ||
| if region: | ||
| params['region'] = region | ||
| if tags: | ||
| params['tags'] = tags | ||
|
|
||
| if db_id: | ||
| data = self.get_data("databases/{}/replicas".format(db_id), type='POST', params=params) | ||
| else: | ||
| data = self.get_data("databases/{}/replicas".format(self.id), type='POST', params=params) | ||
|
|
||
| if data: | ||
| return data['replica'] | ||
| else: | ||
| return 'Error creating replica' | ||
|
|
||
| def user(self, name, db_id=None): | ||
| params = {} | ||
| params['name'] = name | ||
|
|
||
| if db_id: | ||
| data = self.get_data("databases/{}/users".format(db_id), type='POST', params=params) | ||
| else: | ||
| data = self.get_data("databases/{}/users".format(self.id), type='POST', params=params) | ||
|
|
||
| if data: | ||
| return data['users'] | ||
| else: | ||
| return 'Error creating users' | ||
|
|
||
| def database(self, name, db_id=None): | ||
| params = {} | ||
| params['name'] = name | ||
|
|
||
| if db_id: | ||
| data = self.get_data("databases/{}/dbs".format(db_id), type='POST', params=params) | ||
| else: | ||
| data = self.get_data("databases/{}/dbs".format(self.id), type='POST', params=params) | ||
|
|
||
| if data: | ||
| return data['db'] | ||
| else: | ||
| return 'Error creating database' | ||
|
|
||
|
|
||
| class DatabaseList(BaseAPI): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(DatabaseList, self).__init__(*args, **kwargs) | ||
|
|
||
| def clusters(self, tag_name=None): | ||
| if tag_name: | ||
| data = self.get_data("databases?tag_name={}".format(tag_name)) | ||
| else: | ||
| data = self.get_data("databases") | ||
| return None if not data else data['databases'] | ||
|
|
||
| def backups(self, db_id): | ||
| data = self.get_data("databases/{}/backups".format(db_id)) | ||
| return None if not data else data['backups'] | ||
|
|
||
| def replicas(self, db_id): | ||
| data = self.get_data("databases/{}/replicas".format(db_id)) | ||
| return None if not data else data['replicas'] | ||
|
|
||
| def users(self, db_id): | ||
| data = self.get_data("databases/{}/users".format(db_id)) | ||
| return None if not data else data['users'] | ||
|
|
||
| def databases(self, db_id): | ||
| data = self.get_data("databases/{}/dbs".format(db_id)) | ||
| return None if not data else data['dbs'] | ||
|
|
||
|
|
||
| class DatabaseGet(BaseAPI): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(DatabaseGet, self).__init__(*args, **kwargs) | ||
|
|
||
| def cluster(self, db_id): | ||
| data = self.get_data("databases/{}".format(db_id)) | ||
| return None if not data else data['database'] | ||
|
|
||
| def replica(self, db_id, replica_name): | ||
| data = self.get_data("databases/{}/replicas/{}".format(db_id, replica_name)) | ||
| return None if not data else data['replica'] | ||
|
|
||
| def user(self, db_id, username): | ||
| data = self.get_data("databases/{}/users/{}".format(db_id, username)) | ||
| return None if not data else data['user'] | ||
|
|
||
|
|
||
| class DatabaseDestroy(BaseAPI): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(DatabaseDestroy, self).__init__(*args, **kwargs) | ||
|
|
||
| def cluster(self, db_id): | ||
| data = self.get_data("databases/{}".format(db_id), type='DELETE') | ||
| return None if not data else True | ||
|
|
||
| def replica(self, db_id, replica_name): | ||
| data = self.get_data("databases/{}/replicas/{}".format(db_id, replica_name), type='DELETE') | ||
| return None if not data else True | ||
|
|
||
| def user(self, db_id, username): | ||
| data = self.get_data("databases/{}/users/{}".format(db_id, username), type='DELETE') | ||
| return None if not data else True | ||
|
|
||
| def database(self, db_id, db_name): | ||
| data = self.get_data("databases/{}/dbs/{}".format(db_id, db_name), type='DELETE') | ||
| return None if not data else True | ||
|
|
||
| class Database(BaseAPI): | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(Database, self).__init__(*args, **kwargs) | ||
| self.args = args | ||
| self.kwargs = kwargs | ||
| pass | ||
|
|
||
| @property | ||
| def create(self): | ||
| return DatabaseCreate(*self.args, **self.kwargs) | ||
|
|
||
| @property | ||
| def destroy(self): | ||
| return DatabaseDestroy(*self.args, **self.kwargs) | ||
|
|
||
| @property | ||
| def list(self): | ||
| return DatabaseList(*self.args, **self.kwargs) | ||
|
|
||
| @property | ||
| def get(self): | ||
| return DatabaseGet(*self.args, **self.kwargs) | ||
|
|
||
| def resize(self, size, num_nodes, db_id): | ||
| params = {} | ||
| if size in __SIZE_SLUG__: | ||
| params['size'] = size | ||
| params['num_nodes'] = int(num_nodes) | ||
| data = self.get_data('databases/{}/resize'.format(db_id), type='PUT', params=params) | ||
| return None if not data else True | ||
|
|
||
| def migrate(self, region, db_id): | ||
| params = {} | ||
| params['region'] = region | ||
| data = self.get_data('databases/{}/migrate'.format(db_id), type='PUT', params=params) | ||
| return None if not data else True | ||
|
|
||
| def maintenance(self, day, hour, db_id): | ||
| params = {} | ||
| params['day'] = day | ||
| params['hour'] = hour | ||
| data = self.get_data('databases/{}/maintenance'.format(db_id), type='PUT', params=params) | ||
| return None if not data else True | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.