Esempio n. 1
0
    def test_create_dict_from_kwargs(self):
        dict1 = utils.create_dict_from_kwargs(first='1', second=2)
        self.assertEqual({'first': '1', 'second': 2}, dict1)

        dict2 = utils.create_dict_from_kwargs(first='1', second=None)
        self.assertEqual({'first': '1'}, dict2)

        dict3 = utils.create_dict_from_kwargs(first='1', second=False)
        self.assertEqual({'first': '1', 'second': False}, dict3)
Esempio n. 2
0
    def test_create_dict_from_kwargs(self):
        dict1 = utils.create_dict_from_kwargs(first='1', second=2)
        self.assertEqual({'first': '1', 'second': 2}, dict1)

        dict2 = utils.create_dict_from_kwargs(first='1', second=None)
        self.assertEqual({'first': '1'}, dict2)

        dict3 = utils.create_dict_from_kwargs(first='1', second=False)
        self.assertEqual({'first': '1', 'second': False}, dict3)
    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)
Esempio n. 4
0
    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)
Esempio n. 6
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.data_processing

        update_dict = utils.create_dict_from_kwargs(
            is_public=parsed_args.is_public,
            is_protected=parsed_args.is_protected)

        data = client.job_executions.update(
            parsed_args.job, **update_dict).job_execution

        _format_job_output(data)
        data = utils.prepare_data(data, JOB_FIELDS)

        return self.dict2columns(data)
Esempio n. 7
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        client = self.app.client_manager.data_processing

        update_dict = utils.create_dict_from_kwargs(
            is_public=parsed_args.is_public,
            is_protected=parsed_args.is_protected)

        data = client.job_executions.update(parsed_args.job,
                                            **update_dict).job_execution

        _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

        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

        update_fields = utils.create_dict_from_kwargs(
            name=parsed_args.name,
            description=parsed_args.description,
            data_source_type=parsed_args.type, url=parsed_args.url,
            credential_user=parsed_args.username,
            credential_pass=parsed_args.password,
            is_public=parsed_args.is_public,
            is_protected=parsed_args.is_protected)

        ds_id = utils.get_resource(
            client.data_sources, parsed_args.data_source).id
        data = client.data_sources.update(ds_id, update_fields).data_source
        data = utils.prepare_data(data, DATA_SOURCE_FIELDS)

        return self.dict2columns(data)
Esempio n. 10
0
    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)
Esempio n. 12
0
    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)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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
            )

            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

        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)