Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
release python sdk 1.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchen-huawei committed Jul 14, 2020
1 parent 87f2812 commit 4d61fc5
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 11 deletions.
8 changes: 4 additions & 4 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Metadata-Version: 1.1
Name: huaweicloud-sdk-python
Version: 1.0.23
Version: 1.0.24
Summary: An SDK for building applications to work with OpenStack
Home-page: https://github.com/huaweicloud/huaweicloud-sdk-python
Author: huawei
Author-email:
License: UNKNOWN
Author: "HuaweiCloud SDK"
Author-email: "[email protected]"
License: Apache LICENSE 2.0
Description: Python SDK for Cloud

Platform: UNKNOWN
Expand Down
39 changes: 39 additions & 0 deletions examples/rds/v3/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from openstack import connection


projectId = "xxxxxxxxxxxxxx"
cloud = "xxxxxxxxxxxxxx" # cdn use: cloud = "myhwclouds.com"
region = "xxxxxxxxxxxxxx" # example: region = "cn-north-1"
AK = "xxxxxxxxxxxxxx"
SK = "xxxxxxxxxxxxxx"
connect = connection.Connection(
project_id=projectId,
cloud=cloud,
region=region,
ak=AK,
sk=SK)


def databases(conn):
instance_id = 'xxxxxxxxxxxxxxxxxxxxxxx'
query = {
'page': 1,
'limit': 10
}
for database in conn.rdsv3.databases(instance_id, details=True, **query):
print(database)


def create_database(conn):
database = {
"name": 'test_db1',
"character_set": 'utf8'
}
instance_id = 'xxxxxxxxxxxxxxxxxxxxxxx'
print(conn.rdsv3.create_database(instance_id=instance_id, **database))


def delete_database(conn):
database_name = 'test_db1'
instance_id = 'xxxxxxxxxxxxxxxxxxxxxxx'
print(conn.rdsv3.delete_database(database_name, instance_id))
60 changes: 55 additions & 5 deletions openstack/rds/v3/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from openstack.rds.v3 import instance as _instance
from openstack.rds.v3 import rdsversion as _version
from openstack.rds.v3 import configuration as _configurations
from openstack.rds.v3 import database as _database


class Proxy(proxy2.BaseProxy):
Expand Down Expand Up @@ -339,7 +340,6 @@ def get_parameter(self, datastore, name):
return self._get(_datastore.Parameter, name,
datastore_version_id=datastore_version_id)


def get_rds_version(self,version):
"""Get version by id
Expand All @@ -353,11 +353,8 @@ def get_rds_version(self,version):
else:
version_id = version



return self._get(_version.rdsverion,version_id)


def list_rds_version(self):
"""Get instance by id
Expand All @@ -366,4 +363,57 @@ def list_rds_version(self):
:returns: The results of instance
:rtype: :class:`~openstack.rds.v1.instance.Instance`.
"""
return self._list(_version.rdsverion, paginated=False)
return self._list(_version.rdsverion, paginated=False)

def create_database(self, **kwargs):
"""Create a new database from attributes
:param dict kwargs: Keyword arguments which will be used to create
a :class:`~openstack.rds.v3.database.Database`,
comprised of the properties on the Database class.
:returns: The results of server creation
:rtype: :class:`~openstack.database.v3.database.Database`
"""
return self._create(_database.Database, **kwargs)

def delete_database(self, database, instance=None, ignore_missing=True):
"""Delete a database
:param database: The value can be either the name of a database or a
:class:`~openstack.rds.v3.database.Database` instance.
:param instance: This can be either the ID of an instance
or a :class:`~openstack.database.v3.instance.Instance`
instance that the interface belongs to.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the database does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent database.
:returns: ``None``
"""
instance = self._get_resource(_instance.Instance, instance)
self._delete(_database.Database, database, instance_id=instance.id,
ignore_missing=ignore_missing)

def databases(self, instance, details=True, **query):
"""Return a generator of databases
:param details: When ``True``, returns
:class:`~openstack.rds.v3.database.DatabaseDetail` objects,
otherwise :class:`~openstack.rds.v3.database.Database`.
*Default: ``True``*
:param instance: This can be either the ID of an instance
or a :class:`~openstack.rds.v3.instance.Instance`
instance that the interface belongs to.
:param kwargs \*\*query: Optional query parameters to be sent to limit
the resources being returned.
:returns: A generator of database objects
:rtype: :class:`~openstack.database.v3.database.Database`
"""
instance = self._get_resource(_instance.Instance, instance)
res_type = _database.DatabaseDetail if details else _database.Database
return self._list(res_type, paginated=False,
instance_id=instance.id, **query)
47 changes: 47 additions & 0 deletions openstack/rds/v3/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding:utf-8 -*-
# Copyright 2019 Huawei Technologies Co.,Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use
# this file except in compliance with the License. You may obtain a copy of the
# License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from openstack.rds import rds_service
from openstack.rds.v3 import rdsresource as _rdsresource
from openstack import resource2 as resource


class Database(_rdsresource.Resource):
base_path = 'instances/%(instance_id)s/database'
resources_key = 'databases'
service = rds_service.RDSServiceV3()

_query_mapping = resource.QueryParameters('page', 'limit')

# capabilities
allow_create = True
allow_delete = True
allow_list = True

# Properties
# instanceId
instance_id = resource.URI('instance_id')
# database name
name = resource.Body("name")
# database character_set
character_set = resource.Body("character_set")


class DatabaseDetail(Database):
base_path = 'instances/%(instance_id)s/database/detail'

# capabilities
allow_create = False
allow_delete = False
allow_list = True
2 changes: 1 addition & 1 deletion openstack/rds/v3/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ class InstanceRestoreTime(_rdsresource.Resource):
# Error log data time
datetime = resource.Body('datetime')
#: Error log content
content = resource.Body('content')
content = resource.Body('content')
2 changes: 1 addition & 1 deletion openstack/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,4 @@ def request(self, *args, **kwargs):
# Fix MRS service require *Content-Type* header in GET request
headers = kwargs.setdefault('headers', dict())
headers.setdefault('Content-Type', 'application/json')
return super(Session, self).request(*args, **kwargs)
return super(Session, self).request(*args, **kwargs)

0 comments on commit 4d61fc5

Please sign in to comment.