Ejemplo n.º 1
0
    def handle_create(self):
        tenant_id = self.stack.context.tenant_id
        project_obj = self.vnc_lib().project_read(id=str(uuid.UUID(tenant_id)))
        try:
            si_obj = self.vnc_lib().service_instance_read(
                id=self.properties[self.SERVICE_INSTANCE])
        except vnc_api.NoIdError:
            si_name = project_obj.fq_name + \
                [self.properties[self.SERVICE_INSTANCE]]
            si_obj = self.vnc_lib().service_instance_read(fq_name=si_name)

        pt_obj = vnc_api.PortTuple(
            name=self.properties[self.NAME], parent_obj=si_obj)
        try:
            pt_uuid = self.vnc_lib().port_tuple_create(pt_obj)
        except vnc_api.RefsExistError:
            pt_obj = self.vnc_lib().port_tuple_read(fq_name=pt_obj.fq_name)
            pt_uuid = pt_obj.uuid

        st_uuid = si_obj.get_service_template_refs()[0]['uuid']
        st_obj = self.vnc_lib().service_template_read(id=st_uuid)
        st_props = st_obj.get_service_template_properties()
        if_list = st_props.get_interface_type()
        for index in range(0, len(if_list)):
            port_id = self.properties[self.PORTS][index]
            vmi_obj = self.vnc_lib().virtual_machine_interface_read(id=port_id)
            vmi_props = vnc_api.VirtualMachineInterfacePropertiesType()
            vmi_props.set_service_interface_type(
                if_list[index].get_service_interface_type())
            vmi_obj.set_virtual_machine_interface_properties(vmi_props)
            vmi_obj.add_port_tuple(pt_obj)
            self.vnc_lib().virtual_machine_interface_update(vmi_obj)

        self.resource_id_set(pt_uuid)
Ejemplo n.º 2
0
    def handle_create(self):
        tenant_id = self.stack.context.tenant_id
        project_obj = self.vnc_lib().project_read(id=str(uuid.UUID(tenant_id)))
        vmi_obj = vnc_api.VirtualMachineInterface(
            name=self.properties[self.NAME], parent_obj=project_obj)
        vmi_obj.set_virtual_machine_interface_mac_addresses(
            vnc_api.MacAddressesType(
                self.properties[self.VIRTUAL_MACHINE_INTEFRACE_MAC_ADDRESSES]))
        for network in self.properties[self.VIRTUAL_NETWORKS]:
            try:
                vn_obj = self.vnc_lib().virtual_network_read(id=network)
            except vnc_api.NoIdError:
                vn_obj = self.vnc_lib().virtual_network_read(
                    fq_name_str=network)
            vmi_obj.add_virtual_network(vn_obj)

        for port_tuple in self.properties[self.PORT_TUPLES]:
            try:
                pt_obj = self.vnc_lib().port_tuple_read(id=port_tuple)
            except vnc_api.NoIdError:
                pt_obj = self.vnc_lib().port_tuple_read(fq_name_str=port_tuple)
            vmi_obj.add_port_tuple(pt_obj)
        vmi_props = vnc_api.VirtualMachineInterfacePropertiesType()
        vmi_props.set_service_interface_type(
            self.properties[self.SERVICE_INTERFACE_TYPE])
        vmi_obj.set_virtual_machine_interface_properties(vmi_props)
        vmi_uuid = super(HeatVirtualMachineInterface,
                         self).resource_create(vmi_obj)

        iip_obj = self._allocate_iip_for_family(vn_obj, pt_obj, vmi_obj, 'v4')
        iip_obj.add_virtual_machine_interface(vmi_obj)
        self.vnc_lib().instance_ip_update(iip_obj)

        self.resource_id_set(vmi_uuid)
def vmi_1(project):
    vmi = vnc_api.VirtualMachineInterface(name="esxi-1_dvs-1_dpg-1",
                                          parent_obj=project)
    vmi.set_uuid(models.generate_uuid(vmi.name))
    vmi.set_id_perms(constants.ID_PERMS)
    vmi_properties = vnc_api.VirtualMachineInterfacePropertiesType(
        sub_interface_vlan_tag=5)
    vmi.set_virtual_machine_interface_properties(vmi_properties)
    return vmi
Ejemplo n.º 4
0
 def _create_vnc_vmi_obj_with_new_vlan(self, new_vlan, old_vnc_vmi, vnc_vn):
     new_vnc_vmi = vnc_api.VirtualMachineInterface(
         name=old_vnc_vmi.name, parent_obj=self.get_project())
     new_vnc_vmi.set_uuid(old_vnc_vmi.uuid)
     new_vnc_vmi.add_virtual_network(vnc_vn)
     vmi_properties = vnc_api.VirtualMachineInterfacePropertiesType(
         sub_interface_vlan_tag=new_vlan)
     new_vnc_vmi.set_virtual_machine_interface_properties(vmi_properties)
     new_vnc_vmi.set_id_perms(const.ID_PERMS)
     return new_vnc_vmi
