def get_nuage_port_by_id(restproxy_serv, params): req_params = {'externalID': get_vsd_external_id(params['neutron_port_id'])} vport_type = params.get('nuage_vport_type') if vport_type == constants.HOST_VPORT_TYPE: req_params['vport_id'] = params['nuage_vport_id'] nuage_intf = nuagelib.NuageHostInterface(create_params=req_params) nuage_extra_headers = nuage_intf.extra_headers_by_externalid() else: nuage_intf = nuagelib.NuageVMInterface(create_params=req_params) nuage_extra_headers = nuage_intf.extra_headers_for_all_vmifs() response = restproxy_serv.rest_call('GET', nuage_intf.get_all_resource(), '', extra_headers=nuage_extra_headers) if not nuage_intf.validate(response): raise restproxy.RESTProxyError(nuage_intf.error_msg, nuage_intf.vsd_error_code) if len(response[3]) > 0: port = response[3][0] req_params = {'vport_id': port['VPortID']} nuage_vport = nuagelib.NuageVPort(create_params=req_params) vport_resp = restproxy_serv.rest_call('GET', nuage_vport.get_resource(), '') if not nuage_vport.validate(vport_resp): raise restproxy.RESTProxyError(nuage_vport.error_msg, nuage_vport.vsd_error_code) vport = vport_resp[3][0] vport['nuage_vif_id'] = port['ID'] return vport
def get_nuage_port_by_id(restproxy_serv, params): req_params = { 'externalID': get_vsd_external_id(params['neutron_port_id']) } vport_type = params.get('nuage_vport_type') if vport_type == constants.HOST_VPORT_TYPE: req_params['vport_id'] = params['nuage_vport_id'] nuage_intf = nuagelib.NuageHostInterface(create_params=req_params) nuage_extra_headers = nuage_intf.extra_headers_by_externalid() else: nuage_intf = nuagelib.NuageVMInterface(create_params=req_params) nuage_extra_headers = nuage_intf.extra_headers_for_all_vmifs() interfaces = restproxy_serv.get(nuage_intf.get_all_resource(), extra_headers=nuage_extra_headers, required=True) if interfaces: interface = interfaces[0] req_params = {'vport_id': interface['VPortID']} nuage_vport = nuagelib.NuageVPort(create_params=req_params) vport = restproxy_serv.get(nuage_vport.get_resource(), required=True)[0] vport['nuage_vif_id'] = interface['ID'] return vport return None
def get_nuage_vm_if_by_vport_id(self, vport_id): req_params = { 'vport_id': vport_id, } nuageif = nuagelib.NuageVMInterface(create_params=req_params) vm_interfaces = self.restproxy.get(nuageif.get_interface_for_vport()) if vm_interfaces: return vm_interfaces[0] else: return
def get_nuage_vm_interface_by_neutron_id(restproxy_serv, neutron_port_id): req_params = {'externalID': get_vsd_external_id(neutron_port_id)} nuage_intf = nuagelib.NuageVMInterface(create_params=req_params) nuage_extra_headers = nuage_intf.extra_headers_for_all_vmifs() interfaces = restproxy_serv.get(nuage_intf.get_all_resource(), extra_headers=nuage_extra_headers, required=True) return interfaces[0] if interfaces else None
def update_nuage_vm_if(self, params): req_params = { 'vport_id': params['nuage_vport_id'], } nuageif = nuagelib.NuageVMInterface(create_params=req_params) vm_interfaces = self.restproxy.get(nuageif.get_interface_for_vport()) if vm_interfaces: vm_interface = vm_interfaces[0] params = { 'id': vm_interface['ID'], 'mac': params['mac'], 'ipv4': params['ipv4'], 'ipv6': params['ipv6'] } updated_if = nuagelib.NuageVMInterface(create_params=params) utils.retry_on_vsdclient_error( self.restproxy.put, vsd_error_codes=[(constants.CONFLICT_ERR_CODE, constants.VSD_VPORT_ATTACHED_NET_ID_CHANGED)] )(updated_if.delete_resource(), updated_if.put_data())
def _delete_nuage_vm_if(self, params): LOG.debug("vsdclient._delete_nuage_vm_if() called") req_params = { 'id': params['nuage_vif_id'], } extra_params = { 'tenant': params['tenant'], 'net_partition_name': params['netpart_name'] } nuagevmif = nuagelib.NuageVMInterface(create_params=req_params, extra_params=extra_params) self.restproxy.delete(nuagevmif.delete_resource(), extra_headers=nuagevmif.extra_headers()) if (not params['portOnSharedSubn'] and (params['subn_tenant'] != params['tenant'])): self._delete_extra_perm_attached(params['tenant'], params.get('l2dom_id'), params.get('l3dom_id'))
def _create_nuage_vm_if(self, params): vm_id = self._get_nuage_vm(params) vsd_subnet = params['vsd_subnet'] req_params = { 'vm_id': vm_id, 'mac': params['mac'], 'ipv4': params['ipv4'], 'ipv6': params['ipv6'], 'externalID': get_vsd_external_id(params['port_id']) } extra_params = { 'tenant': params['tenant'], 'net_partition_name': params['netpart_name'] } if params.get('vport_id') and not params.get('attached_network'): req_params['vport_id'] = params.get('vport_id') elif params.get('attached_network'): req_params['attachedNetworkID'] = vsd_subnet['ID'] if vsd_subnet['type'] == constants.SUBNET: self._attach_reqd_perm_for_vm_boot(params, vsd_subnet['parentID'], on_l2=False) elif vsd_subnet['type'] == constants.L2DOMAIN: self._clear_vsd_unmanaged_l2_domain_vm_ip(vsd_subnet, req_params) self._attach_reqd_perm_for_vm_boot(params, vsd_subnet['ID'], on_l2=True) nuagevmif = nuagelib.NuageVMInterface(create_params=req_params, extra_params=extra_params) response = self.restproxy.post(nuagevmif.post_resource(), nuagevmif.post_data(), extra_headers=nuagevmif.extra_headers()) return { 'ip': nuagevmif.get_vmif_ip(response), 'vport_id': nuagevmif.get_vport_id(response), 'vif_id': nuagevmif.get_vif_id(response) }
def _delete_nuage_vm_if(self, params): LOG.debug("vsdclient._delete_nuage_vm_if() called") req_params = { 'id': params['nuage_vif_id'], } extra_params = { 'tenant': params['tenant'], 'net_partition_name': params['netpart_name'] } nuagevmif = nuagelib.NuageVMInterface(create_params=req_params, extra_params=extra_params) resp = self.restproxy.rest_call( 'DELETE', nuagevmif.delete_resource(), '', extra_headers=nuagevmif.extra_headers()) if not nuagevmif.delete_validate(resp): raise restproxy.RESTProxyError(nuagevmif.error_msg, nuagevmif.vsd_error_code) if (not params['portOnSharedSubn'] and (params['subn_tenant'] != params['tenant'])): self._delete_extra_perm_attached(params['tenant'], params.get('l2dom_id'), params.get('l3dom_id'))