Support resize api
Task: 29572 Story: 2005054 Change-Id: Ic9ede21bbf87883d7dbdf9fde02e7dba24440ce7
This commit is contained in:
parent
c79d673096
commit
94380f9ad5
@ -17,7 +17,8 @@ from osc_lib import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_API_VERSION = '1'
|
||||
DEFAULT_MAJOR_API_VERSION = '1'
|
||||
DEFAULT_MAGNUM_API_VERSION = 'latest'
|
||||
API_VERSION_OPTION = 'os_container_infra_api_version'
|
||||
API_NAME = 'container_infra'
|
||||
API_VERSIONS = {
|
||||
@ -37,7 +38,8 @@ def make_client(instance):
|
||||
region_name=instance._region_name,
|
||||
interface=instance._interface,
|
||||
insecure=instance._insecure,
|
||||
ca_cert=instance._cacert)
|
||||
ca_cert=instance._cacert,
|
||||
api_version=DEFAULT_MAGNUM_API_VERSION)
|
||||
return client
|
||||
|
||||
|
||||
@ -49,8 +51,8 @@ def build_option_parser(parser):
|
||||
metavar='<container-infra-api-version>',
|
||||
default=utils.env(
|
||||
'OS_CONTAINER_INFRA_API_VERSION',
|
||||
default=DEFAULT_API_VERSION),
|
||||
default=DEFAULT_MAJOR_API_VERSION),
|
||||
help='Container-Infra API version, default=' +
|
||||
DEFAULT_API_VERSION +
|
||||
DEFAULT_MAJOR_API_VERSION +
|
||||
' (Env: OS_CONTAINER_INFRA_API_VERSION)')
|
||||
return parser
|
||||
|
@ -370,3 +370,46 @@ class ConfigCluster(command.Command):
|
||||
cluster, cluster_template, parsed_args.dir,
|
||||
force=parsed_args.force, certs=tls,
|
||||
use_keystone=parsed_args.use_keystone))
|
||||
|
||||
|
||||
class ResizeCluster(command.Command):
|
||||
_description = _("Resize a Cluster")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ResizeCluster, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'cluster',
|
||||
metavar='<cluster>',
|
||||
help=_('The name or UUID of cluster to update'))
|
||||
|
||||
parser.add_argument(
|
||||
'node_count',
|
||||
type=int,
|
||||
help=_("Desired node count of the cluser."))
|
||||
|
||||
parser.add_argument(
|
||||
'--nodes-to-remove',
|
||||
metavar='<Server UUID>',
|
||||
action='append',
|
||||
help=_("Server ID of the nodes to be removed. Repeat to add"
|
||||
"more server ID"))
|
||||
|
||||
parser.add_argument(
|
||||
'--nodegroup',
|
||||
metavar='<nodegroup>',
|
||||
help=_('The name or UUID of the nodegroup of current cluster.'))
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
mag_client = self.app.client_manager.container_infra
|
||||
cluster = mag_client.clusters.get(parsed_args.cluster)
|
||||
|
||||
mag_client.clusters.resize(cluster.uuid,
|
||||
parsed_args.node_count,
|
||||
parsed_args.nodes_to_remove,
|
||||
parsed_args.nodegroup)
|
||||
print("Request to resize cluster %s has been accepted." %
|
||||
parsed_args.cluster)
|
||||
|
@ -54,6 +54,10 @@ UPDATED_CLUSTER = copy.deepcopy(CLUSTER1)
|
||||
NEW_NAME = 'newcluster'
|
||||
UPDATED_CLUSTER['name'] = NEW_NAME
|
||||
|
||||
RESIZED_CLUSTER = copy.deepcopy(CLUSTER1)
|
||||
RESIZED_NODE_COUNT = 5
|
||||
UPDATED_CLUSTER['node_count'] = RESIZED_NODE_COUNT
|
||||
|
||||
fake_responses = {
|
||||
'/v1/clusters':
|
||||
{
|
||||
@ -145,6 +149,13 @@ fake_responses = {
|
||||
{'clusters': [CLUSTER2, CLUSTER1]},
|
||||
),
|
||||
},
|
||||
'/v1/clusters/%s/actions/resize' % CLUSTER1['uuid']:
|
||||
{
|
||||
'POST': (
|
||||
{},
|
||||
UPDATED_CLUSTER
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -355,3 +366,13 @@ class ClusterManagerTest(testtools.TestCase):
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(NEW_NAME, cluster.name)
|
||||
|
||||
def test_cluster_resize(self):
|
||||
body = {'node_count': RESIZED_NODE_COUNT}
|
||||
cluster = self.mgr.resize(CLUSTER1["uuid"], **body)
|
||||
expect = [
|
||||
('POST', '/v1/clusters/%s/actions/resize' % CLUSTER1['uuid'],
|
||||
{}, body),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(RESIZED_NODE_COUNT, cluster.node_count)
|
||||
|
@ -32,3 +32,18 @@ class Cluster(baseunit.BaseTemplate):
|
||||
class ClusterManager(baseunit.BaseTemplateManager):
|
||||
resource_class = Cluster
|
||||
template_name = 'clusters'
|
||||
|
||||
def resize(self, cluster_uuid, node_count,
|
||||
nodes_to_remove=[], nodegroup=None):
|
||||
url = self._path(cluster_uuid) + "/actions/resize"
|
||||
|
||||
post_body = {"node_count": node_count}
|
||||
if nodes_to_remove:
|
||||
post_body.update({"nodes_to_remove": nodes_to_remove})
|
||||
if nodegroup:
|
||||
post_body.update({"nodegroup": nodegroup})
|
||||
|
||||
resp, resp_body = self.api.json_request("POST", url, body=post_body)
|
||||
|
||||
if resp_body:
|
||||
return self.resource_class(self, resp_body)
|
||||
|
@ -43,6 +43,7 @@ openstack.container_infra.v1 =
|
||||
coe_cluster_show = magnumclient.osc.v1.clusters:ShowCluster
|
||||
coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster
|
||||
coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster
|
||||
coe_cluster_resize = magnumclient.osc.v1.clusters:ResizeCluster
|
||||
coe_ca_rotate = magnumclient.osc.v1.certificates:RotateCa
|
||||
coe_ca_show = magnumclient.osc.v1.certificates:ShowCa
|
||||
coe_ca_sign = magnumclient.osc.v1.certificates:SignCa
|
||||
|
Loading…
Reference in New Issue
Block a user