def port_chain_update(self, port_chain_id, port_chain): try: pc = self.client.update_port_chain(port_chain_id, {'port_chain': port_chain}) except nc_exceptions.BadRequest as e: LOG.warning('update port chain returns %s', e) raise ValueError(str(e)) if pc and len(pc): return pc['port_chain']['id'] else: raise nfvo.UpdateChainException(message="Failed to update " "port-chain")
def heal_chain(self, chain_id, vnf, new_cp_list, symmetrical=None, auth_attr=None): if not auth_attr: LOG.warning("auth information required for n-sfc driver") return None neutronclient_ = NeutronClient(auth_attr) port_pairs_list = neutronclient_.port_pair_list() port_pair_groups_list = neutronclient_.port_pair_group_list() port_chains_list = neutronclient_.port_chain_list() pc_info = neutronclient_.port_chain_show(chain_id) old_ppgs = pc_info['port_chain']['port_pair_groups'] old_ppgs_dict = {neutronclient_.port_pair_group_show(ppg_id) ['port_pair_group']['name'].split('-')[0]: \ ppg_id for ppg_id in old_ppgs} # Find old_ppg_id if vnf['name'] in old_ppgs_dict: old_ppg_id = old_ppgs_dict[vnf['name']] # Find old_pp for port_pair in port_pairs_list['port_pairs']: if vnf['name'] == port_pair['name'].split('-')[0]: old_port_pair_id = port_pair['id'] # Create new port-pair num_cps = len(new_cp_list) if num_cps not in [1, 2]: LOG.warning( "Failed due to wrong number " "of connection points: expected [1 | 2]," "got %(cps)d", {'cps': num_cps}) raise nfvo.UpdateChainException( message="Invalid number of connection points") if num_cps == 1: ingress = new_cp_list[0] egress = new_cp_list[0] else: ingress = new_cp_list[0] egress = new_cp_list[1] port_pair = {} port_pair['name'] = vnf['name'] + '-respawned-connection-points' port_pair['description'] = 'port pair for ' + vnf['name'] port_pair['ingress'] = ingress port_pair['egress'] = egress port_pair_id = neutronclient_.port_pair_create(port_pair) LOG.info('log: port_pair_id : %s', port_pair) LOG.info('log: port_pair_id : %s', port_pair_id) # Append new port-pair to port-pair-group updated_ppg = {} updated_ppg['name'] = vnf['name'] + '-port-pair-group' updated_ppg[ 'description'] = 'respawned port pair group for ' + vnf['name'] updated_ppg['port_pairs'] = [] updated_ppg['port_pairs'].append(port_pair_id) ppg = neutronclient_.port_pair_group_update(ppg_id=old_ppg_id, ppg_dict=updated_ppg) # Delete old_port_pair neutronclient_.port_pair_delete(old_port_pair_id) return ppg
def update_chain(self, chain_id, fc_ids, vnfs, symmetrical=None, auth_attr=None): # (s3wong): chain can be updated either for # the list of fc and/or list of port-pair-group # since n-sfc driver does NOT track the ppg id # it will look it up (or reconstruct) from # networking-sfc DB --- but the caveat is that # the VNF name MUST be unique # TODO(mardim) Currently we figure out which VNF belongs to what # port-pair-group or port-pair through the name of VNF. # This is not the best approach. The best approach for the future # propably is to maintain in the database the ID of the # port-pair-group and port-pair that VNF belongs to so we can # implemement the update in a more robust way. if not auth_attr: LOG.warning("auth information required for n-sfc driver") return None neutronclient_ = NeutronClient(auth_attr) new_ppgs = [] updated_port_chain = dict() pc_info = neutronclient_.port_chain_show(chain_id) old_ppgs = pc_info['port_chain']['port_pair_groups'] old_ppgs_dict = { neutronclient_.port_pair_group_show(ppg_id)['port_pair_group'] ['name'].split('-')[0]: ppg_id for ppg_id in old_ppgs } past_ppgs_dict = old_ppgs_dict.copy() try: for vnf in vnfs: port_pair_group = {} port_pair = {} if vnf['name'] in old_ppgs_dict: old_ppg_id = old_ppgs_dict.pop(vnf['name']) new_ppgs.append(old_ppg_id) else: port_pair_group['name'] = vnf['name'] + '-port-pair-group' port_pair_group['description'] = \ 'port pair group for %s' % vnf['name'] port_pair_group['port_pairs'] = [] if CONNECTION_POINT not in vnf: LOG.warning( "Chain update failed due to missing " "connection point info in VNF " "%(vnfname)s", {'vnfname': vnf['name']}) raise nfvo.UpdateChainException( message="Connection point not found") cp_list = vnf[CONNECTION_POINT] num_cps = len(cp_list) if num_cps != 1 and num_cps != 2: LOG.warning( "Chain update failed due to wrong number " "of connection points: expected [1 | 2]," "got %(cps)d", {'cps': num_cps}) raise nfvo.UpdateChainException( message="Invalid number of connection points") port_pair['name'] = vnf['name'] + '-connection-points' port_pair['description'] = 'port pair for %s' % vnf['name'] if num_cps == 1: port_pair['ingress'] = cp_list[0] port_pair['egress'] = cp_list[0] else: port_pair['ingress'] = cp_list[0] port_pair['egress'] = cp_list[1] port_pair_id = neutronclient_.port_pair_create(port_pair) if not port_pair_id: LOG.warning( "Chain update failed due to port pair " "creation failed for " "vnf %(vnf)s", {'vnf': vnf['name']}) raise nfvo.UpdateChainException( message="Failed to create port-pair") port_pair_group['port_pairs'].append(port_pair_id) port_pair_group_id = \ neutronclient_.port_pair_group_create(port_pair_group) if not port_pair_group_id: LOG.warning( "Chain update failed due to port pair " "group creation failed for vnf " "%(vnf)s", {'vnf': vnf['name']}) for pp_id in port_pair_group['port_pairs']: neutronclient_.port_pair_delete(pp_id) raise nfvo.UpdateChainException( message="Failed to create port-pair-group") new_ppgs.append(port_pair_group_id) except nfvo.UpdateChainException as e: self._delete_ppgs_and_pps(neutronclient_, new_ppgs, past_ppgs_dict) raise e updated_port_chain['port_pair_groups'] = new_ppgs try: pc_id = neutronclient_.port_chain_update(chain_id, updated_port_chain) except (nc_exceptions.BadRequest, nfvo.UpdateChainException) as e: self._delete_ppgs_and_pps(neutronclient_, new_ppgs, past_ppgs_dict) raise e for ppg_name in old_ppgs_dict: ppg_info = neutronclient_. \ port_pair_group_show(old_ppgs_dict[ppg_name]) neutronclient_.port_pair_group_delete(old_ppgs_dict[ppg_name]) port_pairs = ppg_info['port_pair_group']['port_pairs'] if port_pairs and len(port_pairs): for j in xrange(0, len(port_pairs)): pp_id = port_pairs[j] neutronclient_.port_pair_delete(pp_id) return pc_id
def scale_chain(self, chain_id, vnf, symmetrical=None, auth_attr=None): # chain_id = asdf1234 # vnf = {“name” : VNF1_name, “CONNECTION_POINT” : CP,} if not auth_attr: LOG.warning("auth information required for n-sfc driver") return None neutronclient_ = NeutronClient(auth_attr) port_pairs_list = neutronclient_.port_pair_list() port_pair_groups_list = neutronclient_.port_pair_group_list() port_chains_list = neutronclient_.port_chain_list() new_ppgs = [] updated_port_chain = dict() pc_info = neutronclient_.port_chain_show(chain_id) # Get port_chain_info from chain_id old_ppgs = pc_info['port_chain']['port_pair_groups'] # old_ppgs = ["ppg_id1", "ppg_id2"] old_ppgs_dict = {neutronclient_.port_pair_group_show(ppg_id) ['port_pair_group']['name'].split('-')[0]: \ ppg_id for ppg_id in old_ppgs} # old_ppgs_dict = {VNF1 : ppg_id1, VNF2 : ppg_id2} try: if vnf['name'] in old_ppgs_dict: updating_ppg_id = old_ppgs_dict[vnf['name']] # updating_ppg_id = "ppg_id" updating_ppg_dict = neutronclient_.port_pair_group_show( updating_ppg_id) #TODO: CONNECTION_POINT = manual typing cp_list = vnf[CONNECTION_POINT] num_cps = len(cp_list) if num_cps not in [1, 2]: LOG.warning( "Chain update failed due to wrong number " "of connection points: expected [1 | 2]," "got %(cps)d", {'cps': num_cps}) raise nfvo.UpdateChainException( message="Invalid number of connection points") if num_cps == 1: ingress = cp_list[0] egress = cp_list[0] else: ingress = cp_list[0] egress = cp_list[1] port_pair = {} port_pair[ 'name'] = vnf['name'] + '-connection-points-scaled-out' port_pair[ 'description'] = 'scaled-out port pair for' + vnf['name'] port_pair['ingress'] = ingress port_pair['egress'] = egress port_pair_id = neutronclient_.port_pair_create(port_pair) updating_ppg_dict['port_pairs'].append(port_pair_id) updated_ppg = neutronclient_.port_pair_group_update( ppg_id=updating_ppg_id, ppg_dict=updating_ppg_dict) # call port_pair_group_update method return updated_ppg else: raise nfvo.UpdateChainException( message="The VNF is not included in the chain") except nfvo.UpdateChainException as e: raise e