summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwona Kotlarska <iwona260909@gmail.com>2017-08-28 21:19:44 +0200
committerIwona Kotlarska <iwona260909@gmail.com>2017-08-30 21:49:10 +0200
commitdaf20d91c623f45d5a88278e3d1e88e34e8ab0e5 (patch)
treea537bf40d3612f02b4a1000fd988fada711dbdd7
parent586a306358c555a042bcb5cfc76715756f370f87 (diff)
downloadpython-saharaclient-daf20d91c623f45d5a88278e3d1e88e34e8ab0e5.tar.gz
Add import of Cluster Templates
Partially-Implements: bp portable-node-group-and-cluster-templates This change adds command 'dataprocessing node group template import' to OpenStack CLI. Change-Id: I09866296c5b85910bf720d23d3213067f9f0a78a
-rw-r--r--saharaclient/osc/v1/cluster_templates.py82
-rw-r--r--setup.cfg1
2 files changed, 83 insertions, 0 deletions
diff --git a/saharaclient/osc/v1/cluster_templates.py b/saharaclient/osc/v1/cluster_templates.py
index 6d9491e..c3a5b6b 100644
--- a/saharaclient/osc/v1/cluster_templates.py
+++ b/saharaclient/osc/v1/cluster_templates.py
@@ -506,3 +506,85 @@ class UpdateClusterTemplate(command.ShowOne):
data = utils.prepare_data(data, CT_FIELDS)
return self.dict2columns(data)
+
+
+class ImportClusterTemplate(command.ShowOne):
+ """Imports node group template"""
+
+ log = logging.getLogger(__name__ + ".ImportClusterTemplate")
+
+ def get_parser(self, prog_name):
+ parser = super(ImportClusterTemplate, self).get_parser(prog_name)
+
+ parser.add_argument(
+ 'json',
+ metavar="<json>",
+ help="JSON containing cluster template",
+ )
+ parser.add_argument(
+ '--name',
+ metavar="<name>",
+ help="Name of the cluster template",
+ )
+ parser.add_argument(
+ '--default-image-id',
+ metavar="<default_image_id>",
+ help="Default image ID to be used",
+ )
+ parser.add_argument(
+ '--node-groups',
+ metavar="<node-group:instances_count>",
+ nargs="+",
+ required=True,
+ help="List of the node groups(names or IDs) and numbers of "
+ "instances for each one of them"
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ self.log.debug("take_action(%s)", parsed_args)
+ client = self.app.client_manager.data_processing
+
+ if (not parsed_args.node_groups):
+ raise exceptions.CommandError('--node_groups should be specified')
+
+ blob = osc_utils.read_blob_file_contents(parsed_args.json)
+ try:
+ template = json.loads(blob)
+ except ValueError as e:
+ raise exceptions.CommandError(
+ 'An error occurred when reading '
+ 'template from file %s: %s' % (parsed_args.json, e))
+
+ if parsed_args.default_image_id:
+ template['cluster_template']['default_image_id'] = (
+ parsed_args.default_image_id)
+ else:
+ template['cluster_template']['default_image_id'] = None
+
+ if parsed_args.name:
+ template['cluster_template']['name'] = parsed_args.name
+
+ if 'neutron_management_network' in template['cluster_template']:
+ template['cluster_template']['net_id'] = (
+ template['cluster_template'].pop('neutron_management_network'))
+
+ plugin, plugin_version, node_groups = _configure_node_groups(
+ parsed_args.node_groups, client)
+ if (('plugin_version' in template['cluster_template'] and
+ template['cluster_template']['plugin_version'] !=
+ plugin_version) or
+ ('plugin' in template['cluster_template'] and
+ template['cluster_template']['plugin'] != plugin)):
+ raise exceptions.CommandError(
+ 'Plugin of plugin version do not match between template '
+ 'and given node group templates')
+ template['cluster_template']['node_groups'] = node_groups
+
+ data = client.cluster_templates.create(
+ **template['cluster_template']).to_dict()
+
+ _format_ct_output(data)
+ data = utils.prepare_data(data, CT_FIELDS)
+
+ return self.dict2columns(data)
diff --git a/setup.cfg b/setup.cfg
index 1ad6fb8..d1fa15a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -61,6 +61,7 @@ openstack.data_processing.v1 =
dataprocessing_cluster_template_show = saharaclient.osc.v1.cluster_templates:ShowClusterTemplate
dataprocessing_cluster_template_update = saharaclient.osc.v1.cluster_templates:UpdateClusterTemplate
dataprocessing_cluster_template_delete = saharaclient.osc.v1.cluster_templates:DeleteClusterTemplate
+ dataprocessing_cluster_template_import = saharaclient.osc.v1.cluster_templates:ImportClusterTemplate
dataprocessing_cluster_create = saharaclient.osc.v1.clusters:CreateCluster
dataprocessing_cluster_list = saharaclient.osc.v1.clusters:ListClusters