summaryrefslogtreecommitdiff
path: root/saharaclient/osc/v1/node_group_templates.py
diff options
context:
space:
mode:
Diffstat (limited to 'saharaclient/osc/v1/node_group_templates.py')
-rw-r--r--saharaclient/osc/v1/node_group_templates.py223
1 files changed, 14 insertions, 209 deletions
diff --git a/saharaclient/osc/v1/node_group_templates.py b/saharaclient/osc/v1/node_group_templates.py
index 9cfe282..590547e 100644
--- a/saharaclient/osc/v1/node_group_templates.py
+++ b/saharaclient/osc/v1/node_group_templates.py
@@ -16,12 +16,10 @@
import sys
from osc_lib.command import command
-from osc_lib import exceptions
from osc_lib import utils as osc_utils
from oslo_log import log as logging
-from oslo_serialization import jsonutils as json
-from saharaclient.osc.v1 import utils
+from saharaclient.osc import utils
NGT_FIELDS = ['id', 'name', 'plugin_name', 'plugin_version', 'node_processes',
'description', 'auto_security_group', 'security_groups',
@@ -43,7 +41,7 @@ def _format_ngt_output(data):
del data['volumes_size']
-class CreateNodeGroupTemplate(command.ShowOne):
+class CreateNodeGroupTemplate(command.ShowOne, utils.NodeGroupTemplatesUtils):
"""Creates node group template"""
log = logging.getLogger(__name__ + ".CreateNodeGroupTemplate")
@@ -202,73 +200,7 @@ class CreateNodeGroupTemplate(command.ShowOne):
self.log.debug("take_action(%s)", parsed_args)
client = self.app.client_manager.data_processing
- if parsed_args.json:
- 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))
- data = client.node_group_templates.create(**template).to_dict()
- else:
- if (not parsed_args.name or not parsed_args.plugin or
- not parsed_args.plugin_version or not parsed_args.flavor or
- not parsed_args.processes):
- raise exceptions.CommandError(
- 'At least --name, --plugin, --plugin-version, --processes,'
- ' --flavor arguments should be specified or json template '
- 'should be provided with --json argument')
-
- configs = None
- if parsed_args.configs:
- blob = osc_utils.read_blob_file_contents(parsed_args.configs)
- try:
- configs = json.loads(blob)
- except ValueError as e:
- raise exceptions.CommandError(
- 'An error occurred when reading '
- 'configs from file %s: %s' % (parsed_args.configs, e))
-
- shares = None
- if parsed_args.shares:
- blob = osc_utils.read_blob_file_contents(parsed_args.shares)
- try:
- shares = json.loads(blob)
- except ValueError as e:
- raise exceptions.CommandError(
- 'An error occurred when reading '
- 'shares from file %s: %s' % (parsed_args.shares, e))
-
- compute_client = self.app.client_manager.compute
- flavor_id = osc_utils.find_resource(
- compute_client.flavors, parsed_args.flavor).id
-
- data = client.node_group_templates.create(
- name=parsed_args.name,
- plugin_name=parsed_args.plugin,
- hadoop_version=parsed_args.plugin_version,
- flavor_id=flavor_id,
- description=parsed_args.description,
- volumes_per_node=parsed_args.volumes_per_node,
- volumes_size=parsed_args.volumes_size,
- node_processes=parsed_args.processes,
- floating_ip_pool=parsed_args.floating_ip_pool,
- security_groups=parsed_args.security_groups,
- auto_security_group=parsed_args.auto_security_group,
- availability_zone=parsed_args.availability_zone,
- volume_type=parsed_args.volumes_type,
- is_proxy_gateway=parsed_args.proxy_gateway,
- volume_local_to_instance=parsed_args.volumes_locality,
- use_autoconfig=parsed_args.autoconfig,
- is_public=parsed_args.public,
- is_protected=parsed_args.protected,
- node_configs=configs,
- shares=shares,
- volumes_availability_zone=(
- parsed_args.volumes_availability_zone),
- volume_mount_prefix=parsed_args.volumes_mount_prefix
- ).to_dict()
+ data = self._create_take_action(client, self.app, parsed_args)
_format_ngt_output(data)
data = utils.prepare_data(data, NGT_FIELDS)
@@ -276,7 +208,7 @@ class CreateNodeGroupTemplate(command.ShowOne):
return self.dict2columns(data)
-class ListNodeGroupTemplates(command.Lister):
+class ListNodeGroupTemplates(command.Lister, utils.NodeGroupTemplatesUtils):
"""Lists node group templates"""
log = logging.getLogger(__name__ + ".ListNodeGroupTemplates")
@@ -314,41 +246,10 @@ class ListNodeGroupTemplates(command.Lister):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
client = self.app.client_manager.data_processing
- search_opts = {}
- if parsed_args.plugin:
- search_opts['plugin_name'] = parsed_args.plugin
- if parsed_args.plugin_version:
- search_opts['hadoop_version'] = parsed_args.plugin_version
+ return self._list_take_action(client, self.app, parsed_args)
- data = client.node_group_templates.list(search_opts=search_opts)
- if parsed_args.name:
- data = utils.get_by_name_substring(data, parsed_args.name)
-
- if parsed_args.long:
- columns = ('name', 'id', 'plugin_name', 'hadoop_version',
- 'node_processes', 'description')
- column_headers = utils.prepare_column_headers(
- columns, {'hadoop_version': 'plugin_version'})
-
- else:
- columns = ('name', 'id', 'plugin_name', 'hadoop_version')
- column_headers = utils.prepare_column_headers(
- columns, {'hadoop_version': 'plugin_version'})
-
- return (
- column_headers,
- (osc_utils.get_item_properties(
- s,
- columns,
- formatters={
- 'node_processes': osc_utils.format_list
- }
- ) for s in data)
- )
-
-
-class ShowNodeGroupTemplate(command.ShowOne):
+class ShowNodeGroupTemplate(command.ShowOne, utils.NodeGroupTemplatesUtils):
"""Display node group template details"""
log = logging.getLogger(__name__ + ".ShowNodeGroupTemplate")
@@ -378,7 +279,7 @@ class ShowNodeGroupTemplate(command.ShowOne):
return self.dict2columns(data)
-class DeleteNodeGroupTemplate(command.Command):
+class DeleteNodeGroupTemplate(command.Command, utils.NodeGroupTemplatesUtils):
"""Deletes node group template"""
log = logging.getLogger(__name__ + ".DeleteNodeGroupTemplate")
@@ -406,7 +307,7 @@ class DeleteNodeGroupTemplate(command.Command):
'successfully.\n'.format(ngt=ngt))
-class UpdateNodeGroupTemplate(command.ShowOne):
+class UpdateNodeGroupTemplate(command.ShowOne, utils.NodeGroupTemplatesUtils):
"""Updates node group template"""
log = logging.getLogger(__name__ + ".UpdateNodeGroupTemplate")
@@ -620,74 +521,7 @@ class UpdateNodeGroupTemplate(command.ShowOne):
self.log.debug("take_action(%s)", parsed_args)
client = self.app.client_manager.data_processing
- ngt_id = utils.get_resource_id(
- client.node_group_templates, parsed_args.node_group_template)
-
- if parsed_args.json:
- 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))
- data = client.node_group_templates.update(
- ngt_id, **template).to_dict()
- else:
- configs = None
- if parsed_args.configs:
- blob = osc_utils.read_blob_file_contents(parsed_args.configs)
- try:
- configs = json.loads(blob)
- except ValueError as e:
- raise exceptions.CommandError(
- 'An error occurred when reading '
- 'configs from file %s: %s' % (parsed_args.configs, e))
-
- shares = None
- if parsed_args.shares:
- blob = osc_utils.read_blob_file_contents(parsed_args.shares)
- try:
- shares = json.loads(blob)
- except ValueError as e:
- raise exceptions.CommandError(
- 'An error occurred when reading '
- 'shares from file %s: %s' % (parsed_args.shares, e))
-
- flavor_id = None
- if parsed_args.flavor:
- compute_client = self.app.client_manager.compute
- flavor_id = osc_utils.find_resource(
- compute_client.flavors, parsed_args.flavor).id
-
- update_dict = utils.create_dict_from_kwargs(
- name=parsed_args.name,
- plugin_name=parsed_args.plugin,
- hadoop_version=parsed_args.plugin_version,
- flavor_id=flavor_id,
- description=parsed_args.description,
- volumes_per_node=parsed_args.volumes_per_node,
- volumes_size=parsed_args.volumes_size,
- node_processes=parsed_args.processes,
- floating_ip_pool=parsed_args.floating_ip_pool,
- security_groups=parsed_args.security_groups,
- auto_security_group=parsed_args.use_auto_security_group,
- availability_zone=parsed_args.availability_zone,
- volume_type=parsed_args.volumes_type,
- is_proxy_gateway=parsed_args.is_proxy_gateway,
- volume_local_to_instance=parsed_args.volume_locality,
- use_autoconfig=parsed_args.use_autoconfig,
- is_public=parsed_args.is_public,
- is_protected=parsed_args.is_protected,
- node_configs=configs,
- shares=shares,
- volumes_availability_zone=(
- parsed_args.volumes_availability_zone),
- volume_mount_prefix=parsed_args.volumes_mount_prefix
- )
-
- data = client.node_group_templates.update(
- ngt_id, **update_dict).to_dict()
+ data = self._update_take_action(client, self.app, parsed_args)
_format_ngt_output(data)
data = utils.prepare_data(data, NGT_FIELDS)
@@ -695,7 +529,7 @@ class UpdateNodeGroupTemplate(command.ShowOne):
return self.dict2columns(data)
-class ImportNodeGroupTemplate(command.ShowOne):
+class ImportNodeGroupTemplate(command.ShowOne, utils.NodeGroupTemplatesUtils):
"""Imports node group template"""
log = logging.getLogger(__name__ + ".ImportNodeGroupTemplate")
@@ -740,29 +574,8 @@ class ImportNodeGroupTemplate(command.ShowOne):
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()
+
+ data = self._import_take_action(client, parsed_args)
_format_ngt_output(data)
data = utils.prepare_data(data, NGT_FIELDS)
@@ -770,7 +583,7 @@ class ImportNodeGroupTemplate(command.ShowOne):
return self.dict2columns(data)
-class ExportNodeGroupTemplate(command.Command):
+class ExportNodeGroupTemplate(command.Command, utils.NodeGroupTemplatesUtils):
"""Export node group template to JSON"""
log = logging.getLogger(__name__ + ".ExportNodeGroupTemplate")
@@ -794,12 +607,4 @@ class ExportNodeGroupTemplate(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
client = self.app.client_manager.data_processing
- ngt_id = utils.get_resource_id(
- client.node_group_templates, parsed_args.node_group_template)
- response = client.node_group_templates.export(ngt_id)
- result = json.dumps(response._info, indent=4)+"\n"
- if parsed_args.file:
- with open(parsed_args.file, "w+") as file:
- file.write(result)
- else:
- sys.stdout.write(result)
+ self._export_take_action(client, parsed_args)