Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新ResizeCluster接口 #102

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qingcloud/iaas/actions/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 20 additions & 0 deletions qingcloud/iaas/actions/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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',
Expand Down
60 changes: 60 additions & 0 deletions tests/actions/test_resize_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# =========================================================================
# 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):

protocol = None
port = None
host = None
conn = None
zone = None
secret_access_key = None
access_key_id = None

@classmethod
def test_resize_cluster(self):
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=self.host,
port=self.port,
protocol=self.protocol,

)
cluster = ""
# node_role_not_list = {"cpu": 2, "memory": 2048, "volume_size": 120, "storage_size": 120, "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)
assert resp.get('ret_code') == 0