def xenserver_vm(self):
    '''
    Return the XenServer VM on which this device is a guest.
    '''
    vif = VIF.findByMAC(self.dmd, device_macaddresses(self))
    if vif:
        return vif.vm()
def create_endpoint(dmd):
    '''
    Return an Endpoint suitable for functional testing.
    '''
    # DeviceClass
    dc = dmd.Devices.createOrganizer('/XenServer')
    dc.setZenProperty('zPythonClass', 'ZenPacks.zenoss.XenServer.Endpoint')

    # Endpoint
    endpoint = dc.createInstance('endpoint')

    # Host
    from ZenPacks.zenoss.XenServer.Host import Host
    host1 = add_contained(endpoint, 'hosts', Host('host1'))

    from ZenPacks.zenoss.XenServer.PBD import PBD
    pbd1 = add_contained(host1, 'pbds', PBD('pbd1'))

    from ZenPacks.zenoss.XenServer.PIF import PIF
    pif1 = add_contained(host1, 'pifs', PIF('pif1'))

    # Storage
    from ZenPacks.zenoss.XenServer.SR import SR
    sr1 = add_contained(endpoint, 'srs', SR('sr1'))
    add_noncontained(sr1, 'pbds', pbd1)
    add_noncontained(sr1, 'suspend_image_for_hosts', host1)

    sr2 = add_contained(endpoint, 'srs', SR('sr2'))
    add_noncontained(sr2, 'crash_dump_for_hosts', host1)

    sr3 = add_contained(endpoint, 'srs', SR('sr3'))
    add_noncontained(sr3, 'local_cache_for_hosts', host1)

    from ZenPacks.zenoss.XenServer.VDI import VDI
    vdi1 = add_contained(sr1, 'vdis', VDI('vdi1'))

    # Network
    from ZenPacks.zenoss.XenServer.Network import Network
    network1 = add_contained(endpoint, 'networks', Network('network1'))
    add_noncontained(network1, 'pifs', pif1)

    # Pool
    from ZenPacks.zenoss.XenServer.Pool import Pool
    pool1 = add_contained(endpoint, 'pools', Pool('pool1'))
    add_noncontained(pool1, 'master', host1)
    add_noncontained(pool1, 'default_sr', sr1)
    add_noncontained(pool1, 'suspend_image_sr', sr2)
    add_noncontained(pool1, 'crash_dump_sr', sr3)

    # VM
    from ZenPacks.zenoss.XenServer.VM import VM
    vm1 = add_contained(endpoint, 'vms', VM('vm1'))
    add_noncontained(vm1, 'host', host1)

    from ZenPacks.zenoss.XenServer.VBD import VBD
    vbd1 = add_contained(vm1, 'vbds', VBD('vbd1'))
    add_noncontained(vbd1, 'vdi', vdi1)

    from ZenPacks.zenoss.XenServer.VIF import VIF
    vif1 = add_contained(vm1, 'vifs', VIF('vif1'))
    add_noncontained(vif1, 'network', network1)

    # vApp
    from ZenPacks.zenoss.XenServer.VMAppliance import VMAppliance
    vapp1 = add_contained(endpoint, 'vmappliances', VMAppliance('vapp1'))
    add_noncontained(vapp1, 'vms', vm1)

    return endpoint
    def xenserver_vm(self):
        from ZenPacks.zenoss.XenServer.VIF import VIF

        vif = VIF.findByMAC(self.dmd, mac_addresses=self.mac_addresses)
        if vif:
            return vif.vm()
