def vmi_model_2(vm_model_2, vn_model_2, project, security_group):
    vmi = VirtualMachineInterfaceModel(
        vm_model_2, vn_model_2,
        Mock(mac_address='mac-address-2',
             portgroup_key='dvportgroup-1',
             vlan_id=2))
    vmi.parent = project
    vmi.security_group = security_group
    return vmi
def test_create_uuid():
    mac_str = 'mac-address'
    mac_unicode = u'mac-address'

    uuid_str = VirtualMachineInterfaceModel.create_uuid(mac_str)
    uuid_unicode = VirtualMachineInterfaceModel.create_uuid(mac_unicode)

    assert uuid_str == '2f269404-b466-3cc7-8817-d9ee99f63187'
    assert uuid_unicode == '2f269404-b466-3cc7-8817-d9ee99f63187'
Beispiel #3
0
def test_delete_vmi_model(database, vmi_model):
    database.save(vmi_model)

    uuid = VirtualMachineInterfaceModel.create_uuid('mac-address')
    database.delete_vmi_model(uuid)

    assert database.get_vmi_model_by_uuid(uuid) is None
Beispiel #4
0
def test_get_vmi_model_by_uuid(database, vmi_model):
    database.save(vmi_model)

    uuid = VirtualMachineInterfaceModel.create_uuid('mac-address')
    result = database.get_vmi_model_by_uuid(uuid)

    assert result is vmi_model
    assert database.get_vmi_model_by_uuid('dummy-uuid') is None
Beispiel #5
0
def test_construct_instance_ip(vmi_model, project, security_group):
    vmi_model.parent = project
    vmi_model.security_group = security_group
    vmi_model.vn_model.vnc_vn.external_ipam = None

    vmi_model.construct_instance_ip()
    instance_ip = vmi_model.vnc_instance_ip

    assert instance_ip.instance_ip_address is None
    assert instance_ip.virtual_machine_interface_refs[0]['uuid'] == vmi_model.uuid
    expected_uuid = VirtualMachineInterfaceModel.construct_instance_ip_uuid(instance_ip.display_name)
    assert instance_ip.uuid == expected_uuid
Beispiel #6
0
    def update_nic(self, nic_info):
        vmi_model = self._database.get_vmi_model_by_uuid(
            VirtualMachineInterfaceModel.create_uuid(nic_info.macAddress))
        if not vmi_model:
            return
        if not vmi_model.vn_model.vnc_vn.external_ipam:
            return

        try:
            for ip_address in nic_info.ipAddress:
                self._update_ip_address(vmi_model, ip_address)
        except AttributeError:
            pass
def instance_ip(vnc_vmi, vnc_vn_1, vnc_vm):
    ip_name = 'ip-' + vnc_vn_1.name + '-' + vnc_vm.name
    ip_uuid = VirtualMachineInterfaceModel.create_uuid(ip_name)

    ip = vnc_api.InstanceIp(
        name=ip_uuid,
        display_name=ip_name,
        id_perms=ID_PERMS,
    )

    ip.set_instance_ip_address('10.10.10.1')
    ip.set_uuid(ip_uuid)
    ip.set_virtual_network(vnc_vn_1)
    ip.set_virtual_machine_interface(vnc_vmi)
    ip.annotations = ip.annotations or vnc_api.KeyValuePairs()
    ip.annotations.add_key_value_pair(
        vnc_api.KeyValuePair('vrouter-uuid', 'vrouter-uuid-1'))
    ip.annotations.add_key_value_pair(vnc_api.KeyValuePair('key-1', 'value-1'))
    return ip