Exemple #1
0
    def args2body(self, parsed_args):
        args = {'attributes': {}}
        body = {self.resource: args}
        # config arg passed as data overrides config yaml when both args passed
        config = None
        if parsed_args.config_file:
            with open(parsed_args.config_file) as f:
                config_yaml = f.read()
            try:
                config = yaml.load(config_yaml, Loader=yaml.SafeLoader)
            except yaml.YAMLError as e:
                raise exceptions.InvalidInput(e)

        if config:
            args['attributes']['config'] = config
        if parsed_args.vim_region_name:
            args.setdefault('placement_attr', {})['region_name'] = \
                parsed_args.vim_region_name

        apmec_client = self.get_client()
        apmec_client.format = parsed_args.request_format
        if parsed_args.vim_name:
            _id = apmecV10.find_resourceid_by_name_or_id(
                apmec_client, 'vim', parsed_args.vim_name)
            parsed_args.vim_id = _id
        if parsed_args.mead_name:
            _id = apmecV10.find_resourceid_by_name_or_id(
                apmec_client, 'mead', parsed_args.mead_name)
            parsed_args.mead_id = _id
        elif parsed_args.mead_template:
            with open(parsed_args.mead_template) as f:
                template = f.read()
            try:
                args['mead_template'] = yaml.load(template,
                                                  Loader=yaml.SafeLoader)
            except yaml.YAMLError as e:
                raise exceptions.InvalidInput(e)

        if parsed_args.param_file:
            with open(parsed_args.param_file) as f:
                param_yaml = f.read()
            try:
                args['attributes']['param_values'] = yaml.load(
                    param_yaml, Loader=yaml.SafeLoader)
            except yaml.YAMLError as e:
                raise exceptions.InvalidInput(e)
        apmecV10.update_dict(
            parsed_args, body[self.resource],
            ['tenant_id', 'name', 'description', 'mead_id', 'vim_id'])
        return body
 def args2body(self, parsed_args):
     body = {self.resource: {}}
     mead = None
     if not parsed_args.mead_file:
         raise exceptions.InvalidInput("Invalid input for mead file")
     with open(parsed_args.mead_file) as f:
         mead = f.read()
         try:
             mead = yaml.load(mead, Loader=yaml.SafeLoader)
         except yaml.YAMLError as e:
             raise exceptions.InvalidInput(e)
         if not mead:
             raise exceptions.InvalidInput("mead file is empty")
         body[self.resource]['attributes'] = {'mead': mead}
     apmecV10.update_dict(parsed_args, body[self.resource],
                          ['tenant_id', 'name', 'description'])
     return body
Exemple #3
0
    def args2body(self, parsed_args):
        args = {}
        body = {self.resource: args}

        apmec_client = self.get_client()
        apmec_client.format = parsed_args.request_format

        if parsed_args.mesd_template:
            with open(parsed_args.mesd_template) as f:
                template = f.read()
            try:
                args['mesd_template'] = yaml.load(template,
                                                  Loader=yaml.SafeLoader)
            except yaml.YAMLError as e:
                raise exceptions.InvalidInput(e)
            if not args['mesd_template']:
                raise exceptions.InvalidInput('The mesd template is empty')

        apmecV10.update_dict(parsed_args, body[self.resource], ['tenant_id'])
        return body
Exemple #4
0
 def args2body(self, parsed_args):
     body = {self.resource: {}}
     # config arg passed as data overrides config yaml when both args passed
     config = None
     if parsed_args.config_file:
         with open(parsed_args.config_file) as f:
             config_yaml = f.read()
         try:
             config = yaml.load(config_yaml, Loader=yaml.SafeLoader)
         except yaml.YAMLError as e:
             raise exceptions.InvalidInput(e)
     if parsed_args.config:
         config = parsed_args.config
         if isinstance(config, str) or isinstance(config, unicode):
             config_str = parsed_args.config.decode('unicode_escape')
             try:
                 config = yaml.load(config_str, Loader=yaml.SafeLoader)
             except yaml.YAMLError as e:
                 raise exceptions.InvalidInput(e)
     if config:
         body[self.resource]['attributes'] = {'config': config}
     apmecV10.update_dict(parsed_args, body[self.resource], ['tenant_id'])
     return body
Exemple #5
0
 def args2body(self, parsed_args):
     body = {self.resource: {}}
     config_param = None
     # config arg passed as data overrides config yaml when both args passed
     if parsed_args.config_file:
         with open(parsed_args.config_file) as f:
             config_yaml = f.read()
         try:
             config_param = yaml.load(config_yaml)
         except yaml.YAMLError as e:
             raise exceptions.InvalidInput(e)
     vim_obj = body[self.resource]
     if config_param is not None:
         vim_utils.args2body_vim(config_param, vim_obj)
     apmecV10.update_dict(parsed_args, body[self.resource],
                          ['tenant_id', 'name', 'description',
                           'is_default'])
     return body
Exemple #6
0
 def args2body(self, parsed_args):
     body = {self.resource: {}}
     if parsed_args.config_file:
         with open(parsed_args.config_file) as f:
             vim_config = f.read()
             try:
                 config_param = yaml.load(vim_config,
                                          Loader=yaml.SafeLoader)
             except yaml.YAMLError as e:
                 raise exceptions.InvalidInput(e)
     vim_obj = body[self.resource]
     try:
         auth_url = config_param.pop('auth_url')
     except KeyError:
         raise exceptions.ApmecClientException(message='Auth URL must be '
                                               'specified',
                                               status_code=404)
     vim_obj['auth_url'] = vim_utils.validate_auth_url(auth_url).geturl()
     vim_obj['type'] = config_param.pop('type', 'openstack')
     vim_utils.args2body_vim(config_param, vim_obj)
     apmecV10.update_dict(parsed_args, body[self.resource],
                          ['tenant_id', 'name', 'description',
                           'is_default'])
     return body