Ejemplo n.º 5
0
    def to_vnc_vmi(self, project, fabric_vn):
        if fabric_vn is None:
            raise VNCVMICreationError(
                "Cannot create VNC VMI without a fabric VN.")

        vnc_vmi = vnc_api.VirtualMachineInterface(name=self.name,
                                                  parent_obj=project)
        vnc_vmi.set_uuid(self.uuid)
        vnc_vmi.add_virtual_network(fabric_vn)
        vmi_properties = vnc_api.VirtualMachineInterfacePropertiesType(
            sub_interface_vlan_tag=self.dpg_model.vlan_id)
        vnc_vmi.set_virtual_machine_interface_properties(vmi_properties)
        vnc_vmi.set_id_perms(const.ID_PERMS)
        return vnc_vmi
Ejemplo n.º 6
0
    kvp.set_value("baremetal")
    kvps.add_key_value_pair(kvp)

    kvp = vnc_api.KeyValuePair()
    kvp.set_key("vif_type")
    kvp.set_value("vrouter")
    kvps.add_key_value_pair(kvp)

    if tag_list[my_vn_ids.index(my_vn_id)][1] == 'untagged':
        kvp = vnc_api.KeyValuePair()
        kvp.set_key("tor_port_vlan_id")
        kvp.set_value(str(tag_list[my_vn_ids.index(my_vn_id)][0]))
        kvps.add_key_value_pair(kvp)
    
    my_vmi.set_virtual_machine_interface_bindings(kvps)
    my_vmi.add_security_group(my_sg)
    obj_1 = vnc_api.VirtualMachineInterfacePropertiesType()
    if tag_list[my_vn_ids.index(my_vn_id)][1] == 'untagged':
        obj_1.set_sub_interface_vlan_tag(0)
    else:
        obj_1.set_sub_interface_vlan_tag(tag_list[my_vn_ids.index(my_vn_id)][0])
    my_vmi.set_virtual_machine_interface_properties(obj_1)
    vmi_id=vh.virtual_machine_interface_create(my_vmi)
    my_vmi_ids.append(vmi_id)
print ("Updating VPG with the VMIs")
my_vpg = vh.virtual_port_group_read(id=my_vpg_id)
for my_vmi_id in my_vmi_ids:
    my_vmi=vh.virtual_machine_interface_read(id=my_vmi_id)
    my_vpg.add_virtual_machine_interface(my_vmi)
vh.virtual_port_group_update(my_vpg)
Ejemplo n.º 7
0
    def test_trunk_add_and_delete_sub_ports(self):
        vn = vnc_api.VirtualNetwork('vn-%s' % (self.id()))
        self._vnc_lib.virtual_network_create(vn)
        vmi_obj = vnc_api.VirtualMachineInterface('trunk-port',
                                                  parent_obj=self.project)
        vmi_obj.set_virtual_network(vn)
        vmi_id = self._vnc_lib.virtual_machine_interface_create(vmi_obj)

        context = {
            'operation': 'CREATE',
            'user_id': '',
            'is_admin': True,
            'roles': ''
        }
        data = {
            'resource': {
                'name': 'trunk-%s' % (self.id()),
                'tenant_id': self.project_id,
                'port_id': vmi_id
            }
        }
        body = {'context': context, 'data': data}
        resp = self._api_svr_app.post_json('/neutron/trunk', body)
        trunk_dict = json.loads(resp.text)

        sub_port = vnc_api.VirtualMachineInterface('trunk-sub-port-%s' %
                                                   (self.id()),
                                                   parent_obj=self.project)
        vmi_prop = vnc_api.VirtualMachineInterfacePropertiesType(
            sub_interface_vlan_tag=10)
        sub_port.set_virtual_machine_interface_properties(vmi_prop)
        sub_port.set_virtual_network(vn)
        sub_port_id = self._vnc_lib.virtual_machine_interface_create(sub_port)

        neutron_trunk = self._add_subports(self.project_id, trunk_dict['id'],
                                           sub_port_id)
        self.assertEquals(neutron_trunk['sub_ports'][0].get('port_id'),
                          sub_port.uuid)

        sub_port_neg = vnc_api.VirtualMachineInterface(
            'trunk-sub-port-neg-%s' % (self.id()), parent_obj=self.project)
        sub_port_neg.set_virtual_network(vn)
        sub_port_id_neg = self._vnc_lib.virtual_machine_interface_create(
            sub_port_neg)
        # Adding sub port with the vlan tag that already exists in a trunk
        # should return an exception.
        try:
            self._add_subports(self.project_id,
                               trunk_dict['id'],
                               sub_port_id_neg,
                               vlan_tag=10)
        except webtest.app.AppError as e:
            self.assertIsNot(re.search('DuplicateSubPort', str(e)), None)

        neutron_trunk = self._remove_subports(self.project_id,
                                              trunk_dict['id'], sub_port_id)
        self.assertEquals(neutron_trunk['sub_ports'], [])
        # Clean the resources
        self.delete_resource('trunk', self.project_id, trunk_dict['id'])
        self._vnc_lib.virtual_machine_interface_delete(id=sub_port_id)
        self._vnc_lib.virtual_machine_interface_delete(id=sub_port_id_neg)
        self._vnc_lib.virtual_machine_interface_delete(id=vmi_id)
        self._vnc_lib.virtual_network_delete(id=vn.uuid)
Ejemplo n.º 8
0
 def make_vmi_properties_with_vlan_tag(vlan_tag):
     vmi_properties = vnc_api.VirtualMachineInterfacePropertiesType(
         sub_interface_vlan_tag=vlan_tag)
     return vmi_properties