Exemple #1
0
    def update(self, plugin, context, vnf_id, vnf_dict, vnf,
               auth_attr):
        region_name = vnf_dict.get('placement_attr', {}).get(
            'region_name', None)
        heatclient = hc.HeatClient(auth_attr, region_name)
        heatclient.get(vnf_id)

        # update config attribute
        config_yaml = vnf_dict.get('attributes', {}).get('config', '')
        update_yaml = vnf['vnf'].get('attributes', {}).get('config', '')
        LOG.debug('yaml orig %(orig)s update %(update)s',
                  {'orig': config_yaml, 'update': update_yaml})

        # If config_yaml is None, yaml.safe_load() will raise Attribute Error.
        # So set config_yaml to {}, if it is None.
        if not config_yaml:
            config_dict = {}
        else:
            config_dict = yaml.safe_load(config_yaml) or {}
        update_dict = yaml.safe_load(update_yaml)
        if not update_dict:
            return

        LOG.debug('dict orig %(orig)s update %(update)s',
                  {'orig': config_dict, 'update': update_dict})
        utils.deep_update(config_dict, update_dict)
        LOG.debug('dict new %(new)s update %(update)s',
                  {'new': config_dict, 'update': update_dict})
        new_yaml = yaml.safe_dump(config_dict)
        vnf_dict.setdefault('attributes', {})['config'] = new_yaml
Exemple #2
0
    def update(self, plugin, context, vnf_id, vnf_dict, vnf, auth_attr):
        region_name = vnf_dict.get('placement_attr',
                                   {}).get('region_name', None)
        heatclient = hc.HeatClient(auth_attr, region_name)
        heatclient.get(vnf_id)

        # update config attribute
        config_yaml = vnf_dict.get('attributes', {}).get('config', '')
        update_yaml = vnf['vnf'].get('attributes', {}).get('config', '')
        LOG.debug('yaml orig %(orig)s update %(update)s', {
            'orig': config_yaml,
            'update': update_yaml
        })

        # If config_yaml is None, yaml.safe_load() will raise Attribute Error.
        # So set config_yaml to {}, if it is None.
        if not config_yaml:
            config_dict = {}
        else:
            config_dict = yaml.safe_load(config_yaml) or {}
        update_dict = yaml.safe_load(update_yaml)
        if not update_dict:
            return

        LOG.debug('dict orig %(orig)s update %(update)s', {
            'orig': config_dict,
            'update': update_dict
        })
        utils.deep_update(config_dict, update_dict)
        LOG.debug('dict new %(new)s update %(update)s', {
            'new': config_dict,
            'update': update_dict
        })
        new_yaml = yaml.safe_dump(config_dict)
        vnf_dict.setdefault('attributes', {})['config'] = new_yaml
    def update(self, plugin, context, vnf_id, vnf_dict, vnf, auth_attr):
        """Update containerized VNF through ConfigMap data

        In Kubernetes VIM, updating VNF will be updated by updating
        ConfigMap data
        """
        # initialize Kubernetes APIs
        auth_cred, file_descriptor = self._get_auth_creds(auth_attr)
        try:
            core_v1_api_client = \
                self.kubernetes.get_core_v1_api_client(auth=auth_cred)

            # update config attribute
            config_yaml = vnf_dict.get('attributes', {}).get('config', '')
            update_yaml = vnf['vnf'].get('attributes', {}).get('config', '')
            LOG.debug('yaml orig %(orig)s update %(update)s',
                      {'orig': config_yaml, 'update': update_yaml})
            # If config_yaml is None, yaml.safe_load() will raise Attribute
            # Error. So set config_yaml to {}, if it is None.
            if not config_yaml:
                config_dict = {}
            else:
                config_dict = yaml.safe_load(config_yaml) or {}
            update_dict = yaml.safe_load(update_yaml)
            if not update_dict:
                return
            LOG.debug('dict orig %(orig)s update %(update)s',
                      {'orig': config_dict, 'update': update_dict})
            utils.deep_update(config_dict, update_dict)
            LOG.debug('dict new %(new)s update %(update)s',
                      {'new': config_dict, 'update': update_dict})
            new_yaml = yaml.safe_dump(config_dict)
            vnf_dict.setdefault('attributes', {})['config'] = new_yaml

            deployment_info = vnf_id.split(",")
            for i in range(0, len(deployment_info), 2):
                namespace = deployment_info[i]
                deployment_name = deployment_info[i + 1]
                configmap_resp = core_v1_api_client.read_namespaced_config_map(
                    namespace=namespace,
                    name=deployment_name)
                configmap_data = configmap_resp.data
                new_configmap = {key: update_dict.get(key, configmap_data[key])
                                 for key in configmap_data}
                configmap_resp.data = new_configmap
                core_v1_api_client.\
                    patch_namespaced_config_map(namespace=namespace,
                                                name=deployment_name,
                                                body=configmap_resp)
        except Exception as e:
            LOG.error('Updating VNF got an error due to %s', e)
            raise
        finally:
            self.clean_authenticate_vim(auth_cred, file_descriptor)
 def update_vim(self, context, vim_id, vim):
     vim_obj = self._get_vim(context, vim_id)
     utils.deep_update(vim_obj, vim['vim'])
     vim_type = vim_obj['type']
     try:
         self._vim_drivers.invoke(vim_type, 'register_vim', vim_obj=vim_obj)
         return super(NfvoPlugin, self).update_vim(context, vim_id, vim_obj)
     except Exception:
         with excutils.save_and_reraise_exception():
             self._vim_drivers.invoke(vim_type, 'delete_vim_auth',
                                      vim_id=vim_obj['id'])
