コード例 #1
0
    def take_action(self, parsed_args):
        model, model_id = self.parse_model(parsed_args)
        params = {
            "owner_type": model,
            "owner_id": model_id,
            "role_name": parsed_args.name
        }

        file_path = self.get_file_path(parsed_args.directory, model, model_id,
                                       parsed_args.name, parsed_args.format)

        try:
            with open(file_path, 'r') as stream:
                data = data_utils.safe_load(parsed_args.format, stream)
                self.uploader(data, **params)
        except (OSError, IOError):
            msg = "Could not read description for role '{}' at {}".format(
                parsed_args.name, file_path)
            raise error.InvalidFileException(msg)

        msg = ("Description of role '{role}' for {owner} with id {id} was "
               "{action}d from {file_path}\n".format(role=parsed_args.name,
                                                     owner=model,
                                                     id=model_id,
                                                     action=self.action,
                                                     file_path=file_path))
        self.app.stdout.write(msg)
コード例 #2
0
    def test_safe_load_yaml(self):
        test_data = {'test_key': 'test_val'}

        m_open = mock.mock_open(read_data=yaml.dump(test_data))
        with mock.patch('fuelclient.tests.unit.common.test_utils.open',
                        m_open):
            stream = open('/a/random/file', 'r')
            loaded = data_utils.safe_load('yaml', stream)

        self.assertEqual(test_data, loaded)
コード例 #3
0
    def take_action(self, parsed_args):
        file_path = parsed_args.config

        config = dict()
        if file_path:
            file_format = os.path.splitext(file_path)[1].lstrip('.')
            try:
                with open(file_path, 'r') as stream:
                    config = data_utils.safe_load(file_format, stream)
            except (OSError, IOError):
                msg = 'Could not read configuration at {}.'
                raise error.InvalidFileException(msg.format(file_path))

        result = self.client.create_snapshot(config)

        msg = "Diagnostic snapshot generation task with id {id} was started\n"
        self.app.stdout.write(msg.format(id=result.id))
コード例 #4
0
    def take_action(self, parsed_args):
        directory = parsed_args.directory
        file_path = self.get_attributes_path(self.attribute,
                                             parsed_args.format,
                                             parsed_args.id, directory)
        try:
            with open(file_path, 'r') as stream:
                attribute = data_utils.safe_load(parsed_args.format, stream)
        except (IOError, OSError):
            msg = 'Could not read configuration of {} at {}.'
            raise error.InvalidFileException(
                msg.format(self.attribute, file_path))

        self.uploader(parsed_args.id, attribute)

        msg = ('Configuration of {t} for the environment with id '
               '{env} was loaded from {path}\n')

        self.app.stdout.write(
            msg.format(t=self.attribute, env=parsed_args.id, path=file_path))