diff --git a/LICENSE b/LICENSE index 261eeb9..8d55ceb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -173,29 +174,20 @@ incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - Copyright [yyyy] [name of copyright owner] +Huawei has modified some source files which you can find the license update in +the files. - 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 +Copyright 2018 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 + 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. +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. diff --git a/PKG-INFO b/PKG-INFO index 61f3f28..e47fdba 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: huaweicloud-sdk-python -Version: 1.0.6 +Version: 1.0.9 Summary: An SDK for building applications to work with OpenStack Home-page: https://github.com/huaweicloud/huaweicloud-sdk-python Author: HUAWEICLOUD diff --git a/examples/anti_ddos/__init__.py b/examples/anti_ddos/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/anti_ddos/anti_ddos.py b/examples/anti_ddos/anti_ddos.py deleted file mode 100644 index fe7f471..0000000 --- a/examples/anti_ddos/anti_ddos.py +++ /dev/null @@ -1,89 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing anti-ddos - -""" - -FLOATING_IP_ID = '11ee0ec8-2b4f-438d-8235-dd22a3effa46' - - -def list_config(conn): - print("list anti-ddos confit") - print(conn.anti_ddos.query_config_list()) - - -def list_eips(conn): - print("list eips by status") - print(conn.anti_ddos.list_eips(status='packetcleaning')) - - -def create_eip(conn): - fip_dict = {'enable_L7': True, - 'traffic_pos_id': 1, - 'http_request_pos_id': 1, - 'cleaning_access_pos_id': 1, - 'app_type_id': 0} - - fip = conn.anti_ddos.create_floating_ip(FLOATING_IP_ID, **fip_dict) - print(fip) - - -def update_eip(conn): - fip = conn.anti_ddos.get_floating_ip(FLOATING_IP_ID) - - fip_update_dict = {'enable_L7': False, - 'traffic_pos_id': 1, - 'http_request_pos_id': 1, - 'cleaning_access_pos_id': 1, - 'app_type_id': 0} - ufip = conn.anti_ddos.update_floating_ip(fip, **fip_update_dict) - print(ufip) - - -def delete_eip(conn): - fip = conn.anti_ddos.get_floating_ip(FLOATING_IP_ID) - conn.anti_ddos.delete_floating_ip(fip) - - -def query_task_status(conn): - # query_task_status requires to provide task_id, task_id is only - # returned by create_eip, after create_eip, we get a FloatingIP object - # get task_id by FloatingIP.task_id - print(conn.anti_ddos.query_task_status( - '4a4fefe7-34a1-40e2-a87c-16932af3ac4a')) - - -def get_eip_status(conn): - print(conn.anti_ddos.get_eip_status(FLOATING_IP_ID)) - - -def get_eip_daily(conn): - for d in conn.anti_ddos.list_eip_daily(FLOATING_IP_ID): - print(d) - - -def get_eip_log(conn): - for l in conn.anti_ddos.list_eip_log(FLOATING_IP_ID): - print(l) - - -def get_eip_weekly(conn): - print(conn.anti_ddos.get_eip_weekly('1006510306')) - - -def get_alert_config(conn): - # NOTEs: this is v2 api - print(conn.anti_ddos.get_alert_config()) diff --git a/examples/auto_scaling/__init__.py b/examples/auto_scaling/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/auto_scaling/configs.py b/examples/auto_scaling/configs.py deleted file mode 100644 index 5a65f33..0000000 --- a/examples/auto_scaling/configs.py +++ /dev/null @@ -1,74 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - -from openstack import utils - - -def list_configs(conn): - query = { - "name": "config-name", - "image_id": "some-image-id", - "limit": 10, - "marker": 20 - } - for config in conn.auto_scaling.configs(**query): - logging.info(config) - - -def get_config(conn): - config_id = "some-config-id" - config = conn.auto_scaling.get_config(config_id) - logging.info(config) - - -def create_config(conn): - flavor_id = "" - image_id = "" - key_name = "" - _config = { - "flavor_id": flavor_id, - "image_id": image_id, - "disk": [{ - "size": 40, - "volume_type": "SATA", - "disk_type": "SYS" - }], - "personality": [{ - "path": "/etc/p1.txt", - "content": utils.b64encode("p1") - }, { - "path": "/etc/p2.txt", - "content": utils.b64encode("p2") - }], - "metadata": { - "tag": "app", - "node": "node2" - }, - "key_name": key_name - } - config = conn.auto_scaling.create_config("some-config-name", - **_config) - logging.info(config) - - -def delete_config(conn): - config_id = "some-config-id" - conn.auto_scaling.delete_config(config_id) - - -def batch_delete_config(conn): - ids = ["config-id-1", "config-id-2"] - conn.auto_scaling.batch_delete_configs(ids) diff --git a/examples/auto_scaling/groups.py b/examples/auto_scaling/groups.py deleted file mode 100644 index 4802fc0..0000000 --- a/examples/auto_scaling/groups.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - -from openstack import utils - - -def list_groups(conn): - query = { - "name": "any-as-group-name", - "status": "INSERVICE", # INSERVICE,PAUSED,ERROR - "scaling_configuration_id": "as-config-id", - "marker": 0, - "limit": 20 - } - groups = conn.auto_scaling.groups(**query) - for group in groups: - logging.info(group) - - -def get_group(conn): - group_id = "some-group-id" - group = conn.auto_scaling.get_group(group_id) - logging.info(group) - - -def create_group(conn): - flavor_id = "" - image_id = "" - key_name = "" - _group = { - "flavor_id": flavor_id, - "image_id": image_id, - "disk": [{ - "size": 40, - "volume_type": "SATA", - "disk_type": "SYS" - }], - "personality": [{ - "path": "/etc/p1.txt", - "content": utils.b64encode("p1") - }, { - "path": "/etc/p2.txt", - "content": utils.b64encode("p2") - }], - "metadata": { - "tag": "app", - "node": "node2" - }, - "key_name": key_name - } - group = conn.auto_scaling.create_group("some-group-name", - **_group) - logging.info(group) - - -def delete_group(conn): - group_id = "some-group-id" - conn.auto_scaling.delete_group(group_id) - - -def batch_delete_group(conn): - ids = ["group-id-1", "group-id-2"] - conn.auto_scaling.batch_delete_groups(ids) diff --git a/examples/auto_scaling/lifecycle_hook.py b/examples/auto_scaling/lifecycle_hook.py deleted file mode 100644 index 34ad519..0000000 --- a/examples/auto_scaling/lifecycle_hook.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def get_as_hook(conn): - group_id = '' - lifecycle_hook = 'lifecycle_hook_name' - ff = conn.auto_scaling.get_lifecycle_hook(group_id, lifecycle_hook=lifecycle_hook) - print ff - - -def get_as_hook_list(conn): - group_id = '' - ff = conn.auto_scaling.lifecycle_hooks(group_id) - for i in ff: - print i - - -def create_as_hook(conn): - group_id = '' - data = { - "lifecycle_hook_name": "test-kFaas2", - "default_result": "ABANDON", - "default_timeout": 3600, - "notification_topic_urn": "urn:smn:eu-de:054efa20ee69a64785a196efe56c05ee74:test_as", - "lifecycle_hook_type": "INSTANCE_LAUNCHING" - } - ff = conn.auto_scaling.create_lifecycle_hook(group=group_id, **data) - print ff - - -def modify_lifecycle_hook(conn): - group_id = '' - lifecycle_hook = 'lifecycle_hook_name' - data = {'default_timeout': 15030} - ff = conn.auto_scaling.update_lifecycle_hook(group=group_id, lifecycle_hook=lifecycle_hook, **data) - print ff - - -def delete_lifecycle_hook(conn): - group_id = '' - lifecycle_hook = 'lifecycle_hook_name' - ff = conn.auto_scaling.delete_lifecycle_hook(group_id, lifecycle_hook=lifecycle_hook) - print ff - - -def get_instances(conn): - group_id = '' - ff = conn.auto_scaling.get_group_hanging_instance(group_id) - for i in ff: - print i - - -def call_back(conn): - group_id = '' - data = { - "lifecycle_action_result": "EXTEND", - "lifecycle_action_key": "your action key" - } - - ff = conn.auto_scaling.call_back_instance(group_id, **data) - print ff diff --git a/examples/auto_scaling/notifications.py b/examples/auto_scaling/notifications.py deleted file mode 100644 index 8c2846d..0000000 --- a/examples/auto_scaling/notifications.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def test_create_notification(conn): - group = '7f6fe6bd-6615-44e6-858a-b8b66507083a' - data = { - "topic_urn": "urn:smn:eu-de:054efa2069a64785a196efe56c05ee74:test_as", - "topic_scene": [ - "SCALING_UP", "SCALING_UP_FAIL", "SCALING_DOWN", "SCALING_DOWN_FAIL", "SCALING_GROUP_ABNORMAL" - ] - } - - ff = conn.auto_scaling.create_notification(group=group, **data) - print ff - - -def test_list_notifications(conn): - group = '7f6fe6bd-6615-44e6-858a-b8b66507083a' - - ff = conn.auto_scaling.notifications(group=group) - for i in ff: - print i - - -def test_delete_notification(conn): - group = '7f6fe6bd-6615-44e6-858a-b8b66507083a' - topic = 'urn:smn:eu-de:054efa2069a64785a196efe56c05ee74:test_as' - - ff = conn.auto_scaling.delete_notification(group=group, topic=topic) - print ff diff --git a/examples/auto_scaling/tag.py b/examples/auto_scaling/tag.py deleted file mode 100644 index 1d075cd..0000000 --- a/examples/auto_scaling/tag.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def test_get_tags(conn): - ff = conn.auto_scaling.get_tags() - for i in ff: - print i - - -def test_get_resource_tags(conn): - group = '7f6fe6bd-6615-44e6-858a-b8b66507083a' - ff = conn.auto_scaling.get_group_tags(group=group) - for i in ff: - print i - - -def test_update_tags(conn): - group = '7f6fe6bd-6615-44e6-858a-b8b66507083a' - data = { - "tags": [ - { - "key": "ENV15", - "value": "ENV15" - }, - { - "key": "ENV151", - "value": "ENV151" - } - ], - "action": "delete" - } - - ff = conn.auto_scaling.tag_action(group=group, **data) - print ff - diff --git a/examples/bms/__init__.py b/examples/bms/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/bms/server.py b/examples/bms/server.py deleted file mode 100644 index b6b6240..0000000 --- a/examples/bms/server.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def create_server(conn): - data = { - "availability_zone": "az1.dc1", - "name": "newserverkak", - "imageRef": "ad134bba-dfca-4aa1-a307-26b51e4c608b", - "root_volume": { - "volumetype": "SATA" - }, - "data_volumes": [ - { - "volumetype": "SATA", - "size": 50 - }, - { - "volumetype": "SSD", - "size": 10, - "multiattach": "true", - "hw:passthrough": "false" - } - ], - "isAutoRename": "true", - "flavorRef": "c1.xlarge", - "personality": [ - { - "path": "/etc/banner.txt", - "contents": "ICAgICAgDQoiQmFjaA==" - } - ], - "security_groups": [ - { - "id": "53234334-9c3d-4344-b577-2cdd6c244707" - } - ], - "vpcid": "5b2a6c9a-093d-4d56-8889-a7917e44229c", - "nics": [ - { - "subnet_id": "a8f622a7-0d10-470e-ae80-c8e0e8bc7d12" - } - ], - "publicip": { - "eip": { - "iptype": "5_bgp", - "bandwidth": { - "size": 1, - "sharetype": "PER" - } - } - }, - "key_name": "KeyPair-1565", - "count": 1, - "metadata": { - "ss": "ss" - }, - "extendparam": { - "chargingMode": "postPaid", - "periodType": "month", - "periodNum": 1, - "isAutoRenew": "true", - "isAutoPay": "true", - "regionID": "southchina" - }, - "os:scheduler_hints": { - "group": "cc10d0d1-d371-4f33-9452-fd5fbf14dc06" - } - } - - ff = conn.bms.create_server(**data) - print ff diff --git a/examples/cdn/Domain.py b/examples/cdn/Domain.py index 469f93e..f60b37e 100644 --- a/examples/cdn/Domain.py +++ b/examples/cdn/Domain.py @@ -17,21 +17,36 @@ import time from openstack import connection -os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'https://cdn.myhwclouds.com/v1.0') +os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'xxxxxxxxxxx') -username = "xxxxxxxxxxx" -password = "xxxxxxxxxxx" +# token认证 +# username = "xxxxxxxxxxx" +# password = "xxxxxxxxxxx" +# projectId = "xxxxxxxxxxx" +# userDomainId = "xxxxxxxxxxx" +# auth_url = "xxxxxxxxxxx" +# +# conn = connection.Connection( +# auth_url=auth_url, +# user_domain_id=userDomainId, +# project_id=projectId, +# username=username, +# password=password +# ) + +# AKSK认证 projectId = "xxxxxxxxxxx" -userDomainId = "xxxxxxxxxxx" -auth_url = "https://iam.cn-north-1.myhuaweicloud.com/v3" +domain = "xxxxxxxxxxx" # cdn use: domain = "myhwclouds.com" +region= "xxxxxxxxxxx" # example: region = "cn-north-1" +AK = "xxxxxxxxxxx" +SK = "xxxxxxxxxxx" conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password -) + project_id=projectId, + domain=domain, + region=region, + ak=AK, + sk=SK) def domain_create(domain_name): @@ -42,13 +57,30 @@ def domain_create(domain_name): 'sources': [ { 'ip_or_domain': 'X.X.X.X', - 'origin_type': 'ipaddr', + 'origin_type': 'xxxxxxxxxxx', 'active_standby': 1 # 1 means this source is active } ] } domain = conn.cdn.create_domain(**attrs) +def domain_create_by_enterprise_project_id(domain_name, enterprise_project_id): + print('Create a new acceleration domain name: ') + attrs = { + 'domain_name': domain_name, + 'business_type': 'web', + 'sources': [ + { + 'ip_or_domain': 'X.X.X.X', + 'origin_type': 'xxxxxxxxxxx', + 'active_standby': 1 # 1 means this source is active + } + ], + 'enterprise_project_id': enterprise_project_id + } + domain = conn.cdn.create_domain(**attrs) + print(domain) + def domains_query(): print('List all domains:') @@ -68,12 +100,37 @@ def domains_query(): for domain in conn.cdn.domains(page_size=2, page_number=1): print(domain) +def domains_query_by_enterprise_project_id(_enterprise_project_id): + print('List all domains:') + for domain in conn.cdn.domains(enterprise_project_id='ALL'): + print(domain) + + # Also support filtering by some attributes + print('List domains by enterprise_project_id in "online" status: ') + for domain in conn.cdn.domains(enterprise_project_id=_enterprise_project_id, domain_status='online'): + print(domain) + + print('List domains in "web" type: ') + for domain in conn.cdn.domains(enterprise_project_id='ALL', business_type='web'): + print(domain) + + # You can list domains by page. + print('List 3rd and 4th domains: ') + for domain in conn.cdn.domains(enterprise_project_id='ALL', page_size=10, page_number=1): + print(domain) + def domain_query_detail(domain_id): print('Get the domain detail:') domain = conn.cdn.get_domain(domain_id) print(domain) +def domain_query_detail_by_enterprise_project_id(domain_id, enterprise_project_id='ALL'): + print('Get the domain detail:') + domain = conn.cdn.get_domain_detail_by_enterprise_project_id(domain_id, enterprise_project_id) + print(domain) + print(domain.sources) + def domain_disable_and_delete(domain_id): print('Delete the domain: ') @@ -88,15 +145,191 @@ def domain_disable_and_delete(domain_id): break else: time.sleep(1) - if cnt: - print('Deleted the domain.') - conn.cdn.delete_domain(domain_id) - else: - print('Disable domain timeout') + if cnt: + print('Deleted the domain.') + conn.cdn.delete_domain(domain_id) + else: + print('Disable domain timeout') + +def domain_disable_by_enterprise_project_id(domain_id, enterprise_project_id): + print('Disable the domain: ') + # Disable the domain before deleting + conn.cdn.disable_domain_by_enterprise_project_id(domain_id, enterprise_project_id) + +def domain_delete_by_enterprise_project_id(domain_id, enterprise_project_id): + print('Delete the domain: ') + conn.cdn.delete_domain_by_enterprise_project_id(domain_id, enterprise_project_id) + + +def domain_enable(domain_id): + print('enable the domain: ') + # Enable the domain + conn.cdn.enable_domain(domain_id) + +def domain_enable_by_enterprise_project_id(domain_id, enterprise_project_id): + print('enable the domain: ') + # Enable the domain + conn.cdn.enable_domain_by_enterprise_project_id(domain_id, enterprise_project_id) + + +def get_domain_origin_host(domain_id): + print('get domain origin host: ') + domain = conn.cdn.get_domain_origin_host(domain_id) + print(domain) + +def get_domain_origin_host_by_enterprise_project_id(domain_id, enterprise_project_id): + print('get domain origin host: ') + domain = conn.cdn.get_domain_origin_host_by_enterprise_project_id(domain_id, enterprise_project_id) + print(domain) + + +def set_domain_origin_host(domain_id): + print('set domain origin host: ') + attrs = { + 'origin_host_type': 'accelerate', + 'customize_domain': 'xxxxxxxxxxx' + } + conn.cdn.set_domain_origin_host(domain_id, **attrs) + +def set_domain_origin_host_by_enterprise_project_id(domain_id, enterprise_project_id): + print('set domain origin host: ') + attrs = { + 'origin_host_type': 'accelerate', + 'customize_domain': 'xxxxxxxxxxx' + } + conn.cdn.set_domain_origin_host_by_enterprise_project_id(domain_id, enterprise_project_id, **attrs) + +def get_domain_referer(domain_id): + print('get domain referer:') + domain = conn.cdn.get_domain_referer(domain_id) + print(domain) + +def get_domain_referer_by_enterprise_project_id(domain_id, enterprise_project_id): + print('get domain referer:') + domain = conn.cdn.get_domain_referer_by_enterprise_project_id(domain_id, enterprise_project_id) + print(domain) + +def set_domain_referer(domain_id): + print('set domain referer:') + attrs = { + 'referer_type': 1, + 'referer_list': 'xxxxxxxxxxx', + 'include_empty': False + } + conn.cdn.set_domain_referer(domain_id, **attrs) + +def set_domain_referer_by_enterprise_project_id(domain_id, enterprise_project_id): + print('set domain referer:') + attrs = { + 'referer_type': 1, + 'referer_list': 'xxxxxxxxxxx', + 'include_empty': False + } + conn.cdn.set_domain_referer_by_enterprise_project_id(domain_id, enterprise_project_id, **attrs) + +def get_domain_cache_rules(domain_id): + print('get domain cache rules:') + domain = conn.cdn.get_domain_cache_rules(domain_id) + print(domain) + +def get_domain_cache_rules_by_enterprise_project_id(domain_id, enterprise_project_id): + print('get domain cache rules:') + domain = conn.cdn.get_domain_cache_rules_by_enterprise_project_id(domain_id, enterprise_project_id) + print(domain) + +def set_domain_cache_rules(domain_id): + print('set domain cache rules:') + attrs = { + 'ignore_url_parameter': False, + 'rules': [ + { + 'rule_type': 1, + 'content': '.jpg;.png', + 'ttl': 21, + 'ttl_type': 3, + 'priority': 1 + } + ] + } + conn.cdn.set_domain_cache_rules(domain_id, **attrs) + +def set_domain_cache_rules_by_enterprise_project_id(domain_id, enterprise_project_id): + print('set domain cache rules:') + attrs = { + 'ignore_url_parameter': False, + 'rules': [ + { + 'rule_type': 1, + 'content': '.jpg;.png;.zip', + 'ttl': 22, + 'ttl_type': 3, + 'priority': 1 + } + ] + } + conn.cdn.set_domain_cache_rules_by_enterprise_project_id(domain_id, enterprise_project_id, **attrs) + +def get_domain_https(domain_id): + print('get domain https:') + domain = conn.cdn.get_domain_https(domain_id) + print(domain) + +def get_domain_https_by_enterprise_project_id(domain_id, enterprise_project_id): + print('get domain https:') + domain = conn.cdn.get_domain_https_by_enterprise_project_id(domain_id, enterprise_project_id) + print(domain) + +def set_domain_https(domain_id): + print('set domain https:') + attrs = { + 'force_redirect_https': 0, + 'https_status': 2, + 'cert_name': 'xxxxxxxxxxx', + 'certificate': 'xxxxxxxxxxx', + 'private_key': 'xxxxxxxxxxx' + } + conn.cdn.set_domain_https(domain_id, **attrs) + +def set_domain_https_by_enterprise_project_id(domain_id, enterprise_project_id): + print('set domain https:') + attrs = { + 'force_redirect_https': 0, + 'https_status': 2, + 'cert_name': 'xxxxxxxxxxx', + 'certificate': 'xxxxxxxxxxx', + 'private_key': 'xxxxxxxxxxx' + } + conn.cdn.set_domain_https_by_enterprise_project_id(domain_id, enterprise_project_id, **attrs) + +def set_domain_sources(domain_id): + print('set domain sources: ') + attrs = { + 'sources': [ + { + 'ip_or_domain': 'xxxxxxxxxxx', + 'origin_type': 'xxxxxxxxxxx', + 'active_standby': 1 + } + ] + } + conn.cdn.set_domain_sources(domain_id, **attrs) + +def set_domain_sources_by_enterprise_project_id(domain_id, enterprise_project_id): + print('set domain sources: ') + attrs = { + 'sources': [ + { + 'ip_or_domain': 'xxxxxxxxxxx', + 'origin_type': 'xxxxxxxxxxx', + 'active_standby': 1 + } + ] + } + conn.cdn.set_domain_sources_by_enterprise_project_id(domain_id, enterprise_project_id, **attrs) if __name__ == "__main__": - domain_name = 'cdn-python-sdk.example.com' + domain_name = 'xxxxxxxxxxx' domain_id = 'xxxxxxxxxxx' domain_create(domain_name) @@ -107,3 +340,55 @@ def domain_disable_and_delete(domain_id): domain_disable_and_delete(domain_id) + domain_enable(domain_id) + + get_domain_origin_host(domain_id) + + set_domain_origin_host(domain_id) + + get_domain_referer(domain_id) + + set_domain_referer(domain_id) + + get_domain_cache_rules(domain_id) + + set_domain_cache_rules(domain_id) + + get_domain_https(domain_id) + + set_domain_https(domain_id) + + set_domain_sources(domain_id) + + + enterprise_project_id = 'xxxxxxxxxxx' + domain_id = 'xxxxxxxxxxx' + domain_create(domain_name, enterprise_project_id) + + domains_query_by_enterprise_project_id(enterprise_project_id) + + domain_query_detail_by_enterprise_project_id(domain_id, enterprise_project_id) + + domain_disable_by_enterprise_project_id(domain_id, enterprise_project_id) + + domain_delete_by_enterprise_project_id(domain_id, enterprise_project_id) + + domain_enable_by_enterprise_project_id(domain_id, enterprise_project_id) + + get_domain_origin_host_by_enterprise_project_id(domain_id, enterprise_project_id) + + set_domain_origin_host_by_enterprise_project_id(domain_id, enterprise_project_id) + + get_domain_referer_by_enterprise_project_id(domain_id, enterprise_project_id) + + set_domain_referer_by_enterprise_project_id(domain_id, enterprise_project_id) + + get_domain_cache_rules_by_enterprise_project_id(domain_id, enterprise_project_id) + + set_domain_cache_rules_by_enterprise_project_id(domain_id, enterprise_project_id) + + get_domain_https_by_enterprise_project_id(domain_id, enterprise_project_id) + + set_domain_https_by_enterprise_project_id(domain_id, enterprise_project_id) + + set_domain_sources_by_enterprise_project_id(domain_id, enterprise_project_id) \ No newline at end of file diff --git a/examples/cdn/Log.py b/examples/cdn/Log.py index 1ae5741..09aa84f 100644 --- a/examples/cdn/Log.py +++ b/examples/cdn/Log.py @@ -17,21 +17,36 @@ import time from openstack import connection -os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'https://cdn.myhwclouds.com/v1.0') +# os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'xxxxxxxxxxx') -username = "xxxxxxxxxxx" -password = "xxxxxxxxxxx" +# token认证 +# username = "xxxxxxxxxxx" +# password = "xxxxxxxxxxx" +# projectId = "xxxxxxxxxxx" +# userDomainId = "xxxxxxxxxxx" +# auth_url = "xxxxxxxxxxx" +# +# conn = connection.Connection( +# auth_url=auth_url, +# user_domain_id=userDomainId, +# project_id=projectId, +# username=username, +# password=password +# ) + +# AKSK认证 projectId = "xxxxxxxxxxx" -userDomainId = "xxxxxxxxxxx" -auth_url = "https://iam.cn-north-1.myhuaweicloud.com/v3" +domain = "xxxxxxxxxxx" # cdn use: domain = "myhwclouds.com" +region= "xxxxxxxxxxx" # example: region = "cn-north-1" +AK = "xxxxxxxxxxx" +SK = "xxxxxxxxxxx" conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password -) + project_id=projectId, + domain=domain, + region=region, + ak=AK, + sk=SK) def list_logs(domain_name, today): @@ -42,9 +57,18 @@ def list_logs(domain_name, today): # for log in conn.cdn.logs(domain_name=domain_name, query_date=today): # print(log) +def list_logs_by_enterprise_project_id(domain_name, today, enterprise_project_id): + #today = '1532620800000' + logs = conn.cdn.logs_by_enterprise_project_id(domain_name=domain_name, query_date=today, page_number=1, page_size=10, + enterprise_project_id=enterprise_project_id) + log_list = list(logs) + print(log_list) + if __name__ == "__main__": today = int(time.time() * 1000) - 24 * 3600 * 1000 - domain = "cdn-python-sdk.example.com" + domain = "xxxxxxxxxxx" + enterprise_project_id = "xxxxxxxxxxx" list_logs(domain, today) + list_logs_by_enterprise_project_id(domain, today, enterprise_project_id) diff --git a/examples/cdn/Static.py b/examples/cdn/Static.py index d55675a..a91c0a0 100644 --- a/examples/cdn/Static.py +++ b/examples/cdn/Static.py @@ -1,12 +1,12 @@ # -*- coding:utf-8 -*- # Copyright 2018 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 @@ -17,13 +17,13 @@ import time from openstack import connection -os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'https://cdn.myhwclouds.com/v1.0') +os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'xxxxxxxxxxxxxxxx') -username = "xxxxxxxxxxx" -password = "xxxxxxxxxxx" -projectId = "xxxxxxxxxxx" -userDomainId = "xxxxxxxxxxx" -auth_url = "https://iam.cn-north-1.myhuaweicloud.com/v3" +username = "xxxxxxxxxxxxxxxx" +password = "xxxxxxxxxxxxxxxx" +projectId = "xxxxxxxxxxxxxxxx" +userDomainId = "xxxxxxxxxxxxxxxx" +auth_url = "xxxxxxxxxxxxxxxx" conn = connection.Connection( auth_url=auth_url, @@ -34,39 +34,54 @@ ) -def query_total_flux(domain_name, start_time, end_time): +# AKSK +# os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'xxxxxxxxxxxxxxxx') +# projectId = "xxxxxxxxxxxxxxxx" +# domain = "xxxxxxxxxxxxxxxx" +# region= "xxxxxxxxxxxxxxxx" +# AK = "xxxxxxxxxxxxxxxx" +# SK = "xxxxxxxxxxxxxxxx" +# +# conn = connection.Connection( +# project_id=projectId, +# domain=domain, +# region=region, +# ak = AK, +# sk = SK) + +def query_total_flux(domain_name, start_time, end_time, enterprise_project_id): print('Query the total network traffic: ') - total_traffic = conn.cdn.query_network_traffic(domain_name=domain_name, start_time=start_time, end_time=end_time) + total_traffic = conn.cdn.query_network_traffic(domain_name=domain_name, start_time=start_time, end_time=end_time, enterprise_project_id=enterprise_project_id) print(total_traffic) -def query_detail_flux(domain_name, start_time, end_time): +def query_detail_flux(domain_name, start_time, end_time, enterprise_project_id): print('Query the network traffic detail: ') - traffic_detail = conn.cdn.query_network_traffic_detail(domain_name=domain_name, start_time=start_time, end_time=end_time, interval=300) + traffic_detail = conn.cdn.query_network_traffic_detail(domain_name=domain_name, start_time=start_time, end_time=end_time, interval=300, enterprise_project_id=enterprise_project_id) print(traffic_detail) -def query_bandwidth_peak(domain_name, start_time, end_time): +def query_bandwidth_peak(domain_name, start_time, end_time, enterprise_project_id): print('Query bandwidth peak: ') - bandwidth_peak = conn.cdn.query_bandwidth_peak(domain_name=domain_name, start_time=start_time, end_time=end_time) + bandwidth_peak = conn.cdn.query_bandwidth_peak(domain_name=domain_name, start_time=start_time, end_time=end_time, enterprise_project_id=enterprise_project_id) print(bandwidth_peak) -def query_detail_bandwidth(domain_name, start_time, end_time): +def query_detail_bandwidth(domain_name, start_time, end_time, enterprise_project_id): print('Query bandwidth peak detail: ') - bandwidth = conn.cdn.query_bandwidth(domain_name=domain_name, start_time=start_time, end_time=end_time, interval=300) + bandwidth = conn.cdn.query_bandwidth(domain_name=domain_name, start_time=start_time, end_time=end_time, interval=300, enterprise_project_id=enterprise_project_id) print(bandwidth) -def query_summary_by_type(domain_name, start_time, end_time, query_type): +def query_summary_by_type(domain_name, start_time, end_time, query_type, enterprise_project_id): print('Query static summary by type - ' + query_type + ': ') - summary = conn.cdn.query_summary(domain_name=domain_name, start_time=start_time, end_time=end_time, stat_type=query_type, service_area='mainland_china') + summary = conn.cdn.query_summary(domain_name=domain_name, start_time=start_time, end_time=end_time, stat_type=query_type, service_area='mainland_china', enterprise_project_id=enterprise_project_id) print(summary) -def query_summary_detail_by_type(domain_name, start_time, end_time, query_type): +def query_summary_detail_by_type(domain_name, start_time, end_time, query_type, enterprise_project_id): print('Query static summary detail by type - ' + query_type + ': ') - summary = conn.cdn.query_summary_detail(domain_name=domain_name, start_time=start_time, end_time=end_time, stat_type=query_type, service_area='mainland_china') + summary = conn.cdn.query_summary_detail(domain_name=domain_name, start_time=start_time, end_time=end_time, stat_type=query_type, service_area='mainland_china', enterprise_project_id=enterprise_project_id) print(summary) -def query_domains_summary_detail_by_type(domain_name, start_time, end_time, query_type): +def query_domains_summary_detail_by_type(domain_name, start_time, end_time, query_type, enterprise_project_id): print('Query static domains summary detail by type - ' + query_type + ': ') - summaries = conn.cdn.summaries(domain_name=domain_name, start_time=start_time, end_time=end_time, stat_type=query_type, service_area='mainland_china') + summaries = conn.cdn.summaries(domain_name=domain_name, start_time=start_time, end_time=end_time, stat_type=query_type, service_area='mainland_china', enterprise_project_id=enterprise_project_id) for summary in summaries: print(summary) @@ -75,23 +90,24 @@ def query_domains_summary_detail_by_type(domain_name, start_time, end_time, quer end_time = int(time.time() * 1000) start_time = end_time - 3600000 domain_name = "ALL" - - query_total_flux(domain_name, start_time, end_time) - - query_detail_flux(domain_name, start_time, end_time) - - query_bandwidth_peak(domain_name, start_time, end_time) - - query_detail_bandwidth(domain_name, start_time, end_time) - + enterprise_project_id = "" + + query_total_flux(domain_name, start_time, end_time, enterprise_project_id) + + query_detail_flux(domain_name, start_time, end_time, enterprise_project_id) + + query_bandwidth_peak(domain_name, start_time, end_time, enterprise_project_id) + + query_detail_bandwidth(domain_name, start_time, end_time, enterprise_project_id) + for query_type in ['bw', 'flux', 'bs_bw', 'bs_flux', 'req_num', 'req_hit_rate', 'flux_hit_rate', 'bs_fail_rate', 'qps', 'http_code_2xx', 'http_code_3xx', 'http_code_4xx', 'http_code_5xx']: - query_summary_by_type(domain_name, start_time, end_time, query_type) - + query_summary_by_type(domain_name, start_time, end_time, query_type, enterprise_project_id) + for query_type in ['bw', 'flux', 'bs_bw', 'bs_flux', 'req_num', 'req_hit_rate', 'flux_hit_rate', 'bs_fail_rate', 'qps', 'http_code_2xx', 'http_code_3xx', 'http_code_4xx', 'http_code_5xx']: - query_summary_detail_by_type(domain_name, start_time, end_time, query_type) - + query_summary_detail_by_type(domain_name, start_time, end_time, query_type, enterprise_project_id) + domain_name = "cdn-python-sdk-a.example.com,cdn-python-sdk.example.com.com" start_time = end_time - 23 * 3600 * 1000 for query_type in ['bw', 'flux', 'bs_bw', 'bs_flux', 'req_num', 'req_hit_rate', 'flux_hit_rate', 'bs_fail_rate', 'qps', 'http_code_2xx', 'http_code_3xx', 'http_code_4xx', 'http_code_5xx']: - query_domains_summary_detail_by_type(domain_name, start_time, end_time, query_type) - + query_domains_summary_detail_by_type(domain_name, start_time, end_time, query_type, enterprise_project_id) + diff --git a/examples/cdn/preheatTask.py b/examples/cdn/preheatTask.py index 55fb1f6..a200b70 100644 --- a/examples/cdn/preheatTask.py +++ b/examples/cdn/preheatTask.py @@ -16,21 +16,36 @@ import sys from openstack import connection -os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'https://cdn.myhwclouds.com/v1.0') +os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'xxxxxxxxxxx') -username = "xxxxxxxxxxx" -password = "xxxxxxxxxxx" +# token认证 +# username = "xxxxxxxxxxx" +# password = "xxxxxxxxxxx" +# projectId = "xxxxxxxxxxx" +# userDomainId = "xxxxxxxxxxx" +# auth_url = "xxxxxxxxxxx" +# +# conn = connection.Connection( +# auth_url=auth_url, +# user_domain_id=userDomainId, +# project_id=projectId, +# username=username, +# password=password +# ) + +# AKSK认证 projectId = "xxxxxxxxxxx" -userDomainId = "xxxxxxxxxxx" -auth_url = "https://iam.cn-north-1.myhuaweicloud.com/v3" +domain = "xxxxxxxxxxx" # cdn use: domain = "myhwclouds.com" +region= "xxxxxxxxxxx" # example: region = "cn-north-1" +AK = "xxxxxxxxxxx" +SK = "xxxxxxxxxxx" conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password -) + project_id=projectId, + domain=domain, + region=region, + ak=AK, + sk=SK) def preheattask(preheatTask): print("preheat urls or dirs:") @@ -39,8 +54,8 @@ def preheattask(preheatTask): if __name__ == "__main__": preheatTask={ - "urls": ["http://cdn-python-sdk.example.com/img/a7.jpg", - "http://cdn-python-sdk.example.com/js/plugins/"] + "urls": ["xxxxxxxxxxx", + "xxxxxxxxxxx"] } preheattask(preheatTask) diff --git a/examples/cdn/refreshTask.py b/examples/cdn/refreshTask.py index 2eae645..41dab0d 100644 --- a/examples/cdn/refreshTask.py +++ b/examples/cdn/refreshTask.py @@ -16,21 +16,37 @@ import sys from openstack import connection -os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'https://cdn.myhwclouds.com/v1.0') +os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', 'xxxxxxxxxxx') -username = "xxxxxxxxxxx" -password = "xxxxxxxxxxx" +# token认证 +# username = "xxxxxxxxxxx" +# password = "xxxxxxxxxxx" +# projectId = "xxxxxxxxxxx" +# userDomainId = "xxxxxxxxxxx" +# auth_url = "xxxxxxxxxxx" +# +# conn = connection.Connection( +# auth_url=auth_url, +# user_domain_id=userDomainId, +# project_id=projectId, +# username=username, +# password=password +# ) + +# AKSK认证 projectId = "xxxxxxxxxxx" -userDomainId = "xxxxxxxxxxx" -auth_url = "https://iam.cn-north-1.myhuaweicloud.com/v3" +domain = "xxxxxxxxxxx" # cdn use: domain = "myhwclouds.com" +region= "xxxxxxxxxxx" # example: region = "cn-north-1" +AK = "xxxxxxxxxxx" +SK = "xxxxxxxxxxx" conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password -) + project_id=projectId, + domain=domain, + region=region, + ak=AK, + sk=SK) + def refreshTask(refreshTask): print("refresh files or dirs:") @@ -38,17 +54,16 @@ def refreshTask(refreshTask): print(refreshtask) - if __name__ == "__main__": refreshFileTask={ "type": "file", - "urls": ["http://cdn-python-sdk.example.com/img/a5.jpg", - "http://cdn-python-sdk.example.com/img/a7.jpg"] + "urls": ["xxxxxxxxxxx", + "xxxxxxxxxxx"] } refreshDirTask={ "type": "directory", - "urls": ["http://cdn-python-sdk.example.com/img/", - "http://cdn-python-sdk.example.com/js/plugins/"] + "urls": ["xxxxxxxxxxx", + "xxxxxxxxxxx"] } refreshTask(refreshFileTask) refreshTask(refreshDirTask) diff --git a/examples/cloud_eye/__init__.py b/examples/cloud_eye/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/cloud_eye/alarms.py b/examples/cloud_eye/alarms.py deleted file mode 100644 index 4f5afda..0000000 --- a/examples/cloud_eye/alarms.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - - -def list_alarms(connection): - query = { - "limit": 1, - # "marker": "last-alarm-id", - "order": "desc" - } - for alarm in connection.cloud_eye.alarms(**query): - logging.info(alarm) - - -def get_alarm(connection): - alarm_id = "al1483387711418ZNpR8DX3g" - alarm = connection.cloud_eye.get_alarm(alarm_id) - logging.info(alarm) - - -def delete_alarm(connection): - alarm_id = "al1483387711418ZNpR8DX3g" - connection.cloud_eye.delete_alarm(alarm_id) - - -def enable_alarm(connection): - alarm_id = "al1483387711418ZNpR8DX3g" - connection.cloud_eye.enable_alarm(alarm_id) - - -def disable_alarm(connection): - alarm_id = "al1483387711418ZNpR8DX3g" - connection.cloud_eye.disable_alarm(alarm_id) diff --git a/examples/cloud_eye/metric_data.py b/examples/cloud_eye/metric_data.py deleted file mode 100644 index 5641fc7..0000000 --- a/examples/cloud_eye/metric_data.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import datetime -import logging - -from openstack import utils - -now = datetime.datetime.now() -five_min_ago = now - datetime.timedelta(minutes=5) - - -def list_metric_aggregations(connection): - query = { - "namespace": "MINE.APP", - "metric_name": "cpu_util", - "from": utils.get_epoch_time(five_min_ago), - "to": utils.get_epoch_time(now), - "period": 300, - "filter": "average", - "dimensions": [{ - "name": "instance_id", - "value": "33328f02-3814-422e-b688-bfdba93d4050" - }] - } - for aggregation in connection.cloud_eye.metric_aggregations(**query): - logging.info(aggregation) - - -def add_metric_data(connection): - data = [ - { - "metric": { - "namespace": "MINE.APP", - "dimensions": [ - { - "name": "instance_id", - "value": "33328f02-3814-422e-b688-bfdba93d4050" - } - ], - "metric_name": "cpu_util" - }, - "ttl": 172800, - "collect_time": utils.get_epoch_time(five_min_ago), - "value": 60, - "unit": "%" - }, - { - "metric": { - "namespace": "MINE.APP", - "dimensions": [ - { - "name": "instance_id", - "value": "33328f02-3814-422e-b688-bfdba93d4050" - } - ], - "metric_name": "cpu_util" - }, - "ttl": 172800, - "collect_time": utils.get_epoch_time(now), - "value": 70, - "unit": "%" - } - ] - connection.cloud_eye.add_metric_data(data) diff --git a/examples/cloud_eye/metrics.py b/examples/cloud_eye/metrics.py deleted file mode 100644 index 81fae63..0000000 --- a/examples/cloud_eye/metrics.py +++ /dev/null @@ -1,38 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - - -def list_metrics(connection): - query = { - "namespace": "SYS.ECS", - # "metric_name": "cpu_util", - # "dimensions": [{ - # "name": "instance_id", - # "value": "9f31d05a-76d5-478a-b864-b1b5e8708482" - # }], - # "order": "desc", - # "marker": ("SYS.ECS.cpu_util.instance_id:" - # "9f31d05a-76d5-478a-b864-b1b5e8708482"), - "limit": 100 - } - for metric in connection.cloud_eye.metrics(**query): - logging.info(metric) - - -def list_favorite_metrics(connection): - favorite_metrics = connection.cloud_eye.favorite_metrics() - for metric in favorite_metrics: - logging.info(metric) diff --git a/examples/cloud_eye/quotas.py b/examples/cloud_eye/quotas.py deleted file mode 100644 index f35866c..0000000 --- a/examples/cloud_eye/quotas.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - - -def list_quotas(connection): - quotas = connection.cloud_eye.quotas() - for quota in quotas: - logging.info(quota) diff --git a/examples/cluster/__init__.py b/examples/cluster/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/cluster/policy.py b/examples/cluster/policy.py deleted file mode 100644 index 9ed4b6f..0000000 --- a/examples/cluster/policy.py +++ /dev/null @@ -1,89 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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. - -""" -Managing policies in the Cluster service. - -For a full guide see -https://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html -""" - - -def list_policies(conn): - print("List Policies:") - - for policy in conn.cluster.policies(): - print(policy.to_dict()) - - for policy in conn.cluster.policies(sort='name:asc'): - print(policy.to_dict()) - - -def create_policy(conn): - print("Create Policy:") - - spec = { - 'policy': 'senlin.policy.deletion', - 'version': 1.0, - 'properties': { - 'criteria': 'oldest_first', - 'destroy_after_deletion': True, - } - } - - policy = conn.cluster.create_policy('dp01', spec) - print(policy.to_dict()) - - -def get_policy(conn): - print("Get Policy:") - - policy = conn.cluster.get_policy('dp01') - print(policy.to_dict()) - - -def find_policy(conn): - print("Find Policy:") - - policy = conn.cluster.find_policy('dp01') - print(policy.to_dict()) - - -def update_policy(conn): - print("Update Policy:") - - policy = conn.cluster.update_policy('dp01', name='dp02') - print(policy.to_dict()) - - -def delete_policy(conn): - print("Delete Policy:") - - conn.cluster.delete_policy('dp01') - - print("Policy deleted.") diff --git a/examples/cluster/policy_type.py b/examples/cluster/policy_type.py deleted file mode 100644 index cfbcbde..0000000 --- a/examples/cluster/policy_type.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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. - -""" -Managing policy types in the Cluster service. - -For a full guide see -https://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html -""" - - -def list_policy_types(conn): - print("List Policy Types:") - - for pt in conn.cluster.policy_types(): - print(pt.to_dict()) - - -def get_policy_type(conn): - print("Get Policy Type:") - - pt = conn.cluster.get_policy_type('senlin.policy.deletion-1.0') - - print(pt.to_dict()) diff --git a/examples/cluster/profile.py b/examples/cluster/profile.py deleted file mode 100644 index a21410f..0000000 --- a/examples/cluster/profile.py +++ /dev/null @@ -1,98 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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 examples.connect import FLAVOR_NAME -from examples.connect import IMAGE_NAME -from examples.connect import NETWORK_NAME -from examples.connect import SERVER_NAME - -""" -Managing profiles in the Cluster service. - -For a full guide see -https://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html -""" - - -def list_profiles(conn): - print("List Profiles:") - - for profile in conn.cluster.profiles(): - print(profile.to_dict()) - - for profile in conn.cluster.profiles(sort='name:asc'): - print(profile.to_dict()) - - -def create_profile(conn): - print("Create Profile:") - - spec = { - 'profile': 'os.nova.server', - 'version': 1.0, - 'properties': { - 'name': SERVER_NAME, - 'flavor': FLAVOR_NAME, - 'image': IMAGE_NAME, - 'networks': { - 'network': NETWORK_NAME - } - } - } - - profile = conn.cluster.create_profile('os_server', spec) - print(profile.to_dict()) - - -def get_profile(conn): - print("Get Profile:") - - profile = conn.cluster.get_profile('os_server') - print(profile.to_dict()) - - -def find_profile(conn): - print("Find Profile:") - - profile = conn.cluster.find_profile('os_server') - print(profile.to_dict()) - - -def update_profile(conn): - print("Update Profile:") - - profile = conn.cluster.update_profile('os_server', name='old_server') - print(profile.to_dict()) - - -def delete_profile(conn): - print("Delete Profile:") - - conn.cluster.delete_profile('os_server') - - print("Profile deleted.") diff --git a/examples/cluster/profile_type.py b/examples/cluster/profile_type.py deleted file mode 100644 index f54bb11..0000000 --- a/examples/cluster/profile_type.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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. - -""" -Managing profile types in the Cluster service. - -For a full guide see -https://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html -""" - - -def list_profile_types(conn): - print("List Profile Types:") - - for pt in conn.cluster.profile_types(): - print(pt.to_dict()) - - -def get_profile_type(conn): - print("Get Profile Type:") - - pt = conn.cluster.get_profile_type('os.nova.server-1.0') - - print(pt.to_dict()) diff --git a/examples/compute/__init__.py b/examples/compute/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/compute/create.py b/examples/compute/create.py deleted file mode 100644 index c04d898..0000000 --- a/examples/compute/create.py +++ /dev/null @@ -1,71 +0,0 @@ -# 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. - -import errno -import os - -from examples.connect import FLAVOR_NAME -from examples.connect import IMAGE_NAME -from examples.connect import KEYPAIR_NAME -from examples.connect import NETWORK_NAME -from examples.connect import PRIVATE_KEYPAIR_FILE -from examples.connect import SERVER_NAME -from examples.connect import SSH_DIR - -""" -Create resources with the Compute service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def create_keypair(conn): - keypair = conn.compute.find_keypair(KEYPAIR_NAME) - - if not keypair: - print("Create Key Pair:") - - keypair = conn.compute.create_keypair(name=KEYPAIR_NAME) - - print(keypair) - - try: - os.mkdir(SSH_DIR) - except OSError as e: - if e.errno != errno.EEXIST: - raise e - - with open(PRIVATE_KEYPAIR_FILE, 'w') as f: - f.write("%s" % keypair.private_key) - - os.chmod(PRIVATE_KEYPAIR_FILE, 0o400) - - return keypair - - -def create_server(conn): - print("Create Server:") - - image = conn.compute.find_image(IMAGE_NAME) - flavor = conn.compute.find_flavor(FLAVOR_NAME) - network = conn.network.find_network(NETWORK_NAME) - keypair = create_keypair(conn) - - server = conn.compute.create_server( - name=SERVER_NAME, image_id=image.id, flavor_id=flavor.id, - networks=[{"uuid": network.id}], key_name=keypair.name) - - server = conn.compute.wait_for_server(server) - - print("ssh -i {key} root@{ip}".format( - key=PRIVATE_KEYPAIR_FILE, - ip=server.access_ipv4)) diff --git a/examples/compute/delete.py b/examples/compute/delete.py deleted file mode 100644 index ba34431..0000000 --- a/examples/compute/delete.py +++ /dev/null @@ -1,50 +0,0 @@ -# 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. - -import errno -import os - -from examples.connect import KEYPAIR_NAME -from examples.connect import PRIVATE_KEYPAIR_FILE -from examples.connect import SERVER_NAME - -""" -Delete resources with the Compute service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def delete_keypair(conn): - print("Delete Key Pair:") - - keypair = conn.compute.find_keypair(KEYPAIR_NAME) - - try: - os.remove(PRIVATE_KEYPAIR_FILE) - except OSError as e: - if e.errno != errno.ENOENT: - raise e - - print(keypair) - - conn.compute.delete_keypair(keypair) - - -def delete_server(conn): - print("Delete Server:") - - server = conn.compute.find_server(SERVER_NAME) - - print(server) - - conn.compute.delete_server(server) diff --git a/examples/compute/find.py b/examples/compute/find.py deleted file mode 100644 index b009df9..0000000 --- a/examples/compute/find.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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. - -import examples.connect - -""" -Find a resource from the Compute service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def find_image(conn): - print("Find Image:") - - image = conn.compute.find_image(examples.connect.IMAGE_NAME) - - print(image) - - return image - - -def find_flavor(conn): - print("Find Flavor:") - - flavor = conn.compute.find_flavor(examples.connect.FLAVOR_NAME) - - print(flavor) - - return flavor - - -def find_keypair(conn): - print("Find Keypair:") - - keypair = conn.compute.find_keypair(examples.connect.KEYPAIR_NAME) - - print(keypair) - - return keypair diff --git a/examples/compute/list.py b/examples/compute/list.py deleted file mode 100644 index 0886f88..0000000 --- a/examples/compute/list.py +++ /dev/null @@ -1,45 +0,0 @@ -# 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. - -""" -List resources from the Compute service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def list_servers(conn): - print("List Servers:") - - for server in conn.compute.servers(): - print(server) - - -def list_images(conn): - print("List Images:") - - for image in conn.compute.images(): - print(image) - - -def list_flavors(conn): - print("List Flavors:") - - for flavor in conn.compute.flavors(): - print(flavor) - - -def list_keypairs(conn): - print("List Keypairs:") - - for keypair in conn.compute.keypairs(): - print(keypair) diff --git a/examples/cts/__init__.py b/examples/cts/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/cts/cts.py b/examples/cts/cts.py deleted file mode 100644 index c6deb62..0000000 --- a/examples/cts/cts.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing cts - -""" - - -def create_update_tracker(conn): - tracker_dict = { - "bucket_name": "defaultbucket", - "file_prefix_name": "mytracker1" - } - - t = conn.cts.create_tracker(**tracker_dict) - print("newly created tracker is:") - - update_dict = { - "bucket_name": "my_created_bucket", - "file_prefix_name": "some_folder", - "status": "disabled" - } - - ut = conn.cts.update_tracker(t, **update_dict) - print("tracker is updated as:") - print(ut) - - -def get_delete_tracker(conn): - # default name, we will get the 'system' tracker - gett = conn.cts.get_tracker() - print("system tracker is:") - print(gett) - - print("traces for system tracker is") - for tr in conn.cts.traces(): - print(tr) - - print("delete tracker:") - conn.cts.delete_tracker() diff --git a/examples/dms/__init__.py b/examples/dms/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/dms/dms.py b/examples/dms/dms.py deleted file mode 100644 index 4d3c8f9..0000000 --- a/examples/dms/dms.py +++ /dev/null @@ -1,134 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing dms - -""" - - -def create_queue(conn): - queue_dict = { - 'name': "queue001", - 'description': 'test1' - } - - q = conn.dms.create_queue(**queue_dict) - print(q) - - print("list queues") - for qs in conn.dms.queues(): - print(qs) - - print("get queue") - getq = conn.dms.get_queue(q) - print(getq) - - -def create_delete_groups(conn, queue): - print("create groups on queue %s", queue) - groups = { - "groups": [ - { - "name": "aaaxjjjacccc" - }, - { - "name": "dddeeessfff" - } - - ] - } - print(conn.dms.create_groups(queue, **groups)) - - for g in conn.dms.groups(queue): - print(g) - conn.dms.delete_group(queue, g) - - -def create_message(conn, queue): - print("send message on a queue %s", queue) - msg_dict = { - "messages": [ - { - "body": "TEST11", - "attributes": - { - "attribute1": "value1", - "attribute2": "value2" - } - }, - { - "body": - { - "foo": "test02" - }, - "attributes": - { - "attribute1": "value1", - "attribute2": "value2" - } - } - ] - } - print(conn.dms.send_messages(queue, **msg_dict)) - - -def consume_message(conn, queue): - - print("delete groups for queue %s", queue) - for g in conn.dms.groups(queue): - print(g) - conn.dms.delete_group(queue, g) - - groups = { - "groups": [ - { - "name": "aaaxjjjacccc" - }, - { - "name": "dddeeessfff" - } - - ] - } - - grp = conn.dms.create_groups(queue, **groups) - - for cm in conn.dms.consume_message(queue, grp[0].id): - print("ack consumed message") - print(conn.dms.ack_consumed_message(cm)) - - -# Consume message by tag list in queue and group -def consume_message_with_tags(conn, qui, gid): - qid = '673f8fca-9aa1-4974-8fc5-b0eb1c5f9724' - # gid = 'g-a826e437-2e67-46c7-b220-63836b5bb463' - params = { - 'max_msgs': 10, - 'time_wait': 30, - 'tags': ['tag1', 'tag2'], - 'tag_type': 'or' - } - - for c in conn.dms.consume_message(qid, gid, **params): - print(c) - - -def get_quotas(conn): - - for q in conn.dms.quotas(): - print(q) - print(q.type) - print(q.quota) - print(q.used) diff --git a/examples/dns/__init__.py b/examples/dns/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/dns/ptr.py b/examples/dns/ptr.py deleted file mode 100644 index 330b139..0000000 --- a/examples/dns/ptr.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - - -def list_ptrs(conn): - query = { - 'limit': 10 - } - for ptr in conn.dns.ptrs(**query): - logging.info(ptr) - - -def create_ptr(conn): - ptr = { - 'ptrdname': 'www.turnbig.net', - 'description': 'HaveFun.lee - For Test', - 'ttl': 300, - 'region': 'eu-de', - 'floating_ip_id': '9e9c6d33-51a6-4f84-b504-c13301f1cc8c' - } - ptr = conn.dns.create_ptr(**ptr) - logging.info(ptr) - return ptr - - -def get_ptr(conn): - ptr = conn.dns.get_ptr('eu-de', '9e9c6d33-51a6-4f84-b504-c13301f1cc8c') - logging.info(ptr) - - -def restore_ptr(conn): - conn.dns.restore_ptr('eu-de', '9e9c6d33-51a6-4f84-b504-c13301f1cc8c') - -# list_ptrs(connection) -# get_ptr(connection) -# create_ptr(connection) -# restore_ptr(connection) diff --git a/examples/dns/recordsets.py b/examples/dns/recordsets.py deleted file mode 100644 index e6bd02b..0000000 --- a/examples/dns/recordsets.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - -from openstack.dns.v2.recordset import Recordset -from openstack.dns.v2.zone import Zone - - -def list_recordsets(conn): - query = { - 'limit': 5 - } - zone_id = 'ff8080825ca865e8015caa9f452700a8' - recordsets = conn.dns.recordsets(zone_id, **query) - for recordset in recordsets: - logging.info(recordset) - - -def create_recordset(conn): - recordset = { - "name": "api.turnbig.net", - "description": "This is an example record set.", - "type": "CNAME", - "ttl": 3600, - "records": [ - "www.turnbig.net" - ] - } - - recordset = conn.dns.create_recordset('ff8080825ca865e8015caa9f452700a8', - **recordset) - logging.info(recordset) - return recordset - - -def get_recordset(conn, recordset_id): - zone = Zone(id='ff8080825ca865e8015caa9f452700a8') - recordset = conn.dns.get_recordset(zone, recordset_id) - recordset = conn.dns.get_recordset(zone, Recordset(id=recordset_id)) - recordset = conn.dns.get_recordset(zone.id, recordset_id) - recordset = conn.dns.get_recordset(zone.id, Recordset(id=recordset_id)) - logging.info(recordset) - - -def delete_recordset(conn): - zone = Zone(id='ff8080825ca865e8015caa9f452700a8') - recordset = Recordset(id='ff8080825ca865e8015caaaa0e1500ba') - conn.dns.delete_recordset(zone, recordset) - - -def all_recordsets(conn): - query = { - 'limit': 100 - } - recordsets = conn.dns.all_recordsets(**query) - for recordset in recordsets: - logging.info(recordset) diff --git a/examples/dns/zones.py b/examples/dns/zones.py deleted file mode 100644 index 2b19f8f..0000000 --- a/examples/dns/zones.py +++ /dev/null @@ -1,87 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import logging - -from openstack.dns.v2.zone import Zone - - -def list_zones(conn): - query = { - # 'vip_address': '192.168.2.36' - 'type': 'private', - 'limit': 3 - } - for zone in conn.dns.zones(**query): - logging.info(zone) - - -def create_zone(conn): - zone = { - 'name': 'turnbig.net', - 'description': 'This is an example zone.', - 'zone_type': 'private', - 'email': 'admin@turnbig.net', - 'ttl': 500, - 'router': { - 'router_id': '5fbf2de5-c7e5-4ec5-92ef-1e0b128f729f', - 'router_region': 'eu-de' - } - } - zone = conn.dns.create_zone(**zone) - logging.info(zone) - return zone - - -def get_zone(conn, zone_id): - zone = conn.dns.get_zone(zone_id) - logging.info(zone) - - zone = conn.dns.get_zone(Zone(id=zone_id)) - logging.info(zone) - - -def delete_zone(conn): - conn.dns.delete_backup('ff8080825ca5c454015ca6eefb480067') - - -def get_nameservers(conn): - # zone = create_zone(conn) - nameservers = conn.dns.nameservers( - 'ff8080825ca865e8015ca99563af004a' - ) - - for nameserver in nameservers: - logging.info(nameserver) - - -def add_router_to_zone(conn): - router = { - 'router_id': '62615060-5a38-42d4-a391-9b8a109da548', - 'router_region': 'eu-de' - } - conn.dns.add_router_to_zone('ff8080825ca865e8015ca99563af004a', **router) - - -def remove_router_from_zone(conn): - router = { - 'router_id': '62615060-5a38-42d4-a391-9b8a109da548', - 'router_region': 'eu-de' - } - result = conn.dns.remove_router_from_zone( - 'ff8080825ca865e8015ca99563af004a', - **router - ) - - logging.info(result) diff --git a/examples/evs/__init__.py b/examples/evs/__init__.py deleted file mode 100644 index 7608083..0000000 --- a/examples/evs/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def main(): - pass - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/examples/evs/volume.py b/examples/evs/volume.py deleted file mode 100644 index 77164ed..0000000 --- a/examples/evs/volume.py +++ /dev/null @@ -1,87 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def create_volume(conn): - data = { - "volume": { - "availability_zone": "az1.dc1", - "size": 10, - "name": "new_kakakak", - "volume_type": "SSD", - "count": 1, - "metadata": { - "__system__encrypted": "0", - "hw:passthrough": "false" - }, - "multiattach": "true" - } - } - - ff = conn.evs.create_volume(**data) - print ff - - -def resize_volume(conn): - volume_id = '16d4b5e1-f613-4a1c-a92c-b40df63ba35f' - data = { - "os-extend": { - "new_size": 15 - } - } - - ff = conn.evs.resize_volume(volume_id=volume_id, **data) - print ff - - -def create_volume_ext(conn): - data = { - "volume": { - "availability_zone": "az1.dc1", - "size": 120, - "name": "_kakakak", - "volume_type": "SSD", - "count": 1, - "metadata": { - "__system__encrypted": "0", - "hw:passthrough": "false" - }, - "multiattach": "true" - }, - "bssParam": { - "chargingMode": "prePaid", - "periodType": "year", - "periodNum": 1, - "isAutoPay": "true", - "isAutoRenew": "true" - } - } - - ff = conn.evs.create_volume_ext(**data) - print ff - - -def resize_volume_ext(conn): - volume_id = 'ad2c5328-e734-4600-a54e-8b25477b97e2' - data = { - "os-extend": { - "new_size": 150 - }, - "bssParam": { - "chargingMode": "prePaid", - "isAutoPay": "true" - } - } - - ff = conn.evs.resize_volume_ext(volume_id=volume_id, **data) - print ff diff --git a/examples/identity/__init__.py b/examples/identity/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/identity/list.py b/examples/identity/list.py deleted file mode 100644 index fff73a5..0000000 --- a/examples/identity/list.py +++ /dev/null @@ -1,108 +0,0 @@ -# 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. - -""" -List resources from the Identity service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def list_users(conn): - print("List Users:") - - for user in conn.identity.users(): - print(user) - - -def list_credentials(conn): - print("List Credentials:") - - for credential in conn.identity.credentials(): - print(credential) - - -def list_projects(conn): - print("List Projects:") - - for project in conn.identity.projects(): - print(project) - - -def list_domains(conn): - print("List Domains:") - - for domain in conn.identity.domains(): - print(domain) - - -def list_groups(conn): - print("List Groups:") - - for group in conn.identity.groups(): - print(group) - - -def list_services(conn): - print("List Services:") - - for service in conn.identity.services(): - print(service) - - -def list_endpoints(conn): - print("List Endpoints:") - - for endpoint in conn.identity.endpoints(): - print(endpoint) - - -def list_regions(conn): - print("List Regions:") - - for region in conn.identity.regions(): - print(region) - - -def list_roles(conn): - print("List Roles:") - - for role in conn.identity.roles(): - print(role) - - -def list_role_domain_group_assignments(conn): - print("List Roles assignments for a group on domain:") - - for role in conn.identity.role_domain_group_assignments(): - print(role) - - -def list_role_domain_user_assignments(conn): - print("List Roles assignments for a user on domain:") - - for role in conn.identity.role_project_user_assignments(): - print(role) - - -def list_role_project_group_assignments(conn): - print("List Roles assignments for a group on project:") - - for role in conn.identity.role_project_group_assignments(): - print(role) - - -def list_role_project_user_assignments(conn): - print("List Roles assignments for a user on project:") - - for role in conn.identity.role_project_user_assignments(): - print(role) diff --git a/examples/image/__init__.py b/examples/image/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/image/create.py b/examples/image/create.py deleted file mode 100644 index ccc781d..0000000 --- a/examples/image/create.py +++ /dev/null @@ -1,53 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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 examples.connect import EXAMPLE_IMAGE_NAME - -""" -Create resources with the Image service. - -For a full guide see -http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html -""" - - -def upload_image(conn): - print("Upload Image:") - - # Load fake image data for the example. - data = 'This is fake image data.' - - # Build the image attributes and upload the image. - image_attrs = { - 'name': EXAMPLE_IMAGE_NAME, - 'data': data, - 'disk_format': 'raw', - 'container_format': 'bare', - 'visibility': 'public', - } - conn.image.upload_image(**image_attrs) diff --git a/examples/image/delete.py b/examples/image/delete.py deleted file mode 100644 index 6cc5d2b..0000000 --- a/examples/image/delete.py +++ /dev/null @@ -1,44 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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 examples.connect import EXAMPLE_IMAGE_NAME - -""" -Delete resources with the Image service. - -For a full guide see -http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html -""" - - -def delete_image(conn): - print("Delete Image:") - - example_image = conn.image.find_image(EXAMPLE_IMAGE_NAME) - - conn.image.delete_image(example_image, ignore_missing=False) diff --git a/examples/image/download.py b/examples/image/download.py deleted file mode 100644 index 7e6d52d..0000000 --- a/examples/image/download.py +++ /dev/null @@ -1,79 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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. - -import hashlib - -""" -Download an image with the Image service. - -For a full guide see -http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html -""" - - -def download_image_stream(conn): - print("Download Image via streaming:") - - # Find the image you would like to download. - image = conn.image.find_image("myimage") - - # As the actual download now takes place outside of the library - # and in your own code, you are now responsible for checking - # the integrity of the data. Create an MD5 has to be computed - # after all of the data has been consumed. - md5 = hashlib.md5() - - with open("myimage.qcow2", "wb") as local_image: - response = conn.image.download_image(image, stream=True) - - # Read only 1024 bytes of memory at a time until - # all of the image data has been consumed. - for chunk in response.iter_content(chunk_size=1024): - # With each chunk, add it to the hash to be computed. - md5.update(chunk) - - local_image.write(chunk) - - # Now that you've consumed all of the data the response gave you, - # ensure that the checksums of what the server offered and - # what you downloaded are the same. - if response.headers["Content-MD5"] != md5.hexdigest(): - raise Exception("Checksum mismatch in downloaded content") - - -def download_image(conn): - print("Download Image:") - - # Find the image you would like to download. - image = conn.image.find_image("myimage") - - with open("myimage.qcow2", "w") as local_image: - response = conn.image.download_image(image) - - # Response will contain the entire contents of the Image. - local_image.write(response) diff --git a/examples/image/list.py b/examples/image/list.py deleted file mode 100644 index 0be111b..0000000 --- a/examples/image/list.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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. -# -# Huawei has modified this source file. -# -# Copyright 2018 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. - -""" -List resources from the Image service. - -For a full guide see -http://developer.openstack.org/sdks/python/openstacksdk/users/guides/image.html -""" - - -def list_images(conn): - print("List Images:") - - for image in conn.image.images(): - print(image) diff --git a/examples/key_manager/__init__.py b/examples/key_manager/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/key_manager/create.py b/examples/key_manager/create.py deleted file mode 100644 index c45e7dc..0000000 --- a/examples/key_manager/create.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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. - -""" -List resources from the Key Manager service. -""" - - -def create_secret(conn): - print("Create a secret:") - - conn.key_manager.create_secret(name="My public key", - secret_type="public", - expiration="2020-02-28T23:59:59", - payload="ssh rsa...", - payload_content_type="text/plain") diff --git a/examples/key_manager/get.py b/examples/key_manager/get.py deleted file mode 100644 index 0025dd6..0000000 --- a/examples/key_manager/get.py +++ /dev/null @@ -1,26 +0,0 @@ -# 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. - -""" -List resources from the Key Manager service. -""" - -s = None - - -def get_secret_payload(conn): - print("Get a secret's payload:") - - # Assuming you have an object `s` which you perhaps received from - # a conn.key_manager.secrets() call... - secret = conn.key_manager.get_secret(s.secret_id) - print(secret.payload) diff --git a/examples/key_manager/list.py b/examples/key_manager/list.py deleted file mode 100644 index b74e4df..0000000 --- a/examples/key_manager/list.py +++ /dev/null @@ -1,31 +0,0 @@ -# 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. - -""" -List resources from the Key Manager service. -""" - - -def list_secrets(conn): - print("List Secrets:") - - for secret in conn.key_manager.secrets(): - print(secret) - - -def list_secrets_query(conn): - print("List Secrets:") - - for secret in conn.key_manager.secrets( - secret_type="symmetric", - expiration="gte:2020-01-01T00:00:00"): - print(secret) diff --git a/examples/kms/__init__.py b/examples/kms/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/kms/kms.py b/examples/kms/kms.py deleted file mode 100644 index 2a9babf..0000000 --- a/examples/kms/kms.py +++ /dev/null @@ -1,89 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing key by KMS - -""" - - -def keys(conn): - print("List encript keys") - for k in conn.kms.keys(): - print(conn.kms.describe_key(k)) - - -def create_key(conn): - key_dict = { - "key_alias": "test-key-123-456789223", - "realm": "cn-north-1eu-deaaa" - } - key = conn.kms.create_key(**key_dict) - print(key) - - -def enable_key(conn, key): - # a string of key id or an object of Key - print(conn.kms.enable_key(key)) - - -def disable_key(conn, key): - # a string of key id or an object of Key - print(conn.kms.disable_key(key)) - - -def delete_key(conn, key): - # a string of key id or an object of Key - print(conn.kms.schedule_deletion_key(key, 7)) - - -def cancel_delete_key(conn, key): - # a string of key id or an object of Key - print(conn.kms.cancel_deletion_key(key)) - - -def create_random(conn): - print(conn.kms.gen_random(random_data_length=512)) - - -def create_data_key(conn, key): - # a string of key id or an object of Key - data_key_dict = { - "datakey_length": "512" - } - print(conn.kms.create_datakey(key, **data_key_dict)) - - print(conn.kms.create_datakey_wo_plain(key, **data_key_dict)) - - -def encrypt_datakey(conn, key): - params = { - "plain_text": "fooofofoofofofofoofofoffofoofo", - "datakey_plain_length": "64" - } - datakey = conn.kms.encrypt_datakey(key, **params) - print(datakey) - params = { - "datakey_cipher_length": "64" - } - print(conn.kms.decrypt_datakey(datakey, **params)) - - -def get_instance_number(conn): - print(conn.kms.get_instance_number()) - - -def list_quota(conn): - for q in conn.kms.get_quota(): - print(q) diff --git a/examples/load_balancer/__init__.py b/examples/load_balancer/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/load_balancer/load_balancer.py b/examples/load_balancer/load_balancer.py deleted file mode 100644 index a0393be..0000000 --- a/examples/load_balancer/load_balancer.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -''' -List resources from the Load Balancer service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -''' - - -# import sys - -# from openstack import utils - - -def list_loadbalancers(conn): - print('List Load Balancer:') - query = { - # 'vip_address': '192.168.2.36' - # 'name': 'elb-yc5f' - } - for load_balancer in conn.load_balancer.load_balancers(**query): - print(load_balancer) - - -def create_load_balancer(conn): - lb = { - 'name': 'elb-python-sdk-1', - 'type': 'Internal', - 'bandwidth': 200, - 'availability_zone': 'eu-de', - 'security_group_id': '0005ba27-b937-4a7c-a280-c7b65cea2e47', - 'vpc_id': '31d158b8-e7d7-4b4a-b2a7-a5240296b267', - 'vip_subnet_id': 'cb9a6ede-39c6-498f-ad85-c554ef7220fc', - 'vip_address': '192.168.2.36', - 'admin_state_up': 0, - 'description': 'elb-python-sdk-1 description' - } - conn.load_balancer.create_load_balancer(**lb) - - -def get_load_balancer(conn): - conn.load_balancer.get_load_balancer('lb_id') - - -def delete_load_balancer(conn): - conn.load_balancer.delete_load_balancer('lb_id') diff --git a/examples/maas/__init__.py b/examples/maas/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/maas/maas.py b/examples/maas/maas.py deleted file mode 100644 index 5582b50..0000000 --- a/examples/maas/maas.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing maas - -""" - - -def create_task(conn): - task_dict = { - "src_node": - { - "region": "source_region", - "ak": "source_ak", - "sk": "source_sk", - "object_key": - { - "path": "log/", - "keys": ["object1", "object2"] - }, - "bucket": "source_bucket" - }, - "thread_num": 5, - "enableKMS": True, - "dst_node": - { - "region": "target_region", - "ak": "target_ak", - "sk": "target_sk", - "object_key": "targetkey", - "bucket": "targetbucket" - }, - } - - task = conn.maas.create_task(**task_dict) - print(task) - - -def tasks(conn): - query = { - 'start': '0', - 'limit': '10'} - for t in conn.maas.tasks(**query): - print(t) - - -def task_count(conn): - print(conn.maas.task_count('0')) diff --git a/examples/nat/__init__.py b/examples/nat/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/nat/dnat_rule.py b/examples/nat/dnat_rule.py deleted file mode 100644 index e7cfbfd..0000000 --- a/examples/nat/dnat_rule.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import sys -import os -from openstack import connection -from openstack import utils - -utils.enable_logging(debug = True, stream = sys.stdout) - -username = "***" -password = "***" -projectId = "054efa2069a64785a196efe56c05ee74" -userDomainId = "cb06f3a9fa4e464ea62695b4dd26e5f0" -auth_url = "https://iam.eu-de.otc.t-systems.com/v3" - -conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password, - verify=False - ) - -nats = conn.nat.create_dnat_rule(nat_gateway_id = "8d45f435-61f7-4a30-b955-ae40f3e3989b", - floating_ip_id = "dd05c596-fde4-491f-bc1b-24f2d7e3e623", - protocol = "TCP", - external_service_port = 6000, - internal_service_port = 5000, - port_id = "66db34af-2eba-4356-b7b8-9e5f71b3a5dd" - ) -print nats - - -print conn.nat.get_dnat_rule('5e465a4f-30ec-4f73-8ec7-5820fda6930c') -print conn.nat.delete_dnat_rule("5e465a4f-30ec-4f73-8ec7-5820fda6930c") -nats = conn.nat.dnat_rules() -for dnat in nats: - print dnat \ No newline at end of file diff --git a/examples/nat/nat_gateway.py b/examples/nat/nat_gateway.py deleted file mode 100644 index 094bc27..0000000 --- a/examples/nat/nat_gateway.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import sys -import warnings - -from openstack import utils -from openstack import connection - -utils.enable_logging(debug=False, stream=sys.stdout) -warnings.filterwarnings('ignore') - -auth_url = 'https://iam.eu-de.otc.t-systems.com/v3' -userDomainId = 'cb06f3a9fa4e464ea62695b4dd26e5f0' -projectId = '054efa2069a64785a196efe56c05ee74' -username = 'zhanggaofeng' -password = 'Ok_1102$123' - -conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password, - verify=False -) - -# list nat_gateway -nat_gateways = conn.nat.nat_gateways() -for nat_gateway in nat_gateways: - print(nat_gateway) - -# update nat_gateway -id = '8d45f435-61f7-4a30-b955-ae40f3e3989b' -data = { - 'name': 'nat-test-update-x2', - 'description': 'a nat description', - 'spec': '3' -} -update_nat_gateway = conn.nat.update_nat_gateway(id, **data) -print(update_nat_gateway) - -nat = conn.nat.create_nat_gateway(router_id='7c7d9bf6-9431-4366-9be2-e0caea8eb382', - name='yyx-test-nat', - description='dddd', - internal_network_id='8719d692-a4e9-4dbc-bba1-15afd13c4ce5', - spec='1') - -print nat - -print conn.nat.get_nat_gateway('8d45f435-61f7-4a30-b955-ae40f3e3989b') - -print conn.nat.delete_nat_gateway('8d45f435-61f7-4a30-b955-ae40f3e3989b') diff --git a/examples/nat/snat_rule.py b/examples/nat/snat_rule.py deleted file mode 100644 index 72dcba6..0000000 --- a/examples/nat/snat_rule.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import sys -import warnings -import time - -from openstack import utils -from openstack import connection - -utils.enable_logging(debug=False, stream=sys.stdout) -warnings.filterwarnings('ignore') - -auth_url = 'https://iam.eu-de.otc.t-systems.com/v3' -userDomainId = 'cb06f3a9fa4e464ea62695b4dd26e5f0' -projectId = '054efa2069a64785a196efe56c05ee74' -username = 'zhanggaofeng' -password = 'Ok_1102$123' - -conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password, - verify=False -) - -rule_id = '' - -# create snat_rule -print('create_snat_rule:') -data = { - 'nat_gateway_id': '8d45f435-61f7-4a30-b955-ae40f3e3989b', - 'network_id': '247e2ef9-4625-4cfd-870a-f128f6f38acf', - 'floating_ip_id': 'dd05c596-fde4-491f-bc1b-24f2d7e3e623' -} -snat_rule = conn.nat.create_snat_rule(**data) -print(snat_rule) -rule_id = snat_rule.id -print('rule_id: ' + rule_id) -print('>>>') - -# get snat_rule -print('get_snat_rule:') -snat_rule = conn.nat.get_snat_rule(rule_id) -print(snat_rule) -print('>>>') - -# list snat_rule -print('snat_rules:') -snat_rules = conn.nat.snat_rules() -for snat_rule in snat_rules: - print(snat_rule) -print('>>>') - -# delete snat_rule -print('delete_snat_rule:') -deleteObj = conn.nat.delete_snat_rule(rule_id) -print(deleteObj) -print('Deleting... Please wait 3 seconds.') -time.sleep(3) -print('>>>') - -# list snat_rule -print('snat_rules:') -snat_rules = conn.nat.snat_rules() -for snat_rule in snat_rules: - print(snat_rule) diff --git a/examples/network/create.py b/examples/network/create.py deleted file mode 100644 index f89387b..0000000 --- a/examples/network/create.py +++ /dev/null @@ -1,35 +0,0 @@ -# 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. - -""" -Create resources with the Network service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def create_network(conn): - print("Create Network:") - - example_network = conn.network.create_network( - name='openstacksdk-example-project-network') - - print(example_network) - - example_subnet = conn.network.create_subnet( - name='openstacksdk-example-project-subnet', - network_id=example_network.id, - ip_version='4', - cidr='10.0.2.0/24', - gateway_ip='10.0.2.1') - - print(example_subnet) diff --git a/examples/network/delete.py b/examples/network/delete.py deleted file mode 100644 index 41e7a3b..0000000 --- a/examples/network/delete.py +++ /dev/null @@ -1,28 +0,0 @@ -# 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. - -""" -Delete resources with the Network service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def delete_network(conn): - print("Delete Network:") - - example_network = conn.network.find_network( - 'openstacksdk-example-project-network') - - for example_subnet in example_network.subnet_ids: - conn.network.delete_subnet(example_subnet, ignore_missing=False) - conn.network.delete_network(example_network, ignore_missing=False) diff --git a/examples/network/find.py b/examples/network/find.py deleted file mode 100644 index 1d9005d..0000000 --- a/examples/network/find.py +++ /dev/null @@ -1,29 +0,0 @@ -# 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. - -import examples.connect - -""" -Find a resource from the Network service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def find_network(conn): - print("Find Network:") - - network = conn.network.find_network(examples.connect.NETWORK_NAME) - - print(network) - - return network diff --git a/examples/network/list.py b/examples/network/list.py deleted file mode 100644 index ff85e1c..0000000 --- a/examples/network/list.py +++ /dev/null @@ -1,59 +0,0 @@ -# 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. - -""" -List resources from the Network service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def list_networks(conn): - print("List Networks:") - - for network in conn.network.networks(): - print(network) - - -def list_subnets(conn): - print("List Subnets:") - - for subnet in conn.network.subnets(): - print(subnet) - - -def list_ports(conn): - print("List Ports:") - - for port in conn.network.ports(): - print(port) - - -def list_security_groups(conn): - print("List Security Groups:") - - for port in conn.network.security_groups(): - print(port) - - -def list_routers(conn): - print("List Routers:") - - for router in conn.network.routers(): - print(router) - - -def list_network_agents(conn): - print("List Network Agents:") - - for agent in conn.network.agents(): - print(agent) diff --git a/examples/network/security_group_rules.py b/examples/network/security_group_rules.py deleted file mode 100644 index b2cf42d..0000000 --- a/examples/network/security_group_rules.py +++ /dev/null @@ -1,57 +0,0 @@ -# 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. - -""" -Create resources with the Network service. - -For a full guide see TODO(etoews):link to docs on developer.openstack.org -""" - - -def open_port(conn): - print("Open a port:") - - example_sec_group = conn.network.create_security_group( - name='openstacksdk-example-security-group') - - print(example_sec_group) - - example_rule = conn.network.create_security_group_rule( - security_group_id=example_sec_group.id, - direction='ingress', - remote_ip_prefix='0.0.0.0/0', - protocol='HTTPS', - port_range_max='443', - port_range_min='443', - ethertype='IPv4') - - print(example_rule) - - -def allow_ping(conn): - print("Allow pings:") - - example_sec_group = conn.network.create_security_group( - name='openstacksdk-example-security-group2') - - print(example_sec_group) - - example_rule = conn.network.create_security_group_rule( - security_group_id=example_sec_group.id, - direction='ingress', - remote_ip_prefix='0.0.0.0/0', - protocol='icmp', - port_range_max=None, - port_range_min=None, - ethertype='IPv4') - - print(example_rule) diff --git a/examples/network/ulb.py b/examples/network/ulb.py deleted file mode 100644 index 8fc6fa5..0000000 --- a/examples/network/ulb.py +++ /dev/null @@ -1,241 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import sys -from openstack import connection -from openstack import utils -import time - -utils.enable_logging(debug = True, stream = sys.stdout) - -username = "***" -password = "***" -projectId = "128a7bf965154373a7b73c89eb6b65aa" -userDomainId = "3b011b89b2f64fb68782a43380e2a78f" -auth_url = "https://iam.cn-north-1.myhwclouds.com/v3" - -conn = connection.Connection( - auth_url=auth_url, - user_domain_id=userDomainId, - project_id=projectId, - username=username, - password=password, - verify=False - ) - -def test_ulb(): - lbs = conn.network.loadbalancers() - for lb in lbs: - print lb.id - lb = conn.network.get_loadbalancer("fd18b88e-e75f-46d6-984e-753eb56d7b17") - print lb - - st = conn.network.get_loadbalancer_status_stree("fd18b88e-e75f-46d6-984e-753eb56d7b17") - print st - - st = conn.network.update_loadbalancer('fd18b88e-e75f-46d6-984e-753eb56d7b17',description = 'this is test') - - lb = conn.network.create_loadbalancer(name = 'ulb-test', - tenant_id = '128a7bf965154373a7b73c89eb6b65aa', - vip_subnet_id ='20b8a44b-e724-4103-8233-f70c7aa1bbc2', - provider = "vlb", - admin_state_up = True, - description = 'this is a test' - ) - time.sleep(10) - conn.network.delete_loadbalancer(lb) - - lss = conn.network.listeners() - for ls in lss: - print ls - - ls = conn.network.create_listener( - protocol_port = '80', - protocol = 'HTTP', - loadbalancer_id = 'fd18b88e-e75f-46d6-984e-753eb56d7b17' - ) - lsn = conn.network.get_listener('c188ba92-8a1b-416e-9ec6-75b9826be486') - - conn.network.update_listener(lsn, name = 'test-listener') - - conn.network.get_listener('c188ba92-8a1b-416e-9ec6-75b9826be486') - - conn.network.delete_listener('c188ba92-8a1b-416e-9ec6-75b9826be486') - pos = conn.network.pools() - for p in pos: - print p.listener_id - p = conn.network.update_pool('ad1044de-fcd7-405c-9542-650f857b0c25', description = "this is test pool") - p = conn.network.create_pool( - lb_algorithm = "LEAST_CONNECTIONS", - protocol = "HTTP", - loadbalancer_id = 'fd18b88e-e75f-46d6-984e-753eb56d7b17', - admin_state_up = True, - name = "pool-test-lb", - description="this is test pool,create with lb-id" - ) - print p - print conn.network.get_pool('ad1044de-fcd7-405c-9542-650f857b0c25') - conn.network.delete_pool('5c0517a6-9157-4ce1-b078-def2550fb4f4') - ms = conn.network.members(pool_id = 'ad1044de-fcd7-405c-9542-650f857b0c25') - for m in ms: - print m - m = conn.network.create_member( - name = "test-member", - address = '192.168.1.165', - protocol_port= 6000, - subnet_id = '20b8a44b-e724-4103-8233-f70c7aa1bbc2', - admin_state_up = True, - pool_id = 'ad1044de-fcd7-405c-9542-650f857b0c25' - ) - print conn.network.get_member('8366279f-54af-4b0e-b9eb-d96405b2e726', pool = 'ad1044de-fcd7-405c-9542-650f857b0c25') - print conn.network.update_member('8366279f-54af-4b0e-b9eb-d96405b2e726', name = 'updated-name',pool_id = 'ad1044de-fcd7-405c-9542-650f857b0c25') - conn.network.delete_member('8366279f-54af-4b0e-b9eb-d96405b2e726',pool = 'ad1044de-fcd7-405c-9542-650f857b0c25') - hms = conn.network.healthmonitors() - for hm in hms: - print hm - print conn.network.get_healthmonitor('08eac2e1-7d78-43b1-b210-afd801045897') - - healthmonitor = conn.network.create_healthmonitor( - # must parameter - # 'HTTP', 'HTTPS', 'PING', 'TCP', 'UDP_CONNECT' - type = 'HTTP', - delay = 10, - timeout = 5, - max_retries = 3, - pool_id = 'ad1044de-fcd7-405c-9542-650f857b0c25', - # optional parameter - tenant_id = '128a7bf965154373a7b73c89eb6b65aa', - name = 'hm_name_by_create', - admin_state_up = True, - monitor_port = 8000, - expected_codes = '200', - url_path = '/', - http_method = 'GET' - ) - print 'print start >' - print healthmonitor - print '< print end' - - print conn.network.update_healthmonitor('08eac2e1-7d78-43b1-b210-afd801045897',delay = 10, - max_retries= 3, - name = 'updated-name', - timeout = 3, - http_method='GET', - expected_codes = '200', - url_path = '/', - monitor_port = 8000 - ) - conn.network.delete_healthmonitor("08eac2e1-7d78-43b1-b210-afd801045897") - data = { - "action": "REDIRECT_TO_POOL", - "listener_id": "11d633e3-ea9f-4e14-bd87-2d2866d347fd", - "redirect_pool_id": "3a412129-863e-430e-a03a-aa6c66a7827e", - "name": "test-policy", - "admin_state_up": True - } - - print conn.network.create_policy(**data) - pls = conn.network.poliycies() - for pl in pls: - print pl - print conn.network.get_policy("a1154af3-9bdf-4fd8-9c96-f63b93319c7e") - print conn.network.update_policy("a1154af3-9bdf-4fd8-9c96-f63b93319c7e", name = "update-policy", description = "this is a test") - conn.network.delete_policy("a1154af3-9bdf-4fd8-9c96-f63b93319c7e") - print conn.network.get_policy("a1154af3-9bdf-4fd8-9c96-f63b93319c7e") - - print conn.network.create_rule( - policy_id = '561fdc6c-c4e1-40c7-8eff-9926c34c30c2', - type = 'HOST_NAME', - compare_type = 'EQUAL_TO', - value = '100' - - ) - - rs = conn.network.rules(policy_id = '561fdc6c-c4e1-40c7-8eff-9926c34c30c2') - for r in rs: - print r - print conn.network.get_rule( "fcd3fe4f-7651-4279-a000-d5dcee182fed",'561fdc6c-c4e1-40c7-8eff-9926c34c30c2') - print conn.network.update_rule("fcd3fe4f-7651-4279-a000-d5dcee182fed", - policy_id = '561fdc6c-c4e1-40c7-8eff-9926c34c30c2', - rule_value = "test" - ) - conn.network.delete_rule("fcd3fe4f-7651-4279-a000-d5dcee182fed",'561fdc6c-c4e1-40c7-8eff-9926c34c30c2') - - #whitelist get - whitelist = conn.network.get_whitelist( - '7d70c81c-ebb9-4740-87b9-521eb3524915' - ) - print 'print start >' - print whitelist - print '< print end' - - #whitelist list - whitelists = conn.network.whitelists( - # listener_id='76323057-293c-4154-936d-ae5a245492c9', - # id = '***', - # enable_whitelist = True, - # whitelist = '***' - ) - print 'print start >' - for whitelist in whitelists: - print whitelist - print '< print end' - - #whitelist create - whitelist = conn.network.create_whitelist( - # must parameter - listener_id = '76323057-293c-4154-936d-ae5a245492c9', - # optional parameter - tenant_id = '128a7bf965154373a7b73c89eb6b65aa', - enable_whitelist = True, - whitelist = '192.168.0.3,192.168.0.6,192.168.0.9' - ) - # print 'print start >' - print whitelist - print '< print end' - - #whitelist delete - conn.network.delete_whitelist( - '7d70c81c-ebb9-4740-87b9-521eb3524915' - ) - - #whitelist update - whitelist = { - 'enable_whitelist': True, - 'whitelist': '192.168.0.62,192.168.0.82,192.168.0.92' - } - update_whitelist = conn.network.update_whitelist( - '7d70c81c-ebb9-4740-87b9-521eb3524915', - **whitelist - ) - cers = conn.network.certificates() - for cer in cers: - print cer - print conn.network.get_certificate('a173f078ff644a4a96e4a84ed854c4b0') - - data = { - 'name' : 'yyxtest', - 'type': 'server', - 'private_key':"-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEA53b//XxsH/oKhMitHnJDRfNU+VeBLbnJeh2j3Jp5tXdkwIENqKjgC17lMtboKvupwBTlqSCFIeVfdu1rLsKsV7p4uWTDM8+lqbrN4qQ26OtEF5Nc9/4jVRCqe6hHR8l4g+B5aOPz0Nz4gn4XRI83c/iSninGy1ewc2C8nmAcNRxsP69AfOBtkp9tr83QmmNQEdj7sXjAsPvlRz3SV5rpE687vIBlJUGUTX+hdhJc/vMfLqmHpDFJI9IqfLPH1bPQ1ZKZmqAucxENCZM7LV24iew061uy8XmLhYHWXMvozQX5MjmM8RhIZIUua0GxS5sk0KQul3a/WgmuydMITijIaQIDAQABAoIBABkq8U7ItqELeRVTFK/Y0MPMX5L1FtC4ANZMXsLf8RfwMX5VCf0qz6Gs4dMTVw9FagG+w/IN3SwAWs79pcfh1wd6+SF/eVIq4+J+s2BPZsEQw8ikd1lnwsO/Gipz87w0hewg/lKPZrVxMXxO5YzI3ci4YIjeFgWKNV92R0wZOzfy+EhpkRGv4KcowoOXhMqAvXdPklSTMk66cOFOXTtzSPOBAsTjWquScW3QTP19HtGZgaCnSmIjqAocmN6ZpHOFEC9sxf1cZ9DMgPwKLz0+qL+liAA+yx6J92kITRYzw1/7Px+O2g1ZGrHKN79Y02TOJD3ohbq3wqeLTET8nprFltkCgYEA958bXxqnJL2pjVHMABUIKl+eTff/bks909Z+B4uDRUXCR0l5u6zP6eFsDnCQxjMm3mI0ekh0yQRfBWzwUxUyLDXxJs2a4ZiYt+SC0dQtoTMSqB1svZm7sq422iBRHFCZ9g8f4RWYkARdEbz4gF8YFN2M2tIaNXluLKNdwW6JjZMCgYEA70vxvAx5JYQ4/uQBXqN6VMF+8tapbesj5J2J4rrUcjMputRgtJLqn9nfT4/00x+026D0jEPhfyAS1MM5rsPB0Li+Wl3/ubvsKXDSyl2la/eRNc15Sqbz4TYlC2DgeylXbHCOFOTxBoQMd3FD2P5GhwCkqxhwGq3iJKnpL1Qnr5MCgYA2w2tsRxq8F24OIQ763avmoysBl11YaS+NUByjUol/ooPq/Cb+CKQa143sS5zZGKr598IfYTLi2iKhsowb884a1Ps2V7ZvOi5cTR9ZhJFq2z6/C3LnI77NL5ZV+1u05WaHcqTcRMhu4Wgr6h0TVvSeeLkUE+9T8D0bhi3P/8BQHQKBgDZ7OvFOgbKJ9RQLQ0iRvcNYPpf5SZ/t/kEJoSAO21mYznJr8gyKuoJkb1RE+T+sI1gxwBvDRK7V1ZO9Uv+4MANeXHBkoFlgMLeKqWNLiOMY/WWbf3cApdvroOmDR/iig/X7dk3Jhhquq8vx7LmVwubvvY36xWM9nZQtXxrYdSSjAoGAX1PvpF2zIn47mI+rcyEJKlY3aEaQAc0xL6h11C2074ASBx8t3/FO0hyJqD9sp3iaoL7OdP9XG1zRi6E7B17ibaMXCzHFTek05xhZj1SxylxF1/Qu4ZZZXZsHRQ4QGwp93CjLqL5RJ3RyrvZGmxh0jEuYdJnq+i7U44e+yvIVFd8=\n-----END RSA PRIVATE KEY-----", - 'certificate':"-----BEGIN CERTIFICATE-----\nMIIELTCCAxWgAwIBAgIJAJU5p3WMgr37MA0GCSqGSIb3DQEBBQUAMGwxCzAJBgNVBAYTAnh4MQswCQYDVQQIEwJ4eDELMAkGA1UEBxMCeHgxCzAJBgNVBAoTAnh4MQswCQYDVQQLEwJ4eDELMAkGA1UEAxMCeHgxHDAaBgkqhkiG9w0BCQEWDXh4QGh1YXdlaS5jb20wHhcNMTcxMDMxMDczMTQxWhcNMjAxMDMwMDczMTQxWjBsMQswCQYDVQQGEwJ4eDELMAkGA1UECBMCeHgxCzAJBgNVBAcTAnh4MQswCQYDVQQKEwJ4eDELMAkGA1UECxMCeHgxCzAJBgNVBAMTAnh4MRwwGgYJKoZIhvcNAQkBFg14eEBodWF3ZWkuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA53b//XxsH/oKhMitHnJDRfNU+VeBLbnJeh2j3Jp5tXdkwIENqKjgC17lMtboKvupwBTlqSCFIeVfdu1rLsKsV7p4uWTDM8+lqbrN4qQ26OtEF5Nc9/4jVRCqe6hHR8l4g+B5aOPz0Nz4gn4XRI83c/iSninGy1ewc2C8nmAcNRxsP69AfOBtkp9tr83QmmNQEdj7sXjAsPvlRz3SV5rpE687vIBlJUGUTX+hdhJc/vMfLqmHpDFJI9IqfLPH1bPQ1ZKZmqAucxENCZM7LV24iew061uy8XmLhYHWXMvozQX5MjmM8RhIZIUua0GxS5sk0KQul3a/WgmuydMITijIaQIDAQABo4HRMIHOMB0GA1UdDgQWBBRl/kItQ4EVKVSo+8Ic+LMYgrekmzCBngYDVR0jBIGWMIGTgBRl/kItQ4EVKVSo+8Ic+LMYgrekm6FwpG4wbDELMAkGA1UEBhMCeHgxCzAJBgNVBAgTAnh4MQswCQYDVQQHEwJ4eDELMAkGA1UEChMCeHgxCzAJBgNVBAsTAnh4MQswCQYDVQQDEwJ4eDEcMBoGCSqGSIb3DQEJARYNeHhAaHVhd2VpLmNvbYIJAJU5p3WMgr37MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAN+eExoMQ717UK8dWmLSWblcoN0w74AQ6tCS8wcFsS3c5TK8UkiGd5lMms8pp6V61jwzuJEDxm8Fwa2107pF06gMTPVg4qeRmAzCJZGhNtul0Ba5KDXWPI6PZx1ipP2jdlqme5hjexw0pBDYzGOomxNToXv2DBBNXtT5VH4F3pvLJo+Ai2yxd5PAHRHBrvLyic2tCBO1GRQx7Jrpooc82fm84s5MZjdy0I7lzTnm1krT8dRg2uKVUkhDZhB96MAj6Mx0hIqlrfMQbLoSvpAyMDyX58xkE2j5N899ZNj211zhzrX/Ikb4+KBX+Wat+5LJeAo42c5gVohkzAUe3Kc0xRc=\n-----END CERTIFICATE-----" - } - print conn.network.create_certificate(**data) - print conn.network.update_certificate('b17e4b9086944f4aa8b6b9c348a26008', name = 'updated-certificate') - print conn.network.delete_certificate('b17e4b9086944f4aa8b6b9c348a26008') - print conn.network.get_certificate('b17e4b9086944f4aa8b6b9c348a26008') - - - -if __name__ == "__main__": - test_ulb() \ No newline at end of file diff --git a/examples/network/vpn_service_test.py b/examples/network/vpn_service_test.py deleted file mode 100644 index 719876d..0000000 --- a/examples/network/vpn_service_test.py +++ /dev/null @@ -1,377 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -import sys - -from openstack import connection -from openstack import exceptions as _exceptions -from openstack import utils - -# logging.basicConfig() -utils.enable_logging(debug=True, stream=sys.stdout) - - -class __BaseVpnService(object): - username = "zhoulei" - password = "sssss" - projectId = "054efa2069a64785a196efe56c05ee74" - userDomainId = "cb06f3a9fa4e464ea62695b4dd26e5f0" - auth_url = "https://iam.eu-de.otc.t-systems.com/v3" - - def __init__(self, debug=False): - utils.enable_logging(debug=debug, stream=sys.stdout) - try: - self.conn = connection.Connection(auth_url=self.auth_url, - user_domain_id=self.userDomainId, - project_id=self.projectId, - username=self.username, - password=self.password, - verify=False) - except _exceptions.InvalidRequest as e: - raise _exceptions.InvalidRequest(message='init connect error') - - -class VPNService(__BaseVpnService): - def create_vpn_service(self): - data = { - "subnet_id": None, - "router_id": "12a5ead9-9b93-4ac9-b28e-ba0992ac8a85", - "name": "myservice", - "admin_state_up": True, - } - - ff = self.conn.network.create_vpn_service(**data) - print ff - - def for_test(self): - ff = self.conn.network.networks() - - network = [i for i in ff] - data = { - "subnet_id": None, - "router_id": "12a5ead9-9b93-4ac9-b28e-ba0992ac8a85", - "name": "myservice", - "admin_state_up": True, - } - # data.update({'router_id': network[0].name}) - ff = self.conn.network.create_vpn_service(**data) - return ff - - def get_vpn_services(self): - ff = self.conn.network.vpn_services() - return ff - - def get_vpn_service(self, vpn_id): - ff = self.conn.network.get_vpn_service(vpn_id) - print ff - - def find_vpn_service(self, vpn_id): - ff = self.conn.network.find_vpn_service(vpn_id) - print ff - - def detele_vpn_service(self, vpn_id): - ff = self.conn.network.delete_vpn_service(vpn_id) - print ff - - def update_vpn_service(self, vpn_id): - ff = self.conn.network.update_vpn_service(vpn_id) - print ff - - -class IPSecPolicy(__BaseVpnService): - def create_ipsec_service(self): - data = { - "name": "ipsecpolicy1sdfasdfasdfasdf", - "transform_protocol": "esp", - "auth_algorithm": "sha1", - "encapsulation_mode": "tunnel", - "encryption_algorithm": "aes-128", - "pfs": "group14", - "lifetime": { - "units": "seconds", - "value": 1212 - }, - "description": "ZLZLZLZ" - } - - ff = self.conn.network.create_ipsec_policy(**data) - return ff - - def get_ipsecs(self): - ff = self.conn.network.get_ipsec_policy() - return ff - - def get_ipsec_from_id(self, ipsecpolicy_id): - ff = self.conn.network.find_ipsec_policy(ipsecpolicy_id) - print ff - - def delete_ipsec(self, policy_id): - ff = self.conn.network.delete_ipsec_policy(policy_id) - print ff - - def modify_ipsec(self, policy_id): - data = { - "pfs": "group2", - "name": 'thisisnew' - } - ff = self.conn.network.update_ipsec_policy(policy_id, **data) - print ff - - -class IkePolcy(__BaseVpnService): - def create_ike_service(self): - data = { - "phase1_negotiation_mode": "main", - "auth_algorithm": "sha1", - "encryption_algorithm": "aes-128", - "pfs": "group5", - "lifetime": { - "units": "seconds", - "value": 7200 - }, - "ike_version": "v1", - "name": "ikepolicy1tetetetette" - } - - ff = self.conn.network.create_ike_policy(**data) - return ff - - def get_ikes(self): - ff = self.conn.network.get_ike_policy() - return ff - - def get_ike_from_id(self, ikepolicy_id): - ff = self.conn.network.find_ike_policy(ikepolicy_id) - print ff - - def delete_ike(self, policy_id): - ff = self.conn.network.delete_ike_policy(policy_id) - print ff - - def modify_ike(self, policy_id): - data = { - "description": 'thisisnew' - } - ff = self.conn.network.update_ike_policy(policy_id, **data) - print ff - - -class EndPointGroup(__BaseVpnService): - def create_endpoint_group(self): - data = { - "endpoints": ["100.2.0.0/24", "100.3.0.0/24"], - "type": "cidr", - "name": "peers" - } - - ff = self.conn.network.create_endpoint_group(**data) - print ff - - def for_test(self): - data1 = { - "endpoints": ["100.2.0.0/24", "100.3.0.0/24"], - "type": "cidr", - "name": "peers" - } - - data2 = { - "endpoints": ["10.2.0.0/24", "10.3.0.0/24"], - "type": "cidr", - "name": "peers" - } - - ff = [] - ff1 = self.conn.network.create_endpoint_group(**data1) - ff2 = self.conn.network.create_endpoint_group(**data2) - ff.append(ff1) - ff.append(ff2) - return ff - - def get_endpoint_group(self): - ff = self.conn.network.get_endpoint_group() - return ff - - def get_endpoint_group_from_id(self, endpoint_group): - ff = self.conn.network.find_endpoint_group(endpoint_group) - print ff - - def delete_endpoint_group(self, endpoint_group): - ff = self.conn.network.delete_endpoint_group(endpoint_group) - print ff - - def modify_endpoint_group(self, endpoint_group): - data = { - "description": 'thisisnew' - } - ff = self.conn.network.update_endpoint_group(endpoint_group, **data) - print ff - - -class VPNConnetion(__BaseVpnService): - def create_vpn_connection(self): - data = { - "psk": "secret", - "initiator": "bi-directional", - "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", - "admin_state_up": True, - "mtu": "1500", - "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", - "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", - "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", - "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", - "peer_address": "172.24.4.233", - "peer_id": "172.24.4.233", - "name": "vpnconnection1" - } - - ff = self.conn.network.create_vpn_connection(**data) - print ff - - def for_test(self, ipsecpolicy_id, ikepolicy_id, local_ep_group_id, peer_ep_group_id, vpnservice_id): - data = { - "psk": "secret", - "initiator": "bi-directional", - "ipsecpolicy_id": "e6e23d0c-9519-4d52-8ea4-5b1f96d857b1", - "admin_state_up": True, - "mtu": "1500", - "peer_ep_group_id": "9ad5a7e0-6dac-41b4-b20d-a7b8645fddf1", - "ikepolicy_id": "9b00d6b0-6c93-4ca5-9747-b8ade7bb514f", - "vpnservice_id": "5c561d9d-eaea-45f6-ae3e-08d1a7080828", - "local_ep_group_id": "3e1815dd-e212-43d0-8f13-b494fa553e68", - "peer_address": "172.24.4.233", - "peer_id": "172.24.4.233", - "name": "vpnconnection1" - } - - data['ipsecpolicy_id'] = ipsecpolicy_id - data['ikepolicy_id'] = ikepolicy_id - data['local_ep_group_id'] = local_ep_group_id - data['peer_ep_group_id'] = peer_ep_group_id - data['vpnservice_id'] = vpnservice_id - - ff = self.conn.network.create_vpn_connection(**data) - return ff - - def get_vpn_connection(self): - ff = self.conn.network.get_vpn_connection() - return ff - - def get_vpn_connection_from_id(self, vpn_connection): - ff = self.conn.network.find_vpn_connection(vpn_connection) - print ff - - def delete_vpn_connection(self, vpn_connection): - ff = self.conn.network.delete_vpn_connection(vpn_connection) - print ff - - def modify_vpn_connection(self, vpn_connection): - data = { - "description": 'thisisnew' - } - ff = self.conn.network.update_vpn_connection(vpn_connection, **data) - print ff - - -def ops_vpn_service(): - vpn_gateway = VPNService() - vpn_gateway.for_test() - - # ff = vpn_gateway.get_vpn_services() - # for i in ff: - # print i - # vpn_gateway.detele_vpn_service(vpn_id=i.id) - - -def ops_ip_sec_policy(): - ip_sec_policy = IPSecPolicy(debug=False) - # create_ipsec_service() - ff = ip_sec_policy.get_ipsecs() - for i in ff: - print i - # ip_sec_policy.get_ipsec_from_id(ipsecpolicy_id=i.id) - # ip_sec_policy.get_ipsec_from_id(ipsecpolicy_id='6aae8319-2f6c-46af-9f3a-3f1d8b8a38d2') - # # modify_ipsec(policy_id='6aae8319-2f6c-46af-9f3a-3f1d8b8a38d2') - ip_sec_policy.delete_ipsec(policy_id=i.id) - # ip_sec_policy.get_ipsec_from_id(ipsecpolicy_id='6aae8319-2f6c-46af-9f3a-3f1d8b8a38d2') - - -def ops_ike_policy(): - ike_policy = IkePolcy(debug=False) - # ike_policy.create_ike_service() - ff = ike_policy.get_ikes() - for i in ff: - print i - # ike_policy.get_ike_from_id(ikepolicy_id='809bc07e-04d6-4c8f-b516-410c900b2845') - # ike_policy.modify_ike(policy_id='809bc07e-04d6-4c8f-b516-410c900b2845') - # ike_policy.get_ike_from_id(ikepolicy_id='809bc07e-04d6-4c8f-b516-410c900b2845') - ike_policy.delete_ike(policy_id=i.id) - # ike_policy.get_ike_from_id(ikepolicy_id='809bc07e-04d6-4c8f-b516-410c900b2845') - - -def ops_endpoint_group(): - endpoint_group = EndPointGroup(debug=False) - # endpoint_group.create_endpoint_group() - ff = endpoint_group.get_endpoint_group() - # endpoint_group.get_endpoint_group_from_id(endpoint_group='32ce9d07-7640-40a7-9ed5-9e7c1d13eede') - # endpoint_group.modify_endpoint_group(endpoint_group='32ce9d07-7640-40a7-9ed5-9e7c1d13eede') - # endpoint_group.get_endpoint_group_from_id(endpoint_group='32ce9d07-7640-40a7-9ed5-9e7c1d13eede') - for i in ff: - print i - endpoint_group.delete_endpoint_group(endpoint_group=i.id) - endpoint_group.get_endpoint_group() - - -def ops_vpn_connection(): - vpn_connection = VPNConnetion() - ff = vpn_connection.get_vpn_connection() - for i in ff: - print i - vpn_connection.delete_vpn_connection(vpn_connection=i.id) - # vpn_connection.create_vpn_connection() - # vpn_connection.get_vpn_connection_from_id(vpn_connection='e191b292-9867-48e8-9e12-ae9ffc47cc2a') - # vpn_connection.modify_vpn_connection(vpn_connection='e191b292-9867-48e8-9e12-ae9ffc47cc2a') - # vpn_connection.delete_vpn_connection(vpn_connection='e191b292-9867-48e8-9e12-ae9ffc47cc2a') - - -def ops_all(): - - - vpn_gateway = VPNService() - vpnservice_id = vpn_gateway.for_test() - vpn_gateway.for_test() - endpoint_group = EndPointGroup() - tem = endpoint_group.for_test() - local_ep_group_id = tem[0] - peer_ep_group_id = tem[1] - - ip_sec_policy = IPSecPolicy() - ipsecpolicy_id = ip_sec_policy.create_ipsec_service() - - ike_policy = IkePolcy() - ikepolicy_id = ike_policy.create_ike_service() - vpn_connection = VPNConnetion() - result = vpn_connection.for_test(ikepolicy_id=ikepolicy_id.id, ipsecpolicy_id=ipsecpolicy_id.id, - local_ep_group_id=local_ep_group_id.id, peer_ep_group_id=peer_ep_group_id.id, - vpnservice_id=vpnservice_id.id) - - print result - - -if __name__ == '__main__': - # ops_vpn_service() - # ops_endpoint_group() - # ops_ike_policy() - # ops_ip_sec_policy() - # ops_vpn_connection() - ops_all() diff --git a/examples/rds/__init__.py b/examples/rds/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/rds/rds.py b/examples/rds/rds.py deleted file mode 100644 index 2836760..0000000 --- a/examples/rds/rds.py +++ /dev/null @@ -1,127 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing rds - -""" - - -def datastore_versions(conn): - for v in conn.rds.datastore_versions('MySQL'): - print(v) - - -def list_rds_instances(conn): - for i in conn.rds.instances(): - print(i) - - -def list_rds_flavors(conn): - for f in conn.rds.flavors(dbId='87620726-6802-46c0-9028-a8785e1f1922', - region="eu-de"): - print(f) - - -def create_instance(conn): - instance_dict = { - "name": "trove-instance-rep2", - "datastore": { - "type": "MySQL", - "version": "5.6.30"}, - "flavorRef": "bf07a6d4-844a-4023-a776-fc5c5fb71fb4", - "volume": { - "type": "COMMON", - "size": 100 - }, - "region": "eu-de", - "availabilityZone": "eu-de-01", - "vpc": "490a4a08-ef4b-44c5-94be-3051ef9e4fce", - "nics": { - "subnetId": "0e2eda62-1d42-4d64-a9d1-4e9aa9cd994f" - }, - "securityGroup": { - "id": "2a1f7fc8-3307-42a7-aa6f-42c8b9b8f8c5" - }, - "backupStrategy": { - "startTime": "01:00:00", - "keepDays": 3 - }, - "dbRtPd": "Test@123" - } - - print(conn.rds.create_instance(**instance_dict)) - - -def get_instance(conn, i): - """i could be the instance id of an instance object""" - return conn.rds.get_instance(i) - - -def set_instance_params(conn, i): - """i could be the instance id of an instance object""" - params = { - "connect_timeout": 17, - "sync_binlog": 1 - } - print(conn.rds.set_instance_params(i, **params)) - - -def reset_instance_params(conn, i): - """i could be the instance id of an instance object""" - print(conn.rds.reset_instance_params(i)) - - -def list_instance_errorlog(conn, i): - """i could be the instance id of an instance object""" - for l in conn.rds.list_instance_errorlog(i, - startDate="2017-07-11+06:35", - endDate="2017-07-20+06:35"): - print(l) - - -def list_instance_slowlog(conn, i): - """i could be the instance id of an instance object""" - for l in conn.rds.list_instance_slowlog(i, sftype='UPDATE'): - print(l) - - -def get_flavor(conn, f): - print(conn.rds.get_flavor(f)) - - -def backups(conn): - for b in conn.rds.backups(): - print(b) - - -def create_backup_policy(conn, i): - print(conn.rds.create_backup_policy(i, 7, "22:00:00")) - - -def get_backup_policy(conn, i): - print(conn.rds.get_backup_policy(i)) - - -def create_backup(conn, i): - print(conn.rds.create_backup(i, "myname", "my desc")) - - -def get_version(conn, version): - print(conn.rds.get_rds_version(version)) - - -def list_version(conn): - for v in conn.rds.list_rds_version(): - print(v) diff --git a/examples/rds_os/__init__.py b/examples/rds_os/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/rds_os/rds_os.py b/examples/rds_os/rds_os.py deleted file mode 100644 index 3149a82..0000000 --- a/examples/rds_os/rds_os.py +++ /dev/null @@ -1,148 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing rds - -""" - - -def list_rds_instances(conn): - for i in conn.rds.os_instances(): - print(i) - - -def create_instance(conn): - instance_dict = { - "name": "trove-instance-rep2", - "datastore": { - "type": "MySQL", - "version": "5.6.30"}, - "flavorRef": "bf07a6d4-844a-4023-a776-fc5c5fb71fb4", - "volume": { - "type": "COMMON", - "size": 100 - }, - "region": "eu-de", - "availabilityZone": "eu-de-01", - "vpc": "490a4a08-ef4b-44c5-94be-3051ef9e4fce", - "nics": { - "subnetId": "0e2eda62-1d42-4d64-a9d1-4e9aa9cd994f" - }, - "securityGroup": { - "id": "2a1f7fc8-3307-42a7-aa6f-42c8b9b8f8c5" - }, - "backupStrategy": { - "startTime": "01:00:00", - "keepDays": 3 - }, - "dbRtPd": "Test@123" - } - - print(conn.rds.os_create_instance(**instance_dict)) - - -def get_instance(conn, i): - """i could be the instance id of an instance object""" - return conn.rds.os_get_instance(i) - - -def get_flavor(conn, f): - print(conn.rds.os_get_flavor(f)) - - -def list_rds_flavors(conn): - for f in conn.rds.os_flavors(dbId='87620726-6802-46c0-9028-a8785e1f1922', - region="eu-de"): - print(f) - - -def get_parameters(conn, version_id): - """list parameters of a datastore""" - for p in conn.rds.os_parameters(version_id): - print(p) - - -def get_parameter(conn, version_id, name): - """Get parameter of a datastore by name""" - print(conn.rds.os_get_parameter(version_id, name)) - - -def get_instance_default_configuration(conn, instance): - print(conn.rds.os_get_instance_default_configuration(instance)) - - -def list_configuration_group(conn): - for g in conn.rds.os_list_configuration_group(): - print(g) - - -def create_configuration_group(conn): - group_dict = { - "configuration": { - "name": "configuration_test", - "description": "configuration_test", - "values": { - "max_connections": "10", - "autocommit": "OFF" - }, - "datastore": { - "type": "mysql", - "version": "5.6" - } - } - } - - print(conn.rds.os_create_configuration_group(**group_dict)) - - -def get_configuration_group(conn, cg): - print(conn.rds.os_get_configuration_group(cg)) - - -def delete_configuration_group(conn, group): - conn.rds.os_delete_configuration_group(group) - - -def update_configuration_group(conn, cg): - - update_dict = { - "configuration": { - "name": "configuration_test", - "description": "configuration_test", - "values": { - "max_connections": "10", - "autocommit": "OFF" - } - } - } - - print(conn.rds.os_update_configuration_group(cg, **update_dict)) - - -def patch_configuration_group(conn, cg): - patch_dict = { - "configuration": { - "values": { - "max_connections": "10", - "autocommit": "OFF" - } - } - } - - print(conn.rds.os_patch_configuration_group(cg, **patch_dict)) - - -def get_configuration_group_associated_instances(conn, cg): - print(conn.rds.os_get_configuration_group_associated_instances(cg)) diff --git a/examples/smn/__init__.py b/examples/smn/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/smn/smn.py b/examples/smn/smn.py deleted file mode 100644 index dca6b6e..0000000 --- a/examples/smn/smn.py +++ /dev/null @@ -1,271 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -""" -Managing smn - -""" - - -def operate_topic(conn): - topic_dict = { - 'name': 'labj', - 'display_name': 'djb', - } - - tp = conn.smn.create_topic(**topic_dict) - print(tp) - - update_dict = { - 'display_name': 'djbsbxxxxxxxx', - } - - newtp = conn.smn.update_topic(tp, **update_dict) - print(newtp) - - print("get topic from topic urn") - gettp = conn.smn.get_topic(newtp.topic_urn) - print(gettp) - - print("publish topic") - msg_dict = { - 'message': "hello world!" - } - print("publish message") - print(conn.smn.publish_topic(tp, **msg_dict)) - - conn.smn.delete_topic(tp) - - print("get all topics with query") - - for t in conn.smn.topics(offset=0, limit=10): - print(t) - - -def send_sms(conn): - msg_dict = { - 'endpoint': '+12345678', - 'message': 'FYL', - 'sign_id': '94d3b63a5dfb475994d3ac34664e2346' - } - print(conn.smn.direct_publish(**msg_dict)) - - -def operate_topic_attr(conn): - - topic_dict = { - 'name': 'labj', - 'display_name': 'djb', - } - - print("create a topic") - tp = conn.smn.create_topic(**topic_dict) - - print("get topic attr of the topic") - tpr = conn.smn.get_topic_attr(tp) - - print("topic attr is:") - print(tpr) - - print("update a topic attr by attr name") - attr_val_str = \ - "{\"Version\": \"2016-09-07\", \"Id\": \"__default_policy_ID\", " \ - "\"Statement\": [{\"Sid\": \"__user_pub_0\",\"Effect\": \"Allow\"" \ - ",\"Principal\": {\"CSP\": [\"urn:csp:iam::93dc1b4697ac493d9b7d0895" \ - "69f86b32:root\"]},\"Action\": [\"SMN:Publish\",\"SMN:QueryTopicDeta" \ - "il\"],\"Resource\": \"urn:smn:regionId:8bad8a40e0f7462f8c1676e3f93a" \ - "8183:zhaoli\"},{\"Sid\": \"__service_pub_0\", \"Effect\": \"Al" \ - "low\",\"Principal\": {\"Service\": [\"obs\"]},\"Action\": [\"SMN:Pu" \ - "blish\",\"SMN:QueryTopicDetail\"],\"Resource\": \"urn:smn:regionId:" \ - "8bad8a40e0f7462f8c1676e3f93a8183:zhaoli\"}]}" - - print(conn.smn.update_topic_attr(tpr, 'access_policy', attr_val_str)) - - print("delete topic access_policy attribute") - conn.smn.delete_topic_attr(tpr, 'access_policy') - - print("delete all topic attrs of the topic") - conn.smn.delete_topic_attrs(tp) - print("delete the topic") - conn.smn.delete_topic(tp) - - -def subscriptions(conn): - print("list all subscriptions") - for s in conn.smn.subscriptions(offset=0, limit=2): - print(s) - - -def topic_subscriptions(conn): - topic_dict = { - 'name': 'labj', - 'display_name': 'djb', - } - - print("create a topic") - tp = conn.smn.create_topic(**topic_dict) - - print("list specific topic subscriptions") - for s in conn.smn.topic_subscriptions(tp.topic_urn, offset=0, limit=10): - print(s) - - -def subscript_topic(conn): - - topic_dict = { - 'name': 'labj', - 'display_name': 'djb', - } - - print("create a topic") - tp = conn.smn.create_topic(**topic_dict) - - sub_dict = { - 'protocol': 'email', - 'endpoint': 'xxx@xxx.com', - 'remark': 'test', - } - - sub = conn.smn.subscript_topic(tp, **sub_dict) - print(sub) - print("confirm subscription") - print(conn.smn.confirm_subcription(sub, - "762bdb3251034f268af0e395c53ea09bc0ce" - "331b2593449a9f5097a679092746a2d52a9f" - "5c3b47f48c3fafb177a587961fb95fce9d80" - "44e28e77e903a887fffe")) - print("unsub") - print(conn.smn.unsubscript_topic(sub.subscription_urn)) - print("delete the topic") - conn.smn.delete_topic(tp) - - -def operate_template_message(conn): - m_dict = { - 'message_template_name': 'testfoobarxxx', - 'protocol': "email", - 'content': 'what the hell!' - } - update_dict = { - 'content': 'be civilization' - } - - print("list all message templates") - for m in conn.smn.message_templates(offset=0, limit=10): - print(m) - - newm = conn.smn.create_message_template(**m_dict) - print("created new template is:") - print(newm) - getm = conn.smn.get_message_template(newm.message_template_id) - print("new template detail is:") - print(getm) - - updatedm = conn.smn.update_message_template(getm, **update_dict) - print("update the template to:") - print(updatedm) - print("delete template") - conn.smn.delete_message_template(updatedm) - for m in conn.smn.message_templates(offset=0, limit=10): - print(m) - - -def publish_struct_message(conn, topic): - # topic is the topic object or topoic urn - message_dict = { - "subject": "test message v2", - "message_structure": - "{\"default\":\"test v2 default\", \"email\":\"abc\"}" - } - - print(conn.smn.publish_topic(topic, **message_dict)) - - -def publish_template_message(conn, topic): - # topic is the topic object or topoic urn - message_dict = { - "message_template_name": "confirm_message", - "tags": { - "topic_urn": "topic_urn3331", - "topic_id": "topic_id3332" - } - } - - print(conn.smn.publish_topic(topic, **message_dict)) - - -def subscript_topic_sms(conn): - - topic_dict = { - 'name': 'labj', - 'display_name': 'djb1', - } - - print("create a topic") - tp = conn.smn.create_topic(**topic_dict) - - sub_dict = { - 'protocol': 'sms', - 'endpoint': '+123456', - 'remark': 'test', - } - - sub = conn.smn.subscript_topic(tp, **sub_dict) - print(sub) - print("delete the topic") - conn.smn.delete_topic(tp) - - -def subscript_topic_http(conn): - - topic_dict = { - 'name': 'labj', - 'display_name': 'djb2', - } - - print("create a topic") - tp = conn.smn.create_topic(**topic_dict) - - sub_dict = { - 'protocol': 'http', - 'endpoint': 'http://foo.bar.com', - 'remark': 'test', - } - - sub = conn.smn.subscript_topic(tp, **sub_dict) - print(sub) - print("delete the topic") - conn.smn.delete_topic(tp) - - -def subscript_topic_https(conn): - - topic_dict = { - 'name': 'labj', - 'display_name': 'djb2', - } - - print("create a topic") - tp = conn.smn.create_topic(**topic_dict) - - sub_dict = { - 'protocol': 'https', - 'endpoint': 'https://foo.bar.com', - 'remark': 'test', - } - - sub = conn.smn.subscript_topic(tp, **sub_dict) - print(sub) - print("delete the topic") - conn.smn.delete_topic(tp) diff --git a/examples/vpc/__init__.py b/examples/vpc/__init__.py deleted file mode 100644 index 7608083..0000000 --- a/examples/vpc/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def main(): - pass - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/examples/vpc/eip.py b/examples/vpc/eip.py deleted file mode 100644 index 8d824ca..0000000 --- a/examples/vpc/eip.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding:utf-8 -*- -# Copyright 2018 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. - -def apply_eip(conn): - data = { - "publicip": { - "type": "5_bgp" - }, - "bandwidth": { - "name": "bw_kakak", - "size": 1, - "share_type": "WHOLE", - "charge_mode": "bandwidth" - }, - "extendParam": { - "charge_mode": "prePaid", - "period_type": "month", - "period_num": 1, - "is_auto_renew": "false", - "is_auto_pay": "true" - } - } - ff = conn.vpc.create_publicip_ext(**data) - print ff - - -def modify_bandwidth(conn): - bandwidth_id = '52723dee-182f-4688-a97b-2a7a9a1fe88f' - data = { - "bandwidth": - { - "name": "bandwidthaaaakkkk3", - "size": 100 - }, - "extendParam": - { - "is_auto_pay": "false" - } - } - - ff = conn.vpc.update_bandwidth_ext(bandwidth_id=bandwidth_id, **data) - print ff diff --git a/openstack/cdn/cdn_resource.py b/openstack/cdn/cdn_resource.py index 921dda9..09bcaf4 100644 --- a/openstack/cdn/cdn_resource.py +++ b/openstack/cdn/cdn_resource.py @@ -1,12 +1,12 @@ # -*- coding:utf-8 -*- # Copyright 2018 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 @@ -54,7 +54,8 @@ def __init__(self, *names, **mappings): """ self._mapping = {'start_time': 'start_time', 'end_time': 'end_time', - 'domain_name': 'domain_name'} + 'domain_name': 'domain_name', + 'enterprise_project_id': 'enterprise_project_id'} self._mapping.update(dict({name: name for name in names}, **mappings)) diff --git a/openstack/cdn/v1/_proxy.py b/openstack/cdn/v1/_proxy.py index 987ae2a..8c5c12d 100644 --- a/openstack/cdn/v1/_proxy.py +++ b/openstack/cdn/v1/_proxy.py @@ -94,6 +94,19 @@ def get_domain(self, domain): """ return self._get(_domain.Domain, domain) + def get_domain_detail_by_enterprise_project_id(self, domain, enterprise_project_id='ALL'): + """Get a single acceleration domain name + + :param domain: The value can be the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.get_detail_by_enterprise_project_id(self._session, enterprise_project_id) + def delete_domain(self, domain, ignore_missing=True): """Delete an acceleration domain name @@ -110,6 +123,22 @@ def delete_domain(self, domain, ignore_missing=True): self._delete(_domain.Domain, domain, ignore_missing=ignore_missing, has_body=True) + def delete_domain_by_enterprise_project_id(self, domain, enterprise_project_id): + """Delete an acceleration domain name + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be + raised when the resource does not exist. + When set to ``True``, no exception will be set when + attempting to delete a nonexistent resource. + + :returns: ``None`` + """ + res = self._get_resource(_domain.Domain, domain) + return res.delete_by_enterprise_project_id(self._session, enterprise_project_id) + def set_domain_sources(self, domain, *sources): """Update information about the origin server @@ -133,6 +162,29 @@ def set_domain_sources(self, domain, *sources): res = self._get_resource(_domain.Domain, domain) return res.set_sources(self._session, *sources) + def set_domain_sources_by_enterprise_project_id(self, domain, enterprise_project_id, **attrs): + """Update information about the origin server + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + :param \*sources: A list of dict which specifies the domain name + or the IP address of the origin server. + Available keys for each source dict include: + + * ip_or_domain: The IP address or domain name of the origin server + Mandatory. + * origin_type: The origin type. The value can be 'ipaddr' or + 'domain'. Mandatory. + * active_standby: Whether the source is active. 1: active, + 0: standby. Mandatory. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.set_sources_by_enterprise_project_id(self._session, enterprise_project_id, **attrs) + def enable_domain(self, domain): """Enables an acceleration domain name @@ -146,6 +198,19 @@ def enable_domain(self, domain): res = self._get_resource(_domain.Domain, domain) return res.enable(self._session) + def enable_domain_by_enterprise_project_id(self, domain, enterprise_project_id): + """Enables an acceleration domain name + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.enable_by_enterprise_project_id(self._session, enterprise_project_id) + def disable_domain(self, domain): """Disable an acceleration domain name @@ -159,6 +224,19 @@ def disable_domain(self, domain): res = self._get_resource(_domain.Domain, domain) return res.disable(self._session) + def disable_domain_by_enterprise_project_id(self, domain, enterprise_project_id): + """Disable an acceleration domain name + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.disable_by_enterprise_project_id(self._session, enterprise_project_id) + def set_domain_origin_host(self, domain, **attrs): """Modifies the configuration of the retrieval host @@ -186,6 +264,33 @@ def set_domain_origin_host(self, domain, **attrs): res = self._get_resource(_domain.Domain, domain) return res.set_origin_host(self._session, **attrs) + def set_domain_origin_host_by_enterprise_project_id(self, domain, enterprise_project_id, **attrs): + """Modifies the configuration of the retrieval host + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + :param dict attrs: Keyword arguments which contains origin host + configuration for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * origin_host_type: The type of the retrieval host. + 'accelerate': the acceleration domain name is used as + the retrieval host address; + 'customize': A custom domain name is used as the retrieval + host address; + 'source': The origin domain name is used as the retrieval + host address. + Mandatory. + * customize_domain: The custom domain name of the retrieval host. + Mandatory when the value of origin_host_type is 'customize'. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.set_origin_host_by_enterprise_project_id(self._session, enterprise_project_id, **attrs) + def get_domain_origin_host(self, domain): """Queries the configuration of the retrieval host @@ -198,6 +303,18 @@ def get_domain_origin_host(self, domain): res = self._get_resource(_domain.Domain, domain) return res.get_origin_host(self._session) + def get_domain_origin_host_by_enterprise_project_id(self, domain, enterprise_project_id): + """Queries the configuration of the retrieval host + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: The retrieval host configuration of this domain name + :rtype: dict + """ + res = self._get_resource(_domain.Domain, domain) + return res.get_origin_host_by_enterprise_project_id(self._session, enterprise_project_id) + def set_domain_referer(self, domain, **attrs): """Configures a referrer list @@ -228,6 +345,36 @@ def set_domain_referer(self, domain, **attrs): res = self._get_resource(_domain.Domain, domain) return res.set_referer(self._session, **attrs) + def set_domain_referer_by_enterprise_project_id(self, domain, enterprise_project_id, **attrs): + """Configures a referrer list + + Self-define referrer whitelists and blacklists identify and filter + user identities, controlling access. + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + :param dict attrs: Keyword arguments which contains origin host + configuration for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * referer_type: The referer type. The values include: + 0: referer filter not set; 1: blacklist; 2: whitelist. + * referer_list: A list of domain names that are separated from + each other by semicolon (;). + * include_empty: Whether blank referrers are included. + True or False. + A referrer blacklist including blank referrers indicates that + requests without any referrers are not allowed to access. + A referrer whitelist including blank referrers indicates that + requests without any referrers are allowed to access. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.set_referer_by_enterprise_project_id(self._session, enterprise_project_id, **attrs) + def get_domain_referer(self, domain): """Queries the referer list of the domain name @@ -240,6 +387,18 @@ def get_domain_referer(self, domain): res = self._get_resource(_domain.Domain, domain) return res.get_referer(self._session) + def get_domain_referer_by_enterprise_project_id(self, domain, enterprise_project_id): + """Queries the referer list of the domain name + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: The referer list of this domain name + :rtype: dict + """ + res = self._get_resource(_domain.Domain, domain) + return res.get_referer_by_enterprise_project_id(self._session, enterprise_project_id) + def set_domain_cache_rules(self, domain, **attrs): """Configures a cache policy for resources on CDN nodes @@ -282,6 +441,48 @@ def set_domain_cache_rules(self, domain, **attrs): res = self._get_resource(_domain.Domain, domain) return res.set_cache_rules(self._session, **attrs) + def set_domain_cache_rules_by_enterprise_project_id(self, domain, enterprise_project_id, **attrs): + """Configures a cache policy for resources on CDN nodes + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + :param dict attrs: Keyword arguments which contains cache policies + for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * ignore_url_parameter: Whether to ignore URL parameters. True or + False. Optional. + * rules: A list of the cache rules, which overwrite the previous + rule configurations. Blank rules are reset to default rules. + Each cache rule contains 'rule_type','content','ttl','ttl_type' and + 'priority' properties. + * rule_type: 0-all types of files are matched, + 1-files are matched based on their suffixes, + 2-files are matched based on directories. + Mandatory. + * content: The content that matches rule_type. + When rule_type is 0, it should be None, + When rule_type is 1, it is suffixes that indicate + different types of files, for example, .jps;.js, + separated by semicolons (;). + When rule_type is 2, be directories, for example, + /www/html;/www/anc, separated by semicolons (;). + * ttl: The cache time. The maximum value of ttl is 365 days. + Mandatory. + * ttl_type: The unit of cache time. + 1-seconds; 2-minutes; 3-hours; 4-days. + Mandatory. + * priority: The priority weight of this rule. A greater value + indicates a higher priority. The value ranges + from 1 to 100. Default to 1. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.set_cache_rules_by_enterprise_project_id(self._session, enterprise_project_id, **attrs) + def get_domain_cache_rules(self, domain): """Queries the cache rules of the domain name @@ -294,6 +495,18 @@ def get_domain_cache_rules(self, domain): res = self._get_resource(_domain.Domain, domain) return res.get_cache_rules(self._session) + def get_domain_cache_rules_by_enterprise_project_id(self, domain, enterprise_project_id): + """Queries the cache rules of the domain name + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: The cache rules of this domain name + :rtype: dict + """ + res = self._get_resource(_domain.Domain, domain) + return res.get_cache_rules_by_enterprise_project_id(self._session, enterprise_project_id) + def set_domain_https(self, domain, **attrs): """Configures the HTTPS of the acceleration domain name @@ -327,6 +540,39 @@ def set_domain_https(self, domain, **attrs): res = self._get_resource(_domain.Domain, domain) return res.set_https(self._session, **attrs) + def set_domain_https_by_enterprise_project_id(self, domain, enterprise_project_id, **attrs): + """Configures the HTTPS of the acceleration domain name + + This method sets HTTPS by configuring the certificate of a domain name, + and deploy the HTTPS configuration on all CDN nodes to implement + secure acceleration. + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + :param dict attrs: Keyword arguments which contains cache policies + for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * cert_name: The certificate name. Mandatory. + * https_status: The mode of HTTPS certificate is enabled. + 0-disabled, 1-enabled in serving and retrieving sources, + 2-only enabled in serving. + Mandatory. + * certificate: The certificate content used by HTTPS, PEM format. + Optional when https_status is 0. + * private_key: The private key content used by HTTPS, PEM format. + Optional when https_status is 0. + * force_redirect_https: Whether to force the client request to be + redirected. 1: yes. 0: no. Optional. + * http2: Whether to use HTTP 2.0. 1: yes. 0: no. Optional. + + :returns: One :class:`~openstack.cdn.v1.domain.Domain` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + res = self._get_resource(_domain.Domain, domain) + return res.set_https_by_enterprise_project_id(self._session, enterprise_project_id, **attrs) + def get_domain_https(self, domain): """Obtains the certificate for the acceleration domain name @@ -339,6 +585,18 @@ def get_domain_https(self, domain): res = self._get_resource(_domain.Domain, domain) return res.get_https(self._session) + def get_domain_https_by_enterprise_project_id(self, domain, enterprise_project_id): + """Obtains the certificate for the acceleration domain name + + :param domain: The value can be either the ID of a domain name or a + :class:`~openstack.cdn.v1.domain.Domain` instance. + + :returns: The HTTPS certificate of this domain name + :rtype: dict + """ + res = self._get_resource(_domain.Domain, domain) + return res.get_https_by_enterprise_project_id(self._session, enterprise_project_id) + def tasks(self, page_size=100, page_number=1, **query): """List the cache refreshing or preheating tasks matching the query @@ -442,6 +700,29 @@ def logs(self, domain_name, query_date, paginated=True) return self._list(_log.Log, **query) + def logs_by_enterprise_project_id(self, domain_name, query_date, enterprise_project_id, + page_size=100, page_number=1, **query): + """List the logs matching the query + + :param str domain_name: The name of the acceleration domain name. + :param int query_date: The date that you want to query, which is + expressed as milliseconds since 1970-01-01 00:00:00 UTC. + :param int page_size: The number of logs on each page. + The value ranges from 10 to 1000. Default to 100. + :param int page_number: The page number that is queried. The value + ranges from 1 to 65535. Default to 1. + :param kwargs \*\*query: Optional query parameters to be sent to limit + the resources being returned. + + :returns: A generator of Task objects + :rtype: :class:`~openstack.cdn.v1.log.Log` + """ + query = query or {} + query.update(domain_name=domain_name, query_date=query_date, + page_size=page_size, page_number=page_number, + enterprise_project_id=enterprise_project_id, paginated=True) + return self._list(_log.Log, **query) + def query_network_traffic(self, **query): """Queries the total network traffic diff --git a/openstack/cdn/v1/domain.py b/openstack/cdn/v1/domain.py index 413e1a8..e895ee3 100644 --- a/openstack/cdn/v1/domain.py +++ b/openstack/cdn/v1/domain.py @@ -32,7 +32,8 @@ class Domain(cdn_resource.Resource): _query_mapping = cdn_resource.QueryParameters('domain_name', 'business_type', - 'domain_status') + 'domain_status', + 'enterprise_project_id') #: The acceleration domain name. domain_name = resource.Body('domain_name') @@ -41,6 +42,7 @@ class Domain(cdn_resource.Resource): #: 'download' (the acceleration for downloads); #: 'video' (the acceleration for media streaming). business_type = resource.Body('business_type') + enterprise_project_id = resource.Body('enterprise_project_id') #: The domain ID of the domain name's owner. user_domain_id = resource.Body('user_domain_id') #: The status of the acceleration domain name. Values include @@ -351,3 +353,319 @@ def get_https(self, session): resp_json = resp.json() self.check_error(resp_json) return resp_json['https'] + + + def get_detail_by_enterprise_project_id(self, session, enterprise_project_id): + """Get a remote resource based on this instance. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param boolean requires_id: A boolean indicating whether resource ID + should be part of the requested URI. + + :returns: This :class:`Domain` instance. + :rtype: :class:`~openstack.cdn.v1.domain.Domain` + """ + + request = self._prepare_request(requires_id=enterprise_project_id) + # NOTE(samsong8610): The URL for GET is not standard + request.uri = utils.urljoin(request.uri, 'detail') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + response = session.get(request.uri, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + + self._translate_response(response) + return self + + def set_sources_by_enterprise_project_id(self, session, enterprise_project_id, **attrs): + """Update information about the origin server + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param \*sources: A list of dict which specifies the domain name + or the IP address of the origin server. + Available keys for each source dict include: + + * ip_or_domain: The IP address or domain name of the origin server + Mandatory. + * origin_type: The origin type. The value can be 'ipaddr' or + 'domain'. Mandatory. + * active_standby: Whether the source is active. 1: active, + 0: standby. Mandatory. + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + # body = {'origin': {'sources': list(sources)}} + # print(attrs) + body = {'origin': attrs} + url = utils.urljoin(self.base_path, self.id, 'origin') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=body, params=params) + resp_json = resp.json() + self.check_error(resp_json) + self.sources = resp_json['origin']['sources'] + return self + + def delete_by_enterprise_project_id(self, session, enterprise_project_id): + """delete an acceleration domain name + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + url = utils.urljoin(self.base_path, self.id) + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.delete(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + self._translate_response(resp) + return self + + def enable_by_enterprise_project_id(self, session, enterprise_project_id): + """Enables an acceleration domain name + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + + url = utils.urljoin(self.base_path, self.id, 'enable') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + self._translate_response(resp) + return self + + def disable_by_enterprise_project_id(self, session, enterprise_project_id): + """Disable an acceleration domain name + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + # print(enterprise_project_id) + url = utils.urljoin(self.base_path, self.id, 'disable') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + self._translate_response(resp) + return self + + def set_origin_host_by_enterprise_project_id(self, session, enterprise_project_id, **attrs): + """Modifies the configuration of the retrieval host + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param dict attrs: Keyword arguments which contains origin host + configuration for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * origin_host_type: The type of the retrieval host. + 'accelerate': the acceleration domain name is used as + the retrieval host address; + 'customize': A custom domain name is used as the retrieval + host address; + 'source': The origin domain name is used as the retrieval + host address. + * customize_domain: The custom domain name of the retrieval host. + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + body = {'origin_host': attrs} + url = utils.urljoin(self.base_path, self.id, 'originhost') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=body, params=params) + resp_json = resp.json() + self.check_error(resp_json) + self.domain_origin_host = resp_json['origin_host'] + return self + + def get_origin_host_by_enterprise_project_id(self, session, enterprise_project_id): + """Queries the configuration of the retrieval host + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: The retrieval host configuration of this domain name + :rtype: dict + """ + # print(enterprise_project_id) + url = utils.urljoin(self.base_path, self.id, 'originhost') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.get(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return resp_json['origin_host'] + + def set_referer_by_enterprise_project_id(self, session, enterprise_project_id, **attrs): + """Configures a referrer list + + Self-define referrer whitelists and blacklists identify and filter + user identities, controlling access. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param dict attrs: Keyword arguments which contains origin host + configuration for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * referer_type: The referer type. The values include: + 0: referer filter not set; 1: blacklist; 2: whitelist. + * referer_list: A list of domain names that are separated from + each other by semicolon (;). + * include_empty: Whether blank referrers are included. + A referrer blacklist including blank referrers indicates that + requests without any referrers are not allowed to access. + A referrer whitelist including blank referrers indicates that + requests without any referrers are allowed to access. + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + body = {'referer': attrs} + url = utils.urljoin(self.base_path, self.id, 'referer') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=body, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return self + + def get_referer_by_enterprise_project_id(self, session, enterprise_project_id): + """Queries the referer list of the domain name + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: The referer list of this domain name + :rtype: dict + """ + url = utils.urljoin(self.base_path, self.id, 'referer') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.get(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return resp_json['referer'] + + def set_cache_rules_by_enterprise_project_id(self, session, enterprise_project_id, **attrs): + """Configures a cache policy for resources on CDN nodes + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param dict attrs: Keyword arguments which contains cache policies + for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * ignore_url_parameter: Whether to ignore URL parameters + * rules: A list of the cache rules, which overwrite the previous + rule configurations. Blank rules are reset to default rules. + Each cache rule contains 'rule_type','content','ttl','ttl_type' and + 'priority' properties. + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + body = {'cache_config': attrs} + url = utils.urljoin(self.base_path, self.id, 'cache') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=body, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return self + + def get_cache_rules_by_enterprise_project_id(self, session, enterprise_project_id): + """Queries the cache rules of the domain name + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: The cache rules of this domain name + :rtype: dict + """ + url = utils.urljoin(self.base_path, self.id, 'cache') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.get(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return resp_json['cache_config'] + + def set_https_by_enterprise_project_id(self, session, enterprise_project_id, **attrs): + """Configures the HTTPS of the acceleration domain name + + This method sets HTTPS by configuring the certificate of a domain name, + and deploy the HTTPS configuration on all CDN nodes to implement + secure acceleration. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param dict attrs: Keyword arguments which contains cache policies + for :class:`~openstack.cdn.v1.domain.Domain`. + Available attributes include: + + * cert_name: The certificate name. + * https_status: The HTTPS certificate is enabled. + * certificate: The certificate used by HTTPS. + * private_key: The private key used by HTTPS. + * force_redirect_https: Whether to force the client request to be + redirected. + * http2: Whether to use HTTP 2.0. + + :returns: This :class:`Domain` instance. + :rtype: :class:`Domain` + """ + body = {'https': attrs} + url = utils.urljoin(self.base_path, self.id, 'https-info') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.put(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=body, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return self + + def get_https_by_enterprise_project_id(self, session, enterprise_project_id): + """Obtains the certificate for the acceleration domain name + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: The HTTPS certificate of this domain name + :rtype: dict + """ + url = utils.urljoin(self.base_path, self.id, 'https-info') + params = {'enterprise_project_id': enterprise_project_id} + endpoint_override = self.service.get_endpoint_override() + resp = session.get(url, endpoint_filter=self.service, + endpoint_override=endpoint_override, params=params) + resp_json = resp.json() + self.check_error(resp_json) + return resp_json['https'] diff --git a/openstack/cdn/v1/log.py b/openstack/cdn/v1/log.py index 084a193..da033ba 100644 --- a/openstack/cdn/v1/log.py +++ b/openstack/cdn/v1/log.py @@ -28,7 +28,7 @@ class Log(cdn_resource.Resource): allow_delete = False allow_list = True - _query_mapping = cdn_resource.QueryParameters('query_date', 'domain_name') + _query_mapping = cdn_resource.QueryParameters('query_date', 'domain_name', 'enterprise_project_id') #: The queried domain name. domain_name = resource.Body('domain_name') diff --git a/openstack/cdn/v1/task.py b/openstack/cdn/v1/task.py index 4ec79e3..f49eb28 100644 --- a/openstack/cdn/v1/task.py +++ b/openstack/cdn/v1/task.py @@ -134,6 +134,36 @@ class RefreshTask(Task): # NOTE(samsong8610): This attribute is *ONLY* used in requests. type = resource.Body('type') + def create(self, session, prepend_key=True): + """Create a remote resource based on this instance. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param prepend_key: A boolean indicating whether the resource_key + should be prepended in a resource creation + request. Default to True. + + :return: This :class:`Resource` instance. + :raises: :exc:`~openstack.exceptions.MethodNotSupported` if + :data:`Resource.allow_create` is not set to ``True``. + """ + + endpoint_override = self.service.get_endpoint_override() + if self.put_create: + request = self._prepare_request(requires_id=True, + prepend_key=prepend_key) + response = session.put(request.uri, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=request.body, headers=request.headers) + else: + request = self._prepare_request(requires_id=False, + prepend_key=prepend_key) + response = session.post(request.uri, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=request.body, headers=request.headers, params={"enterprise_project_id": 'ALL'}) + + self._translate_response(response) + return self class PreheatTask(Task): base_path = '/cdn/preheatingtasks' @@ -144,3 +174,34 @@ class PreheatTask(Task): allow_get = False allow_delete = False allow_list = False + + def create(self, session, prepend_key=True): + """Create a remote resource based on this instance. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param prepend_key: A boolean indicating whether the resource_key + should be prepended in a resource creation + request. Default to True. + + :return: This :class:`Resource` instance. + :raises: :exc:`~openstack.exceptions.MethodNotSupported` if + :data:`Resource.allow_create` is not set to ``True``. + """ + + endpoint_override = self.service.get_endpoint_override() + if self.put_create: + request = self._prepare_request(requires_id=True, + prepend_key=prepend_key) + response = session.put(request.uri, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=request.body, headers=request.headers) + else: + request = self._prepare_request(requires_id=False, + prepend_key=prepend_key) + response = session.post(request.uri, endpoint_filter=self.service, + endpoint_override=endpoint_override, + json=request.body, headers=request.headers, params={"enterprise_project_id": 'ALL'}) + + self._translate_response(response) + return self \ No newline at end of file diff --git a/openstack/ecs/v1/_proxy.py b/openstack/ecs/v1/_proxy.py index 1e0c2aa..edee16c 100644 --- a/openstack/ecs/v1/_proxy.py +++ b/openstack/ecs/v1/_proxy.py @@ -1,12 +1,12 @@ # -*- coding:utf-8 -*- # Copyright 2018 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 @@ -16,6 +16,8 @@ from openstack.ecs.v1 import server as _server from openstack.ecs.v1 import server_ext as _server_ext from openstack.ecs.v1 import job as _job +from openstack.ecs.v1 import flavors +from openstack.ecs.v1 import quotas class Proxy(proxy2.BaseProxy): @@ -92,3 +94,39 @@ def get_job(self, job_id): :return: :class:`~openstack.ecs.v1.job.Job` """ return self._get(_job.Job, job_id) + + def flavors(self, **query): + """Retrieve a generator of flavors + + :param dict query: Optional query parameters to be sent to limit the + resources being returned. + * ``availability_zone``: Zone name + + :returns: A generator of flavors (:class:`~openstack.ecs.v1.flavors.Flavor`) + instances + """ + return self._list(flavors.Flavor, paginated=False, **query) + + def quotas(self): + """Get a quotas + :param None + :rtype: :class:`~openstack.ecs.v1.quotas.Quota` + """ + return self._get(quotas.Quota, requires_id=False) + + def get_server(self, server_id): + """ + Get method to retrieve a ecs server. + :param server_id: Id of ecs server. + :return: :class:`~openstack.ecs.v1.server.Servers` + """ + return self._get(_server.Servers, server_id) + + def servers(self, **query): + """ + Retrieve a generator of servers. + :param query: Query parameters. + :return: A generator of server instances. + """ + res = self._get_resource(_server.ServerDetail, value=None, **query) + return res.list_by_offset(self._session, paginated=True, **query) diff --git a/openstack/ecs/v1/server.py b/openstack/ecs/v1/server.py index 2f4f39f..8fa4812 100644 --- a/openstack/ecs/v1/server.py +++ b/openstack/ecs/v1/server.py @@ -1,12 +1,12 @@ # -*- coding:utf-8 -*- # Copyright 2018 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 @@ -22,6 +22,7 @@ class Servers(resource2.Resource): resources_key = 'servers' service = ecs_service.EcsService() allow_create = True + allow_get = True # string type ECS server name name = resource2.Body('name') @@ -64,7 +65,7 @@ class Servers(resource2.Resource): # info for schedule server based host scheduler_hints = resource2.Body('os:scheduler_hints', type=dict) # tags for identify ecs servers - tags = resource2.Body('tags') + tags = resource2.Body('tags', type=list) # task id job_id = resource2.Body('job_id') # order id @@ -73,6 +74,78 @@ class Servers(resource2.Resource): message = resource2.Body('message') code = resource2.Body('code') + # Add fields for get/list server(s). + # Status of ecs server. + status = resource2.Body('status') + # Update time. + updated = resource2.Body('updated') + # Host ID of the host where the ECS is located. + hostId = resource2.Body('hostId') + # Host name of the host where the ECS is located. + OS_EXT_SRV_ATTR_host = resource2.Body('OS-EXT-SRV-ATTR:host') + # Network infomation of ecs server. + addresses = resource2.Body('addresses', type=dict) + # The state of the current task of the Elastic Cloud Server. + OS_EXT_STS_task_state = resource2.Body('OS-EXT-STS:task_state') + # The current state of the ECS. + OS_EXT_STS_vm_state = resource2.Body('OS-EXT-STS:vm_state') + # Elastic cloud server alias. + OS_EXT_SRV_ATTR_instance_name = resource2.Body('OS-EXT-SRV-ATTR:instance_name') + # The virtualized host name where the ECS is located. + OS_EXT_SRV_ATTR_hypervisor_hostname = resource2.Body('OS-EXT-SRV-ATTR:hypervisor_hostname') + # Elastic cloud server specification information. + flavor = resource2.Body('flavor', type=dict) + # Id of ecs server. + id = resource2.Body('id') + # The name of the available partition where the ECS is located. + OS_EXT_AZ_availability_zone = resource2.Body('OS-EXT-AZ:availability_zone') + # Create a user ID for the ECS. + user_id = resource2.Body('user_id') + # Create time. + created = resource2.Body('created') + # Type of disk config. + OS_DCF_diskConfig = resource2.Body('OS-DCF:diskConfig') + # Reserve attributes. + accessIPv4 = resource2.Body('accessIPv4') + # Reserve attributes. + accessIPv6 = resource2.Body('accessIPv6') + # Elastic cloud server progress. + progress = resource2.Body('progress', type=int) + # Elastic cloud server power status. + OS_EXT_STS_power_state = resource2.Body('OS-EXT-STS:power_state', type=int) + # Config drive information. + config_drive = resource2.Body('config_drive') + # Elastic cloud server startup time. + OS_SRV_USG_launched_at = resource2.Body('OS-SRV-USG:launched_at') + # Elastic cloud server delete time. + OS_SRV_USG_terminated_at = resource2.Body('OS-SRV-USG:terminated_at') + # Mount the disk to the Elastic Cloud Server. + os_extended_volumes_volumes_attached = resource2.Body('os-extended-volumes:volumes_attached', type=list) + # Description of ecs server. + description = resource2.Body('description') + # Nova compute status. + host_status = resource2.Body('host_status') + # The host name of the ECS. + OS_EXT_SRV_ATTR_hostname = resource2.Body('OS-EXT-SRV-ATTR:hostname') + # The reserved ID of the ECS. + OS_EXT_SRV_ATTR_reservation_id = resource2.Body('OS-EXT-SRV-ATTR:reservation_id') + # The startup sequence of the elastic cloud server. + OS_EXT_SRV_ATTR_launch_index = resource2.Body('OS-EXT-SRV-ATTR:launch_index', type=int) + # If the image in AMI format is used, it indicates the UUID of the kernel image. + OS_EXT_SRV_ATTR_kernel_id = resource2.Body('OS-EXT-SRV-ATTR:kernel_id') + # If the AMI format image is used, it indicates the UUID of the ramdisk image. + OS_EXT_SRV_ATTR_ramdisk_id = resource2.Body('OS-EXT-SRV-ATTR:ramdisk_id') + # Device name of the ECS system disk. + OS_EXT_SRV_ATTR_root_device_name = resource2.Body('OS-EXT-SRV-ATTR:root_device_name') + # User_data specified when creating an ECS. + OS_EXT_SRV_ATTR_user_data = resource2.Body('OS-EXT-SRV-ATTR:user_data') + # Whether the ECS is locked. + locked = resource2.Body('locked', type=bool) + # Enterprise project ID to which the ECS belongs. + enterprise_project_id = resource2.Body('enterprise_project_id') + # Elastic cloud server system label. + sys_tags = resource2.Body('sys_tags', type=list) + class ServerAction(resource2.Resource): base_path = "/cloudservers/action" @@ -145,4 +218,29 @@ class ResizeServer(resource2.Resource): order_id = resource2.Body('order_id') error = resource2.Body('error') message = resource2.Body('message') - code = resource2.Body('code') \ No newline at end of file + code = resource2.Body('code') + + +class ServerDetail(Servers): + base_path = '/cloudservers/detail' + + # capabilities + allow_create = False + allow_get = False + allow_list = True + + _query_mapping = resource2.QueryParameters( + 'name', + 'status', + 'limit', + 'offset', + 'not-tags', + 'reservation_id', + 'enterprise_project_id', + flavor_id='flavor' + ) + + # The total number of lists of elastic cloud servers. + count = resource2.Body('count', type=int) + # Elastic cloud server details list. + servers = resource2.Body('servers', type=list) diff --git a/openstack/profile.py b/openstack/profile.py index f71839b..f858cd3 100644 --- a/openstack/profile.py +++ b/openstack/profile.py @@ -97,6 +97,8 @@ from openstack.volume_backup import volume_backup_service from openstack.vpc import vpc_service from openstack.bms import bms_service +from openstack.csbs import csbs_service +from openstack.ims import ims_service # from openstack.nat import nat_service # from openstack.key_manager import key_manager_service # from openstack.bare_metal import bare_metal_service @@ -156,6 +158,8 @@ def __init__(self, plugins=None): self._add_service(ecs_service.EcsServiceV1_1(version='v1.1')) self._add_service(vpc_service.VpcService(version='v2.0')) self._add_service(bms_service.BmsService(version='v1')) + self._add_service(csbs_service.CsbsService(version='v1')) + self._add_service(ims_service.ImsService(version='v2')) # self._add_service(nat_service.NatService(version='v2.0')) self._add_service(lb_service.LoadBalancerService(version='v1')) # not support below service diff --git a/openstack/resource2.py b/openstack/resource2.py index 8542ef9..7d4473f 100644 --- a/openstack/resource2.py +++ b/openstack/resource2.py @@ -899,6 +899,81 @@ def list(cls, session, paginated=False, **params): query_params[cls.query_limit_key] = yielded query_params[cls.query_marker_key] = new_marker + @classmethod + def list_by_offset(cls, session, paginated=False, **params): + """This method is a generator which yields resource objects. + + This resource object list generator handles pagination and takes query + params for response filtering. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + :param bool paginated: ``True`` if a GET to this resource returns + a paginated series of responses, or ``False`` + if a GET returns only one page of data. + **When paginated is False only one + page of data will be returned regardless + of the API's support of pagination.** + :param dict params: These keyword arguments are passed through the + :meth:`~openstack.resource2.QueryParamter._transpose` method + to find if any of them match expected query parameters to be + sent in the *params* argument to + :meth:`~openstack.session.Session.get`. They are additionally + checked against the + :data:`~openstack.resource2.Resource.base_path` format string + to see if any path fragments need to be filled in by the contents + of this argument. + + :return: A generator of :class:`Resource` objects. + :raises: :exc:`~openstack.exceptions.MethodNotSupported` if + :data:`Resource.allow_list` is not set to ``True``. + """ + if not cls.allow_list: + raise exceptions.MethodNotSupported(cls, "list") + + more_data = True + query_params = cls._query_mapping._transpose(params) + uri = cls.get_list_uri(params) + offset = query_params.get("offset") + limit = query_params.get("limit") + + while more_data: + endpoint_override = cls.service.get_endpoint_override() + resp = session.get(uri, endpoint_filter=cls.service, + endpoint_override=endpoint_override, + headers={"Accept": "application/json"}, + params=query_params) + response_json = resp.json() + resources = response_json + + if not resources: + return + + resources.pop("self", None) + value = cls.existing(**resources) + yield value + + if not paginated: + return + + if offset is None: + return + + if limit is None: + return + + resource_list = resources[cls.resources_key] + current_page_size = len(resource_list) + + # Check if you need to continue sending requests. + if current_page_size < int(limit): + return + else: + if int(query_params.get("offset")) == 0: + query_params["offset"] = 2 + else: + query_params["offset"] = int(query_params.get("offset")) + 1 + @classmethod def _get_one_match(cls, name_or_id, results): """Given a list of results, return the match""" diff --git a/openstack/service_endpoint.py b/openstack/service_endpoint.py index 2c91f4a..9c0cd88 100644 --- a/openstack/service_endpoint.py +++ b/openstack/service_endpoint.py @@ -26,7 +26,7 @@ "DNS": { "public": "https://dns.%(domain)s/v2" }, - "ECS": { + "ECS": { "public": "https://ecs.%(region)s.%(domain)s/v1/%(project_id)s" }, "ECSV1.1": { diff --git a/openstack/tests/functional/ecs/v1/server.py b/openstack/tests/functional/ecs/v1/server.py index 119bc1d..6b93f6f 100644 --- a/openstack/tests/functional/ecs/v1/server.py +++ b/openstack/tests/functional/ecs/v1/server.py @@ -12,6 +12,31 @@ # CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. +import sys +import warnings + +from openstack import utils +from openstack import connection + +utils.enable_logging(debug=False, stream=sys.stdout) +warnings.filterwarnings('ignore') + +auth_url = '******' +userDomainId = '******' +projectId = '******' +username = '******' +password = '******' + +conn = connection.Connection( + auth_url=auth_url, + user_domain_id=userDomainId, + project_id=projectId, + username=username, + password=password, + verify=False +) + + def create_server_ext(conn): data = { "availability_zone": "az1.dc1", @@ -176,6 +201,18 @@ def resize_server(conn): print ff +# New dedicated host ID (only for Elastic Cloud Server on a dedicated host) +def resize_server_deh(conn): + server_id = "b38ce153-5e7f-4560-8617-54d6066bc926" + data = { + "flavorRef": "c1.2xlarge", + "dedicated_host_id": "b38ce153-5e7f-4560-8617-54d6066bc926" # only for Elastic Cloud Server on a dedicated host + + } + ff = conn.ecs.resize_server(server_id=server_id, **data) + print ff + + def delete_server(conn): data = { "servers": [ @@ -246,3 +283,30 @@ def server_action_restart(conn): } ff = conn.ecs.reboot_server(**data) print ff + + +def get_server(_conn): + ff = conn.ecs.get_server('600ea016-47c2-4aed-a8c1-c1a2106e3ad0') + print ff + + +def servers(_conn): + query = { + "offset": 1, + # Cloud server flavor ID, flavor_id is an alias for flavor. + "flavor_id": "c1.medium", + "name": "ecs-5280", + "status": "SHUTOFF", + "limit": 1 + } + generator = conn.ecs.servers(**query) + for servers_list in generator: + print servers_list + for server in servers_list.servers: + print(server.get('id')) + + +if __name__ == '__main__': + # get_server(conn) + # servers(conn) + pass diff --git a/openstack/vpc/v2/_proxy.py b/openstack/vpc/v2/_proxy.py index 134580e..638122f 100644 --- a/openstack/vpc/v2/_proxy.py +++ b/openstack/vpc/v2/_proxy.py @@ -15,6 +15,7 @@ from openstack import proxy2 from openstack.vpc.v2 import bandwidth as _bandwidth from openstack.vpc.v2 import eip as _eip +from openstack.vpc.v2 import sharebandwidth as _sharebandwidth class Proxy(proxy2.BaseProxy): @@ -42,3 +43,45 @@ def update_bandwidth_ext(self, bandwidth_id, **attrs): :rtype: :class:`~openstack.vpc.v2.bandwidth.Bandwidths` """ return self._create(_bandwidth.Bandwidths, bandwidth_id=bandwidth_id, **attrs) + + def create_sharebandwidth(self, **data): + """Create a share bandwidth. + + :param data: The attributes to create a share bandwidth. + :return: :class:`~openstack.vpc.v2.sharebandwidth.ShareBandwidth` + """ + return self._create(_sharebandwidth.ShareBandwidth, **data) + + def delete_sharebandwidth(self, bandwidth_id): + """Delete a share bandwidth. + + :param bandwidth_id: Id of share bandwidth. + :return: None + """ + return self._delete(_sharebandwidth.ShareBandwidth, bandwidth_id) + + def create_batch_sharebandwidth(self, **data): + """Create share bandwidth in batches. + + :param data: The attributes to create share bandwidth in batches. + :return: :class:`~openstack.vpc.v2.sharebandwidth.BatchShareBandwidth` + """ + return self._create(_sharebandwidth.BatchShareBandwidth, **data) + + def insert_ip_to_bandwidth(self, bandwidth_id, **data): + """Shared bandwidth is inserted into the elastic public IP address. + + :param bandwidth_id: Id of a bandwidth. + :param data: The attributes to insert ip to bandwidth. + :return: :class:`~openstack.vpc.v2.sharebandwidth.InsertIpToBandwidth` + """ + return self._create(_sharebandwidth.InsertIpToBandwidth, bandwidth_id=bandwidth_id, **data) + + def remove_ip_from_bandwidth(self, bandwidth_id, **data): + """Shared bandwidth removal elastic public IP. + + :param bandwidth_id: Id of a bandwidth. + :param data: The attributes to remove ip from bandwidth. + :return: None. + """ + return self._create(_sharebandwidth.RemoveIpFromBandwidth, bandwidth_id=bandwidth_id, **data)