Exemple #5
0
 def update_vim(self, context, vim_id, vim):
     vim_obj = self._get_vim(context, vim_id)
     utils.deep_update(vim_obj, vim['vim'])
     vim_type = vim_obj['type']
     try:
         self._vim_drivers.invoke(vim_type, 'register_vim', vim_obj=vim_obj)
         return super(NfvoPlugin, self).update_vim(context, vim_id, vim_obj)
     except Exception:
         with excutils.save_and_reraise_exception():
             self._vim_drivers.invoke(vim_type, 'delete_vim_auth',
                                      vim_id=vim_obj['id'])
    def update(self, plugin, context, vnf_id, vnf_dict, vnf, auth_attr):
        """Update containerized VNF through ConfigMap data

        In Kubernetes VIM, updating VNF will be updated by updating
        ConfigMap data
        """
        # initialize Kubernetes APIs
        auth_cred, file_descriptor = self._get_auth_creds(auth_attr)
        try:
            core_v1_api_client = \
                self.kubernetes.get_core_v1_api_client(auth=auth_cred)

            # update config attribute
            config_yaml = vnf_dict.get('attributes', {}).get('config', '')
            update_yaml = vnf['vnf'].get('attributes', {}).get('config', '')
            LOG.debug('yaml orig %(orig)s update %(update)s',
                      {'orig': config_yaml, 'update': update_yaml})
            # If config_yaml is None, yaml.safe_load() will raise Attribute
            # Error. So set config_yaml to {}, if it is None.
            if not config_yaml:
                config_dict = {}
            else:
                config_dict = yaml.safe_load(config_yaml) or {}
            update_dict = yaml.safe_load(update_yaml)
            if not update_dict:
                return
            LOG.debug('dict orig %(orig)s update %(update)s',
                      {'orig': config_dict, 'update': update_dict})
            utils.deep_update(config_dict, update_dict)
            LOG.debug('dict new %(new)s update %(update)s',
                      {'new': config_dict, 'update': update_dict})
            new_yaml = yaml.safe_dump(config_dict)
            vnf_dict.setdefault('attributes', {})['config'] = new_yaml

            deployment_info = vnf_id.split(",")
            for i in range(0, len(deployment_info), 2):
                namespace = deployment_info[i]
                deployment_name = deployment_info[i + 1]
                configmap_resp = core_v1_api_client.read_namespaced_config_map(
                    namespace=namespace,
                    name=deployment_name)
                configmap_data = configmap_resp.data
                new_configmap = {key: update_dict.get(key, configmap_data[key])
                                 for key in configmap_data}
                configmap_resp.data = new_configmap
                core_v1_api_client.\
                    patch_namespaced_config_map(namespace=namespace,
                                                name=deployment_name,
                                                body=configmap_resp)
        except Exception as e:
            LOG.error('Updating VNF got an error due to %s', e)
            raise
        finally:
            self.clean_authenticate_vim(auth_cred, file_descriptor)
