From 3d7bc90cc62b5afbcf5975f9e91741098c73c62a Mon Sep 17 00:00:00 2001 From: MarioMang Date: Sat, 11 Nov 2023 23:51:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?update.=20=E5=A2=9E=E5=8A=A0=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E4=BA=91=E4=B8=BB=E6=8E=A5=E5=8F=A3=E6=9C=BAGPU?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qingcloud/iaas/actions/instance.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qingcloud/iaas/actions/instance.py b/qingcloud/iaas/actions/instance.py index 1d94a78..d5ff371 100644 --- a/qingcloud/iaas/actions/instance.py +++ b/qingcloud/iaas/actions/instance.py @@ -86,6 +86,16 @@ def run_instances(self, image_id, cpu_max=None, mem_max=None, os_disk_size=None, + os_disk_encryption=None, + platform=None, + f_resetpwd=None, + processor_type=None, + default_user=None, + default_passwd=None, + hypervisor=None, + gpu=None, + gpu_class=None, + place_group_id=None, **ignore): """ Create one or more instances. @param image_id : ID of the image you want to use, "img-12345" @@ -116,6 +126,16 @@ def run_instances(self, image_id, @param cpu_max: max cpu core number. @param mem_max: max memory size in MB. @param os_disk_size: operation system disk size in GB. + @param os_disk_encryption: int, + @param platform: linux, + @param f_resetpwd: int, + @param processor_type: 64bit, + @param default_user: root, + @param default_passwd: password, + @param hypervisor: kvm, + @param gpu: int, + @param gpu_class: int, + @param place_group_id: string, """ action = const.ACTION_RUN_INSTANCES valid_keys = ['image_id', 'instance_type', 'cpu', 'memory', 'count', From 69b5f77a2fddec9e4a6556e4f9959f4a3a59e130 Mon Sep 17 00:00:00 2001 From: MarioMang Date: Fri, 15 Mar 2024 16:01:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?update.=20ResizeClusterInput=E4=B8=ADNodeRo?= =?UTF-8?q?le=E7=B1=BB=E5=9E=8B=E4=BB=8Estring=E5=8F=98=E4=B8=BA[]*string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qingcloud/iaas/actions/cluster.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qingcloud/iaas/actions/cluster.py b/qingcloud/iaas/actions/cluster.py index a875596..91fae32 100644 --- a/qingcloud/iaas/actions/cluster.py +++ b/qingcloud/iaas/actions/cluster.py @@ -68,13 +68,15 @@ def resize_cluster(self, cluster, @param memory: memory size in MB. @param storage_size: The new larger size of the storage_size, unit is GB. @param instance_class: The new class of instance + @param node_role: node role you want to. list type """ action = const.ACTION_RESIZE_CLUSTER valid_keys = ['cluster', 'node_role', 'cpu', 'memory', 'storage_size', 'instance_class'] body = filter_out_none(locals(), valid_keys) if not self.conn.req_checker.check_params(body, required_params=['cluster'], - integer_params=['cpu', 'memory'] + integer_params=['cpu', 'memory'], + list_params=['node_role'] ): return None From d5be7385b8e6d5fe00a53f2fe8aff873ec95588f Mon Sep 17 00:00:00 2001 From: MarioMang Date: Mon, 1 Apr 2024 16:06:32 +0800 Subject: [PATCH 3/4] add testcase --- tests/actions/test_resize_cluster.py | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/actions/test_resize_cluster.py diff --git a/tests/actions/test_resize_cluster.py b/tests/actions/test_resize_cluster.py new file mode 100644 index 0000000..d65b01e --- /dev/null +++ b/tests/actions/test_resize_cluster.py @@ -0,0 +1,54 @@ +# ========================================================================= +# Copyright 2012-present Yunify, Inc. +# ------------------------------------------------------------------------- +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this work except in compliance with the License. +# You may obtain a copy of the License in the LICENSE file, or 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 os +import unittest + +from qingcloud.iaas import APIConnection +from qingcloud.iaas.errors import InvalidRouterStatic +from qingcloud.iaas.actions.cluster import ClusterAction + + +class ClusterFactoryTestCase(unittest.TestCase): + + conn = None + zone = None + secret_access_key = None + access_key_id = None + + @classmethod + def test_resize_cluster(self): + self.access_key_id = "BHSWXNKSRKXUAXYCNXUI" + self.secret_access_key = "AK0RfVfmpafzkgwMKcTckudgeKH2efYHxn1Nu3qj" + self.zone = 'qa' + + self.conn = APIConnection( + qy_access_key_id=self.access_key_id, + qy_secret_access_key=self.secret_access_key, + zone=self.zone, + host="api.qacloud.com", + port="80", + protocol="http", + + ) + cluster = "cl-1ah8j7lp" + # node_role_not_list = {"cpu": 2, "memory": 2048, "volume_size": 120, "storage_size": 120, "node_role": "maininstance"} + node_role_with_list = [{"cpu":8,"memory":16384,"volume_size":100,"storage_size":100,"node_role":"maininstance"}] + + action = ClusterAction(self.conn) + resp = action.resize_cluster(cluster, node_role=node_role_with_list) + print(resp) + # self.assertEqual(resp['ret_code'], 0) + From 557e3d358ab67222da6f0404a6b0960dc9ff552d Mon Sep 17 00:00:00 2001 From: MarioMang Date: Mon, 1 Apr 2024 16:14:14 +0800 Subject: [PATCH 4/4] add testcase --- tests/actions/test_resize_cluster.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/actions/test_resize_cluster.py b/tests/actions/test_resize_cluster.py index d65b01e..95672e5 100644 --- a/tests/actions/test_resize_cluster.py +++ b/tests/actions/test_resize_cluster.py @@ -23,6 +23,9 @@ class ClusterFactoryTestCase(unittest.TestCase): + protocol = None + port = None + host = None conn = None zone = None secret_access_key = None @@ -30,25 +33,28 @@ class ClusterFactoryTestCase(unittest.TestCase): @classmethod def test_resize_cluster(self): - self.access_key_id = "BHSWXNKSRKXUAXYCNXUI" - self.secret_access_key = "AK0RfVfmpafzkgwMKcTckudgeKH2efYHxn1Nu3qj" - self.zone = 'qa' + self.access_key_id = os.getenv("QY_ACCESS_KEY_ID") + self.secret_access_key = os.getenv("QY_SECRET_ACCESS_KEY") + self.host = os.getenv("QY_HOST") + self.port = os.getenv("QY_PORT") + self.zone = os.getenv("QY_ZONE") + self.protocol = os.getenv("QY_PROTOCOL") self.conn = APIConnection( qy_access_key_id=self.access_key_id, qy_secret_access_key=self.secret_access_key, zone=self.zone, - host="api.qacloud.com", - port="80", - protocol="http", + host=self.host, + port=self.port, + protocol=self.protocol, ) - cluster = "cl-1ah8j7lp" + cluster = "" # node_role_not_list = {"cpu": 2, "memory": 2048, "volume_size": 120, "storage_size": 120, "node_role": "maininstance"} - node_role_with_list = [{"cpu":8,"memory":16384,"volume_size":100,"storage_size":100,"node_role":"maininstance"}] + node_role_with_list = [{"cpu":4,"memory":8192,"volume_size":100,"storage_size":100,"node_role":"maininstance"}] action = ClusterAction(self.conn) resp = action.resize_cluster(cluster, node_role=node_role_with_list) print(resp) - # self.assertEqual(resp['ret_code'], 0) + assert resp.get('ret_code') == 0