Exemple #4
0
    def xenserver_vm(self):
        from ZenPacks.zenoss.XenServer.VIF import VIF

        vif = VIF.findByMAC(self.dmd, mac_addresses=self.mac_addresses)
        if vif:
            return vif.vm()
    def test_CloudStack(self):
        try:
            from ZenPacks.zenoss.CloudStack.tests.test_impact import create_cloud
        except ImportError:
            # CloudStack earlier than 1.1 which doesn't have hooks for
            # XenServer impact.
            return

        from ZenPacks.zenoss.XenServer.VM import VM
        from ZenPacks.zenoss.XenServer.VIF import VIF

        # Create CloudStack configuration.
        cs_cloud = create_cloud(self.dmd)

        cs_host = cs_cloud.getObjByPath(
            'zones/zone1/pods/pod1/clusters/cluster1/hosts/host1')
        cs_host.ip_address = '10.11.12.13'
        cs_host.index_object()

        cs_routervm = cs_cloud.getObjByPath(
            'zones/zone1/pods/pod1/routervms/routervm1')
        cs_routervm.linklocal_macaddress = '00:0c:29:fe:ab:bc'
        cs_routervm.index_object()

        cs_systemvm = cs_cloud.getObjByPath(
            'zones/zone1/pods/pod1/systemvms/systemvm1')
        cs_systemvm.linklocal_macaddress = '00:0c:29:fe:ab:bd'
        cs_systemvm.index_object()

        cs_vm = cs_cloud.getObjByPath('zones/zone1/vms/vm1')
        cs_vm.mac_address = '00:0c:29:fe:ab:be'
        cs_vm.index_object()

        # Create XenServer configuration.
        xen_endpoint = self.endpoint()

        xen_host = xen_endpoint.getObjByPath('hosts/host1')
        xen_pif = xen_host.getObjByPath('pifs/pif1')
        xen_pif.ipv4_addresses = [cs_host.ip_address]
        xen_pif.index_object()

        xen_routervm = add_contained(xen_endpoint, 'vms', VM('xen_routervm1'))
        xen_routervm_vif = add_contained(xen_routervm, 'vifs',
                                         VIF('xen_routervm1_vif1'))
        xen_routervm_vif.macaddress = cs_routervm.linklocal_macaddress
        xen_routervm_vif.index_object()

        xen_systemvm = add_contained(xen_endpoint, 'vms', VM('xen_systemvm1'))
        xen_systemvm_vif = add_contained(xen_systemvm, 'vifs',
                                         VIF('xen_systemvm1_vif1'))
        xen_systemvm_vif.macaddress = cs_systemvm.linklocal_macaddress
        xen_systemvm_vif.index_object()

        xen_vm = xen_endpoint.getObjByPath('vms/vm1')
        xen_vm_vif = xen_vm.getObjByPath('vifs/vif1')
        xen_vm_vif.macaddress = cs_vm.mac_address
        xen_vm_vif.index_object()

        xen_host_impacts, xen_host_impacted_by = impacts_for(xen_host)
        xen_vm_impacts, vm_impacted_by = impacts_for(xen_vm)
        xen_routervm_impacts, xen_routervm_impacted_by = impacts_for(
            xen_routervm)
        xen_systemvm_impacts, xen_systemvm_impacted_by = impacts_for(
            xen_systemvm)

        # Host -> CloudStack Host
        self.assertTrue(cs_host.id in xen_host_impacts,
                        'missing impact: {0} <- {1}'.format(cs_host, xen_host))

        # VM -> CloudStack RouterVM
        self.assertTrue(
            cs_routervm.id in xen_routervm_impacts,
            'missing impact: {0} <- {1}'.format(cs_routervm, xen_routervm))

        # VM -> CloudStack SystemVM
        self.assertTrue(
            cs_systemvm.id in xen_systemvm_impacts,
            'missing impact: {0} <- {1}'.format(cs_systemvm, xen_systemvm))

        # VM -> CloudStack VirtualMachine
        self.assertTrue(cs_vm.id in xen_vm_impacts,
                        'missing impact: {0} <- {1}'.format(cs_vm, xen_vm))
def xenserver_vif(self):
    '''
    Return the XenServer VIF underlying this interface.
    '''
    return VIF.findByMAC(self.dmd, self.macaddress)