Exemple #7
0
    def update_vim(self, context, vim_id, vim):
        vim_obj = self._get_vim(context, vim_id)
        old_vim_obj = copy.deepcopy(vim_obj)
        utils.deep_update(vim_obj, vim['vim'])
        vim_type = vim_obj['type']
        update_args = vim['vim']
        old_auth_need_delete = False
        new_auth_created = False
        try:
            # re-register the VIM only if there is a change in password.
            # auth_url of auth_cred is from vim object which
            # is not updatable. so no need to consider it
            if 'auth_cred' in update_args:
                auth_cred = update_args['auth_cred']
                if 'password' in auth_cred:
                    vim_obj['auth_cred']['password'] = auth_cred['password']
                    # Notice: vim_obj may be updated in vim driver's
                    self._vim_drivers.invoke(vim_type,
                                             'register_vim',
                                             context=context,
                                             vim_obj=vim_obj)
                    new_auth_created = True

                    # Check whether old vim's auth need to be deleted
                    old_key_type = old_vim_obj['auth_cred'].get('key_type')
                    if old_key_type == 'barbican_key':
                        old_auth_need_delete = True

            vim_obj = super(NfvoPlugin,
                            self).update_vim(context, vim_id, vim_obj)
            if old_auth_need_delete:
                try:
                    self._vim_drivers.invoke(vim_type,
                                             'delete_vim_auth',
                                             context=context,
                                             vim_id=old_vim_obj['id'],
                                             auth=old_vim_obj['auth_cred'])
                except Exception as ex:
                    LOG.warning("Fail to delete old auth for vim %s due to %s",
                                vim_id, ex)
            return vim_obj
        except Exception as ex:
            LOG.debug("Got exception when update_vim %s due to %s", vim_id, ex)
            with excutils.save_and_reraise_exception():
                if new_auth_created:
                    # delete new-created vim auth, old auth is still used.
                    self._vim_drivers.invoke(vim_type,
                                             'delete_vim_auth',
                                             context=context,
                                             vim_id=vim_obj['id'],
                                             auth=vim_obj['auth_cred'])
Exemple #8
0
 def update_vim(self, context, vim_id, vim):
     vim_obj = self._get_vim(context, vim_id)
     utils.deep_update(vim_obj, vim['vim'])
     vim_type = vim_obj['type']
     update_args = vim['vim']
     try:
         # re-register the VIM only if there is a change in password.
         # auth_url of auth_cred is from vim object which
         # is not updatable. so no need to consider it
         if 'auth_cred' in update_args:
             auth_cred = update_args['auth_cred']
             if 'password' in auth_cred:
                 vim_obj['auth_cred']['password'] = auth_cred['password']
                 # Notice: vim_obj may be updated in vim driver's
                 # register_vim method
                 self._vim_drivers.invoke(vim_type, 'register_vim',
                                          vim_obj=vim_obj)
         return super(NfvoPlugin, self).update_vim(context, vim_id, vim_obj)
     except Exception:
         with excutils.save_and_reraise_exception():
             self._vim_drivers.invoke(vim_type, 'delete_vim_auth',
                                      vim_id=vim_obj['id'])
