def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing credentials = {} if parsed_args.username: credentials['user'] = parsed_args.username if parsed_args.password: credentials['password'] = parsed_args.password if not credentials: credentials = None update_fields = utils.create_dict_from_kwargs( name=parsed_args.name, description=parsed_args.description, type=parsed_args.type, url=parsed_args.url, credentials=credentials, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected) ds_id = utils.get_resource_id(client.data_sources, parsed_args.data_source) data = client.data_sources.update(ds_id, update_fields).data_source data = utils.prepare_data(data, DATA_SOURCE_FIELDS) return self.dict2columns(data)
def test_get_resource_id(self): manager = mock.Mock() uuid = '82065b4d-2c79-420d-adc3-310de275e922' manager.find_unique.return_value = mock.Mock(id=uuid) # check case when resource id is passed res = utils.get_resource_id(manager, uuid) self.assertEqual(uuid, res) manager.get.assert_not_called() manager.find_unique.assert_not_called() # check case when resource name is passed res = utils.get_resource_id(manager, 'name') manager.find_unique.assert_called_once_with(name='name') self.assertEqual(uuid, res)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing cluster_id = utils.get_resource_id(client.clusters, parsed_args.cluster) 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)) update_dict = utils.create_dict_from_kwargs( name=parsed_args.name, description=parsed_args.description, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected, shares=shares) data = client.clusters.update(cluster_id, **update_dict).cluster _format_cluster_output(data) data = utils.prepare_data(data, CLUSTER_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing credentials = {} if parsed_args.username: credentials['user'] = parsed_args.username if parsed_args.password: credentials['password'] = parsed_args.password if not credentials: credentials = None update_fields = utils.create_dict_from_kwargs( name=parsed_args.name, description=parsed_args.description, type=parsed_args.type, url=parsed_args.url, credentials=credentials, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected) ds_id = utils.get_resource_id( client.data_sources, parsed_args.data_source) data = client.data_sources.update(ds_id, update_fields).data_source data = utils.prepare_data(data, DATA_SOURCE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing for jt in parsed_args.job_template: jt_id = utils.get_resource_id(client.jobs, jt) client.jobs.delete(jt_id) sys.stdout.write('Job template "{jt}" has been removed ' 'successfully.\n'.format(jt=jt))
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing for image in parsed_args.image: image_id = utils.get_resource_id(client.images, image) client.images.unregister_image(image_id) sys.stdout.write('Image "{image}" has been unregistered ' 'successfully.\n'.format(image=image))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for ngt in parsed_args.node_group_template: ngt_id = utils.get_resource_id(client.node_group_templates, ngt) client.node_group_templates.delete(ngt_id) sys.stdout.write('Node group template "{ngt}" has been removed ' 'successfully.\n'.format(ngt=ngt))
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing for ct in parsed_args.cluster_template: ct_id = utils.get_resource_id(client.cluster_templates, ct) client.cluster_templates.delete(ct_id) sys.stdout.write('Cluster template "{ct}" has been removed ' 'successfully.\n'.format(ct=ct))
def take_action(self, parsed_args): 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 = jsonutils.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.jobs.create(**template).to_dict() else: if parsed_args.interface: blob = osc_utils.read_blob_file_contents(parsed_args.json) try: parsed_args.interface = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'interface from file %s: %s' % (parsed_args.json, e)) mains_ids = [ utils.get_resource_id(client.job_binaries, m) for m in parsed_args.mains ] if parsed_args.mains else None libs_ids = [ utils.get_resource_id(client.job_binaries, m) for m in parsed_args.libs ] if parsed_args.libs else None data = client.jobs.create( name=parsed_args.name, type=parsed_args.type, mains=mains_ids, libs=libs_ids, description=parsed_args.description, interface=parsed_args.interface, is_public=parsed_args.public, is_protected=parsed_args.protected).to_dict() _format_job_template_output(data) data = utils.prepare_data(data, JOB_TEMPLATE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for ds in parsed_args.data_source: data_source_id = utils.get_resource_id(client.data_sources, ds) client.data_sources.delete(data_source_id) sys.stdout.write('Data Source "{ds}" has been removed ' 'successfully.\n'.format(ds=ds))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for image in parsed_args.image: image_id = utils.get_resource_id(client.images, image) client.images.unregister_image(image_id) sys.stdout.write( 'Image "{image}" has been unregistered ' 'successfully.\n'.format(image=image))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for jt in parsed_args.job_template: jt_id = utils.get_resource_id(client.jobs, jt) client.jobs.delete(jt_id) sys.stdout.write( 'Job template "{jt}" has been removed ' 'successfully.\n'.format(jt=jt))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for ct in parsed_args.cluster_template: ct_id = utils.get_resource_id(client.cluster_templates, ct) client.cluster_templates.delete(ct_id) sys.stdout.write( 'Cluster template "{ct}" has been removed ' 'successfully.\n'.format(ct=ct))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for ds in parsed_args.data_source: data_source_id = utils.get_resource_id( client.data_sources, ds) client.data_sources.delete(data_source_id) sys.stdout.write( 'Data Source "{ds}" has been removed ' 'successfully.\n'.format(ds=ds))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing for ngt in parsed_args.node_group_template: ngt_id = utils.get_resource_id( client.node_group_templates, ngt) client.node_group_templates.delete(ngt_id) sys.stdout.write( 'Node group template "{ngt}" has been removed ' 'successfully.\n'.format(ngt=ngt))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing image_id = utils.get_resource_id(client.images, parsed_args.image) data = client.images.update_tags(image_id, parsed_args.tags).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing image_id = utils.get_resource_id(client.images, parsed_args.image) data = client.images.update_tags(image_id, parsed_args.tags).to_dict() data['tags'] = osc_utils.format_list(data['tags']) data = utils.prepare_data(data, IMAGE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): 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 = jsonutils.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.jobs.create(**template).to_dict() else: if parsed_args.interface: blob = osc_utils.read_blob_file_contents(parsed_args.json) try: parsed_args.interface = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'interface from file %s: %s' % (parsed_args.json, e)) mains_ids = [utils.get_resource_id(client.job_binaries, m) for m in parsed_args.mains] if parsed_args.mains else None libs_ids = [utils.get_resource_id(client.job_binaries, m) for m in parsed_args.libs] if parsed_args.libs else None data = client.jobs.create( name=parsed_args.name, type=parsed_args.type, mains=mains_ids, libs=libs_ids, description=parsed_args.description, interface=parsed_args.interface, is_public=parsed_args.public, is_protected=parsed_args.protected).to_dict() _format_job_template_output(data) data = utils.prepare_data(data, JOB_TEMPLATE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing jt_id = utils.get_resource_id(client.jobs, parsed_args.job_template) update_data = utils.create_dict_from_kwargs( name=parsed_args.name, description=parsed_args.description, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected) data = client.jobs.update(jt_id, **update_data).job _format_job_template_output(data) data = utils.prepare_data(data, JOB_TEMPLATE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing jb_id = utils.get_resource_id(client.job_binaries, parsed_args.job_binary) if parsed_args.json: blob = osc_utils.read_blob_file_contents(parsed_args.json) try: template = jsonutils.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.job_binaries.update(jb_id, template).to_dict() else: if parsed_args.password_prompt: parsed_args.password = osc_utils.get_password(self.app.stdin, confirm=False) extra = {} if parsed_args.password: extra['password'] = parsed_args.password if parsed_args.username: extra['user'] = parsed_args.username if not extra: extra = None update_fields = utils.create_dict_from_kwargs( name=parsed_args.name, url=parsed_args.url, description=parsed_args.description, extra=extra, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected) data = client.job_binaries.update(jb_id, update_fields).to_dict() data = utils.prepare_data(data, JOB_BINARY_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing jb_id = utils.get_resource_id( client.job_binaries, parsed_args.job_binary) if parsed_args.json: blob = osc_utils.read_blob_file_contents(parsed_args.json) try: template = jsonutils.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.job_binaries.update(jb_id, template).to_dict() else: if parsed_args.password_prompt: parsed_args.password = osc_utils.get_password( self.app.stdin, confirm=False) extra = {} if parsed_args.password: extra['password'] = parsed_args.password if parsed_args.username: extra['user'] = parsed_args.username if not extra: extra = None update_fields = utils.create_dict_from_kwargs( name=parsed_args.name, url=parsed_args.url, description=parsed_args.description, extra=extra, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected ) data = client.job_binaries.update( jb_id, update_fields).to_dict() data = utils.prepare_data(data, JOB_BINARY_FIELDS) return self.dict2columns(data)
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.file: parsed_args.file = parsed_args.job_binary jb_id = utils.get_resource_id( client.job_binaries, parsed_args.job_binary) data = client.job_binaries.get_file(jb_id) if path.exists(parsed_args.file): self.log.error('File "%s" already exists. Chose another one with ' '--file argument.' % parsed_args.file) else: with open(parsed_args.file, 'w') as f: f.write(data) sys.stdout.write( 'Job binary "{jb}" has been downloaded ' 'successfully.\n'.format(jb=parsed_args.job_binary))
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.file: parsed_args.file = parsed_args.job_binary jb_id = utils.get_resource_id(client.job_binaries, parsed_args.job_binary) data = client.job_binaries.get_file(jb_id) if path.exists(parsed_args.file): self.log.error('File "%s" already exists. Chose another one with ' '--file argument.' % parsed_args.file) else: with open(parsed_args.file, 'w') as f: f.write(data) sys.stdout.write( 'Job binary "{jb}" has been downloaded ' 'successfully.\n'.format(jb=parsed_args.job_binary))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing jt_id = utils.get_resource_id( client.jobs, parsed_args.job_template) update_data = utils.create_dict_from_kwargs( name=parsed_args.name, description=parsed_args.description, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected ) data = client.jobs.update(jt_id, **update_data).job _format_job_template_output(data) data = utils.prepare_data(data, JOB_TEMPLATE_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing clusters = [] for cluster in parsed_args.cluster: cluster_id = utils.get_resource_id(client.clusters, cluster) client.clusters.delete(cluster_id) clusters.append((cluster_id, cluster)) sys.stdout.write( 'Cluster "{cluster}" deletion has been started.\n'.format( cluster=cluster)) if parsed_args.wait: for cluster_id, cluster_arg in clusters: if not utils.wait_for_delete(client.clusters, cluster_id): self.log.error( 'Error occurred during cluster deleting: %s' % cluster_id) else: sys.stdout.write( 'Cluster "{cluster}" has been removed ' 'successfully.\n'.format(cluster=cluster_arg))
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing if parsed_args.show: data = utils.get_resource(client.clusters, parsed_args.cluster).to_dict() ver_data, ver_fields = _prepare_health_checks(data) data = utils.prepare_data(ver_data, ver_fields) return self.dict2columns(data) else: cluster_id = utils.get_resource_id(client.clusters, parsed_args.cluster) client.clusters.verification_update(cluster_id, parsed_args.status) if parsed_args.status == 'START': print_status = 'started' sys.stdout.write( 'Cluster "{cluster}" health verification has been ' '{status}.'.format(cluster=parsed_args.cluster, status=print_status)) return {}, {}
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing network_client = self.app.client_manager.network 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)) if 'neutron_management_network' in template: template['net_id'] = template.pop('neutron_management_network') if 'count' in template: parsed_args.count = template['count'] data = client.clusters.create(**template).to_dict() else: if not parsed_args.name or not parsed_args.cluster_template \ or not parsed_args.image: raise exceptions.CommandError( 'At least --name , --cluster-template, --image arguments ' 'should be specified or json template should be provided ' 'with --json argument') plugin, plugin_version, template_id = _get_plugin_version( parsed_args.cluster_template, client) image_id = utils.get_resource_id(client.images, parsed_args.image) net_id = (network_client.find_network(parsed_args.neutron_network, ignore_missing=False).id if parsed_args.neutron_network else None) data = client.clusters.create( name=parsed_args.name, plugin_name=plugin, hadoop_version=plugin_version, cluster_template_id=template_id, default_image_id=image_id, description=parsed_args.description, is_transient=parsed_args.transient, user_keypair_id=parsed_args.user_keypair, net_id=net_id, count=parsed_args.count, is_public=parsed_args.public, is_protected=parsed_args.protected).to_dict() if parsed_args.count and parsed_args.count > 1: clusters = [ utils.get_resource(client.clusters, id) for id in data['clusters'] ] if parsed_args.wait: for cluster in clusters: if not osc_utils.wait_for_status(client.clusters.get, cluster.id): self.log.error( 'Error occurred during cluster creation: %s' % data['id']) data = {} for cluster in clusters: data[cluster.name] = cluster.id else: if parsed_args.wait: if not osc_utils.wait_for_status(client.clusters.get, data['id']): self.log.error( 'Error occurred during cluster creation: %s' % data['id']) data = client.clusters.get(data['id']).to_dict() _format_cluster_output(data) data = utils.prepare_data(data, CLUSTER_FIELDS) return self.dict2columns(data)
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) 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 ) data = client.node_group_templates.update( ngt_id, **update_dict).to_dict() _format_ngt_output(data) data = utils.prepare_data(data, NGT_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing ct_id = utils.get_resource_id(client.cluster_templates, parsed_args.cluster_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.cluster_templates.update(ct_id, **template).to_dict() else: plugin, plugin_version, node_groups = None, None, None if parsed_args.node_groups: plugin, plugin_version, node_groups = _configure_node_groups( parsed_args.node_groups, client) 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)) update_dict = utils.create_dict_from_kwargs( name=parsed_args.name, plugin_name=plugin, hadoop_version=plugin_version, description=parsed_args.description, node_groups=node_groups, use_autoconfig=parsed_args.use_autoconfig, cluster_configs=configs, shares=shares, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected, domain_name=parsed_args.domain_name) data = client.cluster_templates.update(ct_id, **update_dict).to_dict() _format_ct_output(data) data = utils.prepare_data(data, CT_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.data_processing ct_id = utils.get_resource_id( client.cluster_templates, parsed_args.cluster_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.cluster_templates.update( ct_id, **template).to_dict() else: plugin, plugin_version, node_groups = None, None, None if parsed_args.node_groups: plugin, plugin_version, node_groups = _configure_node_groups( parsed_args.node_groups, client) 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)) update_dict = utils.create_dict_from_kwargs( name=parsed_args.name, plugin_name=plugin, hadoop_version=plugin_version, description=parsed_args.description, node_groups=node_groups, use_autoconfig=parsed_args.use_autoconfig, cluster_configs=configs, shares=shares, is_public=parsed_args.is_public, is_protected=parsed_args.is_protected ) data = client.cluster_templates.update( ct_id, **update_dict).to_dict() _format_ct_output(data) data = utils.prepare_data(data, CT_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): 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 = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError('An error occurred when reading ' 'template from file %s: %s' % (parsed_args.json, e)) if 'job_configs' in template: template['configs'] = template.pop('job_configs') data = client.job_executions.create(**template).to_dict() else: if not parsed_args.cluster or not parsed_args.job_template: raise exceptions.CommandError( 'At least --cluster, --job-template, arguments should be ' 'specified or json template should be provided with ' '--json argument') job_configs = {} if parsed_args.interface: blob = osc_utils.read_blob_file_contents(parsed_args.json) try: parsed_args.interface = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'interface from file %s: %s' % (parsed_args.json, e)) if parsed_args.config_json: blob = osc_utils.read_blob_file_contents(parsed_args.configs) try: job_configs['configs'] = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'configs from file %s: %s' % (parsed_args.json, e)) elif parsed_args.configs: job_configs['configs'] = dict( map(lambda x: x.split(':', 1), parsed_args.configs)) if parsed_args.args: job_configs['args'] = parsed_args.args if parsed_args.params: job_configs['params'] = dict( map(lambda x: x.split(':', 1), parsed_args.params)) jt_id = utils.get_resource_id(client.jobs, parsed_args.job_template) cluster_id = utils.get_resource_id(client.clusters, parsed_args.cluster) input_id = utils.get_resource_id(client.data_sources, parsed_args.input) output_id = utils.get_resource_id(client.data_sources, parsed_args.output) data = client.job_executions.create( job_id=jt_id, cluster_id=cluster_id, input_id=input_id, output_id=output_id, interface=parsed_args.interface, configs=job_configs, is_public=parsed_args.public, is_protected=parsed_args.protected).to_dict() sys.stdout.write('Job "{job}" has been started successfully.\n'.format( job=data['id'])) _format_job_output(data) data = utils.prepare_data(data, JOB_FIELDS) return self.dict2columns(data)
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) 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 ) data = client.node_group_templates.update(ngt_id, **update_dict).to_dict() _format_ngt_output(data) data = utils.prepare_data(data, NGT_FIELDS) return self.dict2columns(data)
def take_action(self, parsed_args): 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 = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'template from file %s: %s' % (parsed_args.json, e)) if 'job_configs' in template: template['configs'] = template.pop('job_configs') data = client.job_executions.create(**template).to_dict() else: if not parsed_args.cluster or not parsed_args.job_template: raise exceptions.CommandError( 'At least --cluster, --job-template, arguments should be ' 'specified or json template should be provided with ' '--json argument') job_configs = {} if parsed_args.interface: blob = osc_utils.read_blob_file_contents(parsed_args.json) try: parsed_args.interface = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'interface from file %s: %s' % (parsed_args.json, e)) if parsed_args.config_json: blob = osc_utils.read_blob_file_contents(parsed_args.configs) try: job_configs['configs'] = jsonutils.loads(blob) except ValueError as e: raise exceptions.CommandError( 'An error occurred when reading ' 'configs from file %s: %s' % (parsed_args.json, e)) elif parsed_args.configs: job_configs['configs'] = dict( map(lambda x: x.split(':', 1), parsed_args.configs)) if parsed_args.args: job_configs['args'] = parsed_args.args if parsed_args.params: job_configs['params'] = dict( map(lambda x: x.split(':', 1), parsed_args.params)) jt_id = utils.get_resource_id( client.jobs, parsed_args.job_template) cluster_id = utils.get_resource_id( client.clusters, parsed_args.cluster) input_id = utils.get_resource_id( client.data_sources, parsed_args.input) output_id = utils.get_resource_id( client.data_sources, parsed_args.output) data = client.job_executions.create( job_id=jt_id, cluster_id=cluster_id, input_id=input_id, output_id=output_id, interface=parsed_args.interface, configs=job_configs, is_public=parsed_args.public, is_protected=parsed_args.protected).to_dict() sys.stdout.write( 'Job "{job}" has been started successfully.\n'.format( job=data['id'])) _format_job_output(data) data = utils.prepare_data(data, JOB_FIELDS) return self.dict2columns(data)