Exemple #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)
    def _take_action(self, client, parsed_args):
        update_dict = utils.create_dict_from_kwargs(
            is_public=parsed_args.is_public,
            is_protected=parsed_args.is_protected)

        data = utils.update_job(client, self.app, parsed_args, update_dict)

        return data
Exemple #3
0
    def _take_action(self, client, parsed_args):
        update_dict = utils.create_dict_from_kwargs(
            is_public=parsed_args.is_public,
            is_protected=parsed_args.is_protected)

        data = utils.update_job(client, self.app, parsed_args, update_dict)

        return 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)
            if parsed_args.secret_key_prompt:
                parsed_args.secret_key = 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 parsed_args.access_key:
                extra['accesskey'] = parsed_args.access_key
            if parsed_args.secret_key:
                extra['secretkey'] = parsed_args.secret_key
            if parsed_args.s3_endpoint:
                extra['endpoint'] = parsed_args.s3_endpoint
            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)
Exemple #5
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)
            if parsed_args.secret_key_prompt:
                parsed_args.secret_key = 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 parsed_args.access_key:
                extra['accesskey'] = parsed_args.access_key
            if parsed_args.secret_key:
                extra['secretkey'] = parsed_args.secret_key
            if parsed_args.s3_endpoint:
                extra['endpoint'] = parsed_args.s3_endpoint
            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)
Exemple #6
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_job_template_id(self.app, client, parsed_args)

        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 = utils.update_job_templates(self.app, client, jt_id, update_data)

        _format_job_template_output(data)
        data = utils.prepare_data(data, JOB_TEMPLATE_FIELDS)

        return self.dict2columns(data)
Exemple #7
0
    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.type == 'swift':
            if parsed_args.username:
                credentials['user'] = parsed_args.username
            if parsed_args.password:
                credentials['password'] = parsed_args.password
        elif parsed_args.type == 's3':
            if parsed_args.access_key:
                credentials['accesskey'] = parsed_args.access_key
            if parsed_args.secret_key:
                credentials['secretkey'] = parsed_args.secret_key
            if parsed_args.s3_endpoint:
                credentials['endpoint'] = parsed_args.s3_endpoint
            if parsed_args.enable_s3_ssl == parsed_args.disable_s3_ssl:
                credentials['ssl'] = parsed_args.enable_s3_ssl
            if (parsed_args.enable_s3_bucket_in_path ==
                    parsed_args.disable_s3_bucket_in_path):
                credentials['bucket_in_path'] = (
                    parsed_args.enable_s3_bucket_in_path)
        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)
Exemple #8
0
    def _take_action(self, client, parsed_args):
        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 = jsonutils.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
        return data
    def _take_action(self, client, parsed_args):
        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 = jsonutils.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
        return data