Exemple #9
0
    def update_vim(self, context, vim_id, vim):
        vim_obj = self._get_vim(context, vim_id)
        old_vim_obj = copy.deepcopy(vim_obj)
        utils.deep_update(vim_obj, vim['vim'])
        vim_type = vim_obj['type']
        update_args = vim['vim']
        old_auth_need_delete = False
        new_auth_created = False
        try:
            # re-register the VIM only if there is a change in bearer_token,
            # username, password or bearer_token.
            # auth_url of auth_cred is from vim object which
            # is not updatable. so no need to consider it
            if 'auth_cred' in update_args:
                auth_cred = update_args['auth_cred']
                if ('username' in auth_cred) and ('password' in auth_cred)\
                        and (auth_cred['password'] is not None):
                    # update new username and password, remove bearer_token
                    # if it exists in the old vim
                    vim_obj['auth_cred']['username'] = auth_cred['username']
                    vim_obj['auth_cred']['password'] = auth_cred['password']
                    if 'bearer_token' in vim_obj['auth_cred']:
                        vim_obj['auth_cred'].pop('bearer_token')
                elif 'bearer_token' in auth_cred:
                    # update bearer_token, remove username and password
                    # if they exist in the old vim
                    vim_obj['auth_cred']['bearer_token'] =\
                        auth_cred['bearer_token']
                    if ('username' in vim_obj['auth_cred']) and\
                            ('password' in vim_obj['auth_cred']):
                        vim_obj['auth_cred'].pop('username')
                        vim_obj['auth_cred'].pop('password')
                if 'ssl_ca_cert' in auth_cred:
                    # update new ssl_ca_cert
                    vim_obj['auth_cred']['ssl_ca_cert'] =\
                        auth_cred['ssl_ca_cert']
                # Notice: vim_obj may be updated in vim driver's
                self._vim_drivers.invoke(vim_type,
                                         'register_vim',
                                         vim_obj=vim_obj)
                new_auth_created = True

                # Check whether old vim's auth need to be deleted
                old_key_type = old_vim_obj['auth_cred'].get('key_type')
                if old_key_type == 'barbican_key':
                    old_auth_need_delete = True

            vim_obj = super(NfvoPlugin,
                            self).update_vim(context, vim_id, vim_obj)
            if old_auth_need_delete:
                try:
                    self._vim_drivers.invoke(vim_type,
                                             'delete_vim_auth',
                                             vim_id=old_vim_obj['id'],
                                             auth=old_vim_obj['auth_cred'])
                except Exception as ex:
                    LOG.warning("Fail to delete old auth for vim %s due to %s",
                                vim_id, ex)
            return vim_obj
        except Exception as ex:
            LOG.debug("Got exception when update_vim %s due to %s", vim_id, ex)
            with excutils.save_and_reraise_exception():
                if new_auth_created:
                    # delete new-created vim auth, old auth is still used.
                    self._vim_drivers.invoke(vim_type,
                                             'delete_vim_auth',
                                             vim_id=vim_obj['id'],
                                             auth=vim_obj['auth_cred'])
Exemple #10
0
    def update(self, plugin, context, vnf_id, vnf_dict, vnf, auth_attr):
        region_name = vnf_dict.get('placement_attr',
                                   {}).get('region_name', None)
        heatclient = hc.HeatClient(auth_attr, region_name)
        heatclient.get(vnf_id)

        update_param_yaml = vnf['vnf'].get('attributes',
                                           {}).get('param_values', '')
        update_config_yaml = vnf['vnf'].get('attributes', {}).get('config', '')

        if update_param_yaml:
            # conversion param_values
            param_yaml = vnf_dict.get('attributes', {}).get('param_values', '')
            param_dict = yaml.safe_load(param_yaml)
            update_param_dict = yaml.safe_load(update_param_yaml)

            # check update values
            update_values = {}
            for key, value in update_param_dict.items():
                if key not in param_dict or\
                        update_param_dict[key] != param_dict[key]:
                    update_values[key] = value

            if not update_values:
                error_reason = _("at vnf_id {} because all parameters "
                                 "match the existing one.").format(vnf_id)
                LOG.warning(error_reason)
                raise vnfm.VNFUpdateInvalidInput(reason=error_reason)

            # update vnf_dict
            utils.deep_update(param_dict, update_param_dict)
            new_param_yaml = yaml.safe_dump(param_dict)
            vnf_dict.setdefault('attributes',
                                {})['param_values'] = new_param_yaml

            # run stack update
            stack_update_param = {
                'parameters': update_values,
                'existing': True
            }
            heatclient.update(vnf_id, **stack_update_param)

        elif not update_param_yaml and not update_config_yaml:
            error_reason = _("at vnf_id {} because the target "
                             "yaml is empty.").format(vnf_id)
            LOG.warning(error_reason)
            raise vnfm.VNFUpdateInvalidInput(reason=error_reason)

        # update config attribute
        config_yaml = vnf_dict.get('attributes', {}).get('config', '')
        LOG.debug('yaml orig %(orig)s update %(update)s', {
            'orig': config_yaml,
            'update': update_config_yaml
        })

        # If config_yaml is None, yaml.safe_load() will raise Attribute Error.
        # So set config_yaml to {}, if it is None.
        if not config_yaml:
            config_dict = {}
        else:
            config_dict = yaml.safe_load(config_yaml) or {}
        update_dict = yaml.safe_load(update_config_yaml)
        if not update_dict:
            return

        LOG.debug('dict orig %(orig)s update %(update)s', {
            'orig': config_dict,
            'update': update_dict
        })
        utils.deep_update(config_dict, update_dict)
        LOG.debug('dict new %(new)s update %(update)s', {
            'new': config_dict,
            'update': update_dict
        })
        new_yaml = yaml.safe_dump(config_dict)
        vnf_dict.setdefault('attributes', {})['config'] = new_yaml
