def _contrail_create_port(self): if not self.project_obj: self.project_obj = self.vnc_api_h.project_read(id=self.project_id) vmi_id = str(uuid.uuid4()) vmi_obj = vnc_api_test.VirtualMachineInterface( name=vmi_id, parent_obj=self.project_obj) if self.mac_address: mac_address_obj = vnc_api_test.MacAddressesType() mac_address_obj.set_mac_address([str(EUI(self.mac_address))]) vmi_obj.set_virtual_machine_interface_mac_addresses( mac_address_obj) vmi_obj.uuid = vmi_id vmi_obj.add_virtual_network(self.vn_obj) if self.security_groups: for sg_id in self.security_groups: sg_obj = self.vnc_api_h.security_group_read(id=sg_id) vmi_obj.add_security_group(sg_obj) else: # Associate default SG default_sg_fq_name = self.project_obj.fq_name[:] default_sg_fq_name.append('default') sg_obj = self.vnc_api_h.security_group_read( fq_name=default_sg_fq_name) vmi_obj.add_security_group(sg_obj) if self.extra_dhcp_opts: # TODO pass if self.binding_profile: bind_kv = vnc_api_test.KeyValuePair(key='profile', value=str( self.binding_profile)) kv_pairs = vmi_obj.get_virtual_machine_interface_bindings() or\ vnc_api_test.KeyValuePairs() kv_pairs.add_key_value_pair(bind_kv) vmi_obj.set_virtual_machine_interface_bindings(kv_pairs) self.vmi_obj = self.vnc_api_h.virtual_machine_interface_create(vmi_obj) self.uuid = vmi_id if self.fixed_ips: for fixed_ip in self.fixed_ips: iip_id = str(uuid.uuid4()) iip_obj = vnc_api_test.InstanceIp( name=iip_id, subnet_id=fixed_ip['subnet_id']) iip_obj.uuid = iip_id iip_obj.add_virtual_machine_interface(vmi_obj) iip_obj.add_virtual_network(self.vn_obj) iip_obj.set_instance_ip_address(fixed_ip['ip_address']) self.vnc_api_h.instance_ip_create(iip_obj) else: iip_id = str(uuid.uuid4()) iip_obj = vnc_api_test.InstanceIp(name=iip_id) iip_obj.uuid = iip_id iip_obj.add_virtual_machine_interface(vmi_obj) iip_obj.add_virtual_network(self.vn_obj) self.vnc_api_h.instance_ip_create(iip_obj)
def _contrail_create_port(self): vmi_props = vnc_api_test.VirtualMachineInterfacePropertiesType() if not self.project_obj: self.project_obj = self.vnc_api_h.project_read(id=self.project_id) vmi_id = str(uuid.uuid4()) vmi_obj = vnc_api_test.VirtualMachineInterface(name=self.name, parent_obj=self.project_obj) if self.mac_address: mac_address_obj = vnc_api_test.MacAddressesType() mac_address_obj.set_mac_address([str(EUI(self.mac_address))]) vmi_obj.set_virtual_machine_interface_mac_addresses( mac_address_obj) vmi_obj.uuid = vmi_id vmi_obj.add_virtual_network(self.vn_obj) if self.security_groups: for sg_id in self.security_groups: sg_obj = self.vnc_api_h.security_group_read(id=sg_id) vmi_obj.add_security_group(sg_obj) else: # Associate default SG default_sg_fq_name = self.project_obj.fq_name[:] default_sg_fq_name.append('default') sg_obj = self.vnc_api_h.security_group_read( fq_name=default_sg_fq_name) vmi_obj.add_security_group(sg_obj) if self.extra_dhcp_opts: # TODO pass if self.vlan_id is not None: vmi_props.set_sub_interface_vlan_tag(int(self.vlan_id)) if self.parent_vmi: vmi_obj.add_virtual_machine_interface(self.parent_vmi) if self.device_owner: vmi_obj.set_virtual_machine_interface_device_owner(self.device_owner) if self.binding_profile: bind_kv = vnc_api_test.KeyValuePair(key='profile', value=json.dumps(self.binding_profile)) kv_pairs = vmi_obj.get_virtual_machine_interface_bindings() or\ vnc_api_test.KeyValuePairs() kv_pairs.add_key_value_pair(bind_kv) if 'local_link_information' in self.binding_profile: vnic_kv = vnc_api_test.KeyValuePair(key='vnic_type', value='baremetal') kv_pairs.add_key_value_pair(vnic_kv) vmi_obj.set_virtual_machine_interface_device_owner("baremetal:None") vmi_obj.set_virtual_machine_interface_bindings(kv_pairs) vmi_obj.set_virtual_machine_interface_properties(vmi_props) self.vmi_obj = self.vnc_api_h.virtual_machine_interface_create(vmi_obj) self.uuid = vmi_id self.iip_objs = [] if self.create_iip == False: return if self.fixed_ips: for fixed_ip in self.fixed_ips: iip_id = str(uuid.uuid4()) iip_obj = vnc_api_test.InstanceIp(name=iip_id, subnet_id=fixed_ip['subnet_id']) iip_obj.uuid = iip_id iip_obj.add_virtual_machine_interface(vmi_obj) iip_obj.add_virtual_network(self.vn_obj) if fixed_ip.get("ip_address", None): iip_obj.set_instance_ip_address(fixed_ip['ip_address']) if fixed_ip.get("instance_ip_secondary", False): iip_obj.instance_ip_secondary = True id = self.vnc_api_h.instance_ip_create(iip_obj) iip_obj = self.vnc_api_h.instance_ip_read(id=id) self.iip_objs.append(iip_obj) else: iip_id = str(uuid.uuid4()) iip_obj = vnc_api_test.InstanceIp(name=iip_id) iip_obj.uuid = iip_id iip_obj.add_virtual_machine_interface(vmi_obj) iip_obj.add_virtual_network(self.vn_obj) self.vnc_api_h.instance_ip_create(iip_obj) if self.af in ['v6', 'dual']: iip_id2 = str(uuid.uuid4()) iip_obj2 = vnc_api_test.InstanceIp(name=iip_id2, instance_ip_family='v6') iip_obj2.uuid = iip_id2 iip_obj2.add_virtual_machine_interface(vmi_obj) iip_obj2.add_virtual_network(self.vn_obj) self.vnc_api_h.instance_ip_create(iip_obj2)