summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwona Kotlarska <iwona260909@gmail.com>2017-07-25 15:16:41 +0200
committerIwona Kotlarska <iwona260909@gmail.com>2017-08-31 23:23:20 +0200
commited08870363e2d864ad498b9f7132c3475bd12398 (patch)
tree90b36e107e532295aac44a70f445f30c9caea213
parent586a306358c555a042bcb5cfc76715756f370f87 (diff)
downloadpython-saharaclient-ed08870363e2d864ad498b9f7132c3475bd12398.tar.gz
Add import of node group templates
Partially-Implements: bp portable-node-group-and-cluster-templates This change adds command 'dataprocessing node group template import' to OpenStack CLI. Change-Id: Ic1e3a681a32171503ea7c2fc40283965a1a62a49
-rw-r--r--saharaclient/osc/v1/node_group_templates.py75
-rw-r--r--setup.cfg1
2 files changed, 76 insertions, 0 deletions
diff --git a/saharaclient/osc/v1/node_group_templates.py b/saharaclient/osc/v1/node_group_templates.py
index dec774d..f65f993 100644
--- a/saharaclient/osc/v1/node_group_templates.py
+++ b/saharaclient/osc/v1/node_group_templates.py
@@ -689,3 +689,78 @@ class UpdateNodeGroupTemplate(command.ShowOne):
data = utils.prepare_data(data, NGT_FIELDS)
return self.dict2columns(data)
+
+
+class ImportNodeGroupTemplate(command.ShowOne):
+ """Imports node group template"""
+
+ log = logging.getLogger(__name__ + ".ImportNodeGroupTemplate")
+
+ def get_parser(self, prog_name):
+ parser = super(ImportNodeGroupTemplate, self).get_parser(prog_name)
+
+ parser.add_argument(
+ 'json',
+ metavar="<json>",
+ help="JSON containing node group template",
+ )
+ parser.add_argument(
+ '--name',
+ metavar="<name>",
+ help="Name of the node group template",
+ )
+ parser.add_argument(
+ '--security_groups',
+ metavar="<security_groups>",
+ help="Security groups of the node group template"
+ )
+ parser.add_argument(
+ '--floating_ip_pool',
+ metavar="<floating_ip_pool>",
+ help="Floating IP pool of the node group template"
+ )
+ parser.add_argument(
+ '--image_id',
+ metavar="<image_id>",
+ required=True,
+ help="Image ID of the node group template",
+ )
+ parser.add_argument(
+ '--flavor_id',
+ metavar="<flavor_id>",
+ required=True,
+ help="Flavor ID of the node group template",
+ )
+ 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.image_id or
+ not parsed_args.flavor_id):
+ raise exceptions.CommandError(
+ 'At least --image_id and --flavor_id 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))
+ template['node_group_template']['floating_ip_pool'] = (
+ parsed_args.floating_ip_pool)
+ template['node_group_template']['image_id'] = (
+ parsed_args.image_id)
+ template['node_group_template']['flavor_id'] = (
+ parsed_args.flavor_id)
+ template['node_group_template']['security_groups'] = (
+ parsed_args.security_groups)
+ if parsed_args.name:
+ template['node_group_template']['name'] = parsed_args.name
+ data = client.node_group_templates.create(
+ **template['node_group_template']).to_dict()
+
+ _format_ngt_output(data)
+ data = utils.prepare_data(data, NGT_FIELDS)
+
+ return self.dict2columns(data)
diff --git a/setup.cfg b/setup.cfg
index 1ad6fb8..3cc7d9c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -55,6 +55,7 @@ openstack.data_processing.v1 =
dataprocessing_node_group_template_show = saharaclient.osc.v1.node_group_templates:ShowNodeGroupTemplate
dataprocessing_node_group_template_update = saharaclient.osc.v1.node_group_templates:UpdateNodeGroupTemplate
dataprocessing_node_group_template_delete = saharaclient.osc.v1.node_group_templates:DeleteNodeGroupTemplate
+ dataprocessing_node_group_template_import = saharaclient.osc.v1.node_group_templates:ImportNodeGroupTemplate
dataprocessing_cluster_template_create = saharaclient.osc.v1.cluster_templates:CreateClusterTemplate
dataprocessing_cluster_template_list = saharaclient.osc.v1.cluster_templates:ListClusterTemplates