From 4d61fc52f07f507987b3487a1170e8e5993f0b4b Mon Sep 17 00:00:00 2001 From: wuchen Date: Tue, 14 Jul 2020 16:03:17 +0800 Subject: [PATCH] release python sdk 1.0.24 --- PKG-INFO | 8 ++--- examples/rds/v3/database.py | 39 +++++++++++++++++++++++ openstack/rds/v3/_proxy.py | 60 +++++++++++++++++++++++++++++++++--- openstack/rds/v3/database.py | 47 ++++++++++++++++++++++++++++ openstack/rds/v3/instance.py | 2 +- openstack/session.py | 2 +- 6 files changed, 147 insertions(+), 11 deletions(-) create mode 100644 examples/rds/v3/database.py create mode 100644 openstack/rds/v3/database.py diff --git a/PKG-INFO b/PKG-INFO index 0a4fff4..b0b0a83 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -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: "hwcloudsdk@huawei.com" +License: Apache LICENSE 2.0 Description: Python SDK for Cloud Platform: UNKNOWN diff --git a/examples/rds/v3/database.py b/examples/rds/v3/database.py new file mode 100644 index 0000000..a0ce46f --- /dev/null +++ b/examples/rds/v3/database.py @@ -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)) diff --git a/openstack/rds/v3/_proxy.py b/openstack/rds/v3/_proxy.py index 6b54d79..2bcd7cb 100644 --- a/openstack/rds/v3/_proxy.py +++ b/openstack/rds/v3/_proxy.py @@ -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): @@ -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 @@ -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 @@ -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) \ No newline at end of file + 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) diff --git a/openstack/rds/v3/database.py b/openstack/rds/v3/database.py new file mode 100644 index 0000000..f62d5f2 --- /dev/null +++ b/openstack/rds/v3/database.py @@ -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 diff --git a/openstack/rds/v3/instance.py b/openstack/rds/v3/instance.py index 79a332c..81ff9b9 100644 --- a/openstack/rds/v3/instance.py +++ b/openstack/rds/v3/instance.py @@ -270,4 +270,4 @@ class InstanceRestoreTime(_rdsresource.Resource): # Error log data time datetime = resource.Body('datetime') #: Error log content - content = resource.Body('content') \ No newline at end of file + content = resource.Body('content') diff --git a/openstack/session.py b/openstack/session.py index 79eb0ca..855f3fa 100644 --- a/openstack/session.py +++ b/openstack/session.py @@ -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) \ No newline at end of file