Exemple #11
0
    def update_vim(self, context, vim_id, vim):
        vim_obj = self._get_vim(context, vim_id)
        old_vim_obj = copy.deepcopy(vim_obj)
        utils.deep_update(vim_obj, vim['vim'])
        vim_type = vim_obj['type']
        update_args = vim['vim']
        old_auth_need_delete = False
        new_auth_created = False
        try:
            # re-register the VIM only if there is a change in bearer_token,
            # username, password or bearer_token.
            # auth_url of auth_cred is from vim object which
            # is not updatable. so no need to consider it
            if 'auth_cred' in update_args:
                auth_cred = update_args['auth_cred']
                if ('username' in auth_cred) and ('password' in auth_cred)\
                        and (auth_cred['password'] is not None):
                    # update new username and password, remove bearer_token
                    # if it exists in the old vim
                    vim_obj['auth_cred']['username'] = auth_cred['username']
                    vim_obj['auth_cred']['password'] = auth_cred['password']
                    if 'bearer_token' in vim_obj['auth_cred']:
                        vim_obj['auth_cred'].pop('bearer_token')
                elif 'bearer_token' in auth_cred:
                    # update bearer_token, remove username and password
                    # if they exist in the old vim
                    vim_obj['auth_cred']['bearer_token'] =\
                        auth_cred['bearer_token']
                    if ('username' in vim_obj['auth_cred']) and\
                            ('password' in vim_obj['auth_cred']):
                        vim_obj['auth_cred'].pop('username')
                        vim_obj['auth_cred'].pop('password')
                if 'ssl_ca_cert' in auth_cred:
                    # update new ssl_ca_cert
                    vim_obj['auth_cred']['ssl_ca_cert'] =\
                        auth_cred['ssl_ca_cert']
                # Notice: vim_obj may be updated in vim driver's
                self._vim_drivers.invoke(vim_type,
                                         'register_vim',
                                         vim_obj=vim_obj)
                new_auth_created = True

                # Check whether old vim's auth need to be deleted
                old_key_type = old_vim_obj['auth_cred'].get('key_type')
                if old_key_type == 'barbican_key':
                    old_auth_need_delete = True

            vim_obj = super(NfvoPlugin, self).update_vim(
                context, vim_id, vim_obj)
            if old_auth_need_delete:
                try:
                    self._vim_drivers.invoke(vim_type,
                                             'delete_vim_auth',
                                             vim_id=old_vim_obj['id'],
                                             auth=old_vim_obj['auth_cred'])
                except Exception as ex:
                    LOG.warning("Fail to delete old auth for vim %s due to %s",
                                vim_id, ex)
            return vim_obj
        except Exception as ex:
            LOG.debug("Got exception when update_vim %s due to %s",
                      vim_id, ex)
            with excutils.save_and_reraise_exception():
                if new_auth_created:
                    # delete new-created vim auth, old auth is still used.
                    self._vim_drivers.invoke(vim_type,
                                             'delete_vim_auth',
                                             vim_id=vim_obj['id'],
                                             auth=vim_obj['auth_cred'])