def _take_action(self, client, parsed_args): cluster = utils.get_resource( client.clusters, parsed_args.cluster) 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.clusters.scale(cluster.id, template).cluster else: scale_object = { "add_node_groups": [], "resize_node_groups": [] } scale_node_groups = dict( map(lambda x: x.split(':', 1), parsed_args.instances)) cluster_ng_map = { ng['node_group_template_id']: ng['name'] for ng in cluster.node_groups} for name, count in scale_node_groups.items(): ngt = utils.get_resource(client.node_group_templates, name) if ngt.id in cluster_ng_map: scale_object["resize_node_groups"].append({ "name": cluster_ng_map[ngt.id], "count": int(count) }) else: scale_object["add_node_groups"].append({ "node_group_template_id": ngt.id, "name": ngt.name, "count": int(count) }) if not scale_object['add_node_groups']: del scale_object['add_node_groups'] if not scale_object['resize_node_groups']: del scale_object['resize_node_groups'] data = client.clusters.scale(cluster.id, scale_object).cluster sys.stdout.write( 'Cluster "{cluster}" scaling has been started.\n'.format( cluster=parsed_args.cluster)) if parsed_args.wait: if not osc_utils.wait_for_status( client.clusters.get, data['id']): self.log.error( 'Error occurred during cluster scaling: %s' % cluster.id) data = client.clusters.get(cluster.id).cluster return data
def _take_action(self, client, parsed_args): cluster = utils.get_resource(client.clusters, parsed_args.cluster) 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.clusters.scale(cluster.id, template).cluster else: scale_object = {"add_node_groups": [], "resize_node_groups": []} scale_node_groups = dict( map(lambda x: x.split(':', 1), parsed_args.instances)) cluster_ng_map = { ng['node_group_template_id']: ng['name'] for ng in cluster.node_groups } for name, count in scale_node_groups.items(): ngt = utils.get_resource(client.node_group_templates, name) if ngt.id in cluster_ng_map: scale_object["resize_node_groups"].append({ "name": cluster_ng_map[ngt.id], "count": int(count) }) else: scale_object["add_node_groups"].append({ "node_group_template_id": ngt.id, "name": ngt.name, "count": int(count) }) if not scale_object['add_node_groups']: del scale_object['add_node_groups'] if not scale_object['resize_node_groups']: del scale_object['resize_node_groups'] data = client.clusters.scale(cluster.id, scale_object).cluster sys.stdout.write( 'Cluster "{cluster}" scaling has been started.\n'.format( cluster=parsed_args.cluster)) if parsed_args.wait: if not osc_utils.wait_for_status(client.clusters.get, data['id']): self.log.error('Error occurred during cluster scaling: %s' % cluster.id) data = client.clusters.get(cluster.id).cluster return data
def test_get_resource(self): manager = mock.Mock() # check case when resource id is passed uuid = '82065b4d-2c79-420d-adc3-310de275e922' utils.get_resource(manager, uuid) manager.get.assert_called_once_with(uuid) # check case when resource name is passed utils.get_resource(manager, 'name') manager.find_unique.assert_called_once_with(name='name')
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing data = self._take_action(client, parsed_args) 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(self.app, 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 data = utils.get_resource(client.data_sources, parsed_args.data_source).to_dict() 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 data = utils.get_resource( client.job_binaries, parsed_args.job_binary).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 data = utils.get_resource(client.images, parsed_args.image).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 data = utils.get_resource(client.job_binaries, parsed_args.job_binary).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 data = utils.get_resource(client.cluster_templates, parsed_args.cluster_template).to_dict() _format_ct_output(self.app, 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 data = utils.get_resource( client.cluster_templates, parsed_args.cluster_template).to_dict() _format_ct_output(self.app, 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 data = utils.get_resource( client.images, parsed_args.image).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, client, parsed_args): kwargs = {} if parsed_args.show_progress or parsed_args.full_dump_events: kwargs['show_progress'] = True data = utils.get_resource(client.clusters, parsed_args.cluster, **kwargs).to_dict() provision_steps = data.get('provision_progress', []) provision_steps = utils.created_at_sorted(provision_steps) if parsed_args.full_dump_events: file_name = utils.random_name('event-logs') # making full dump with open(file_name, 'w') as file: jsonutils.dump(provision_steps, file, indent=4) sys.stdout.write('Event log dump saved to file: %s\n' % file_name) return data, provision_steps
def _take_action(self, client, parsed_args): kwargs = {} if parsed_args.show_progress or parsed_args.full_dump_events: kwargs['show_progress'] = True data = utils.get_resource( client.clusters, parsed_args.cluster, **kwargs).to_dict() provision_steps = data.get('provision_progress', []) provision_steps = utils.created_at_sorted(provision_steps) if parsed_args.full_dump_events: file_name = utils.random_name('event-logs') # making full dump with open(file_name, 'w') as file: jsonutils.dump(provision_steps, file, indent=4) sys.stdout.write('Event log dump saved to file: %s\n' % file_name) return data, provision_steps
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing for jb in parsed_args.job_binary: jb = utils.get_resource(client.job_binaries, jb) if jb.url.startswith("internal-db"): jbi_id = jb.url.replace('internal-db://', '') try: client.job_binary_internals.delete(jbi_id) except base.APIException as ex: # check if job binary internal was already deleted for # some reasons if not ex.error_code == '404': raise client.job_binaries.delete(jb.id) sys.stdout.write('Job binary "{jb}" has been removed ' 'successfully.\n'.format(jb=jb))
def take_action(self, parsed_args): self.log.debug("take_action(%s)", parsed_args) client = self.app.client_manager.data_processing image = utils.get_resource(client.images, parsed_args.image) if parsed_args.all: data = client.images.update_tags(image.id, []).to_dict() else: parsed_args.tags = parsed_args.tags or [] new_tags = list(set(image.tags) - set(parsed_args.tags)) data = client.images.update_tags(image.id, new_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 for jb in parsed_args.job_binary: jb = utils.get_resource(client.job_binaries, jb) if jb.url.startswith("internal-db"): jbi_id = jb.url.replace('internal-db://', '') try: client.job_binary_internals.delete(jbi_id) except base.APIException as ex: # check if job binary internal was already deleted for # some reasons if not ex.error_code == '404': raise client.job_binaries.delete(jb.id) sys.stdout.write( 'Job binary "{jb}" has been removed ' 'successfully.\n'.format(jb=jb))
def _configure_node_groups(app, node_groups, client): node_groups_list = dict( map(lambda x: x.split(':', 1), node_groups)) node_groups = [] plugins_versions = set() for name, count in node_groups_list.items(): ng = utils.get_resource(client.node_group_templates, name) node_groups.append({'name': ng.name, 'count': int(count), 'node_group_template_id': ng.id}) plugins_versions.add((ng.plugin_name, ng.hadoop_version)) if len(plugins_versions) != 1: raise exceptions.CommandError('Node groups with the same plugins ' 'and versions must be specified') plugin, plugin_version = plugins_versions.pop() return plugin, plugin_version, node_groups
def _configure_node_groups(app, node_groups, client): node_groups_list = dict(map(lambda x: x.split(':', 1), node_groups)) node_groups = [] plugins_versions = set() for name, count in node_groups_list.items(): ng = utils.get_resource(client.node_group_templates, name) node_groups.append({ 'name': ng.name, 'count': int(count), 'node_group_template_id': ng.id }) plugins_versions.add((ng.plugin_name, ng.hadoop_version)) if len(plugins_versions) != 1: raise exceptions.CommandError('Node groups with the same plugins ' 'and versions must be specified') plugin, plugin_version = plugins_versions.pop() return plugin, plugin_version, node_groups
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}.\n'.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 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}.\n'.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 data = self._take_action(client, parsed_args) if parsed_args.count and parsed_args.count > 1: clusters = [] for cluster in data['clusters']: clusters.append( utils.get_resource(client.clusters, cluster['cluster']['id'])) 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(self.app, data) data = utils.prepare_data(data, c_v1.CLUSTER_FIELDS) return self.dict2columns(data)