Пример #1
0
    def create_device(self, node, connected_nodes):
        device = self.dmd.Devices.findDeviceByIdExact(node)
        if device:
            device.deleteDevice()

        site = node.split("-", 1)[0]
        gateways = ["{}-gw-a".format(site), "{}-gw-b".format(site)]
        is_host = "host" in node

        dc = self.dmd.Devices.createOrganizer("/Test/Layer2/Site-{}/{}".format(
            site, "Host" if is_host else "Switch"))

        dc.setZenProperty("zL2PotentialRootCause", False if is_host else True)
        dc.setZenProperty("zL2Gateways", gateways)

        device = dc.createInstance(node)
        device.setPerformanceMonitor("localhost")
        device.manageIp = self.ip(node)

        from Products.ZenModel.IpInterface import IpInterface

        mgmt_if_id = "mgmt"
        device.os.interfaces._setObject(mgmt_if_id, IpInterface(mgmt_if_id))
        mgmt_if = device.os.interfaces._getOb(mgmt_if_id)
        mgmt_if.macaddress = self.mac_pair(node, None)[0]
        mgmt_if.setIpAddresses(["{}/16".format(self.ip(node))])
        mgmt_if.index_object()
        notify(IndexingEvent(mgmt_if))

        for connected_node in connected_nodes:
            connecting_if_id = "to-{}".format(connected_node)
            device.os.interfaces._setObject(connecting_if_id,
                                            IpInterface(connecting_if_id))

            local_mac, client_mac = self.mac_pair(node, connected_node)

            connecting_if = device.os.interfaces._getOb(connecting_if_id)
            connecting_if.macaddress = local_mac

            if not is_host:
                connecting_if.clientmacs = [client_mac]

            connecting_if.setIpAddresses(["{}/16".format(self.ip(node))])

            notify(IndexingEvent(connecting_if))

        notify(IndexingEvent(device))
        device.index_object()

        return device
Пример #2
0
    def testGetManageIpMultipleInterfaces(self):
        """
        What should happen if multiple interfaces are available for a
        service?  What if you want to select an alternate one?
        """
        # No interfaces defined
        self.assertEquals(self.dev.getManageIp(), '')
        self.assertEquals(self.ipsvc.getManageIp(), '')

        # Have one IP address
        tmpo = IpInterface('test')
        self.dev.os.interfaces._setObject('test', tmpo)
        self.iface = self.dev.getDeviceComponents()[1]
        self.iface.addIpAddress('1.2.3.4')
        self.dev.setManageIp('1.2.3.4/24')
        self.ipsvc.ipaddresses = ['0.0.0.0']

        self.assertEquals(self.dev.getManageIp(), '1.2.3.4/24')
        self.assertEquals(self.ipsvc.getManageIp(), '1.2.3.4')

        # Have two IP addresses
        tmpo = IpInterface('test1')
        self.dev.os.interfaces._setObject('test1', tmpo)
        self.iface1 = self.dev.getDeviceComponents()[2]
        self.iface1.addIpAddress('2.3.4.5')
        self.dev.setManageIp('2.3.4.5/24')

        self.assertEquals(self.dev.getManageIp(), '2.3.4.5/24')
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')

        self.ipsvc.setManageIp('1.2.3.4/24')
        self.assertEquals(self.ipsvc.getManageIp(), '1.2.3.4')

        self.ipsvc.unsetManageIp()
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')

        # Restrict the service to only one IP address
        # Happens when a service restarts with new configuration
        self.ipsvc.setManageIp('2.3.4.5/24')
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')
        self.ipsvc.ipaddresses = ['1.2.3.4']
        self.assertEquals(self.ipsvc.getManageIp(), '1.2.3.4')

        # Remove an IP address from an interface
        self.ipsvc.ipaddresses = ['0.0.0.0']
        self.ipsvc.setManageIp('1.2.3.4/24')
        self.assertEquals(self.ipsvc.getManageIp(), '1.2.3.4')
        self.iface.setIpAddresses(['10.20.30.40/8'])
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')
 def add_linux_interface_mac(device, interface_name, macaddress):
     eth_if = IpInterface(interface_name)
     device.os.interfaces._setObject(eth_if.id, eth_if)
     eth_if = device.os.interfaces._getOb(eth_if.id)
     eth_if.macaddress = macaddress
     eth_if.index_object()
     device.index_object()
Пример #4
0
    def testSetManageIp(self):
        tmpo = IpInterface('test')
        self.dev.os.interfaces._setObject('test', tmpo)
        self.iface = self.dev.getDeviceComponents()[1]
        self.iface.addIpAddress('1.2.3.4')

        # Explicitly set the manageIp at the device level
        self.dev.setManageIp('1.2.3.4/24')
        self.assertEquals(self.dev.getManageIp(), '1.2.3.4/24')
        self.assertEquals(self.ipsvc.getManageIp(), '1.2.3.4')

        self.dev.setManageIp('2.3.4.5/24')
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')

        # Explicitly set the manageIp at the service level
        self.ipsvc.ipaddresses = ['0.0.0.0']
        self.ipsvc.setManageIp('1.2.3.4/24')
        self.assertEquals(self.dev.getManageIp(), '2.3.4.5/24')
        self.assertEquals(self.ipsvc.getManageIp(), '1.2.3.4')

        # Unset the manageIp
        self.ipsvc.unsetManageIp()
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')

        # Set the manageIp with garbage
        self.ipsvc.setManageIp('HelloWorld')
        self.assertEquals(self.ipsvc.getManageIp(), '2.3.4.5')
Пример #5
0
    def testSetManageIp(self):
        testIp = '1.2.3.4'
        self.dev.setManageIp(testIp)
        self.assertEqual(self.dev.getManageIp(), testIp)

        ip = self.dev.getNetworkRoot().findIp(testIp)
        self.assert_(ip is not None)

        self.dev.setManageIp(testIp)

        # Need a network interface to register an IP in catalog
        from Products.ZenModel.IpInterface import IpInterface
        tmpIface = IpInterface('testNIC')
        self.dev.os.interfaces._setObject('testNIC', tmpIface)
        self.iface1 = self.dev.getDeviceComponents()[0]
        self.iface1.addIpAddress('1.2.3.4')

        # What about duplicates?
        d = self.dmd.Devices.createInstance('localhost')
        d.setManageIp()
        self.assertTrue(d.getManageIp() in ('127.0.0.1', '::1'))

        # Mask out the warning
        log = logging.getLogger()
        curLogLevel = log.getEffectiveLevel()
        log.setLevel(logging.ERROR)
        d.setManageIp(testIp)
        log.setLevel(curLogLevel)
        self.assertTrue(d.getManageIp() in ('127.0.0.1', '::1'))
Пример #6
0
 def afterSetUp(self):
     super(TestIpInterface, self).afterSetUp()
     tmpo = IpInterface('test')
     self.dev = self.dmd.Devices.createInstance('testdev')
     self.dev.os.interfaces._setObject('test', tmpo)
     self.iface = self.dev.getDeviceComponents()[0]
     self.iface.interfaceName = 'test'
     self.iface.macaddress = '00:00:00:00:00:00'
Пример #7
0
 def afterSetUp(self):
     super(TestIpAddress, self).afterSetUp()
     self.dev = self.dmd.Devices.createInstance("testdev")
     tmpIface = IpInterface('test')
     self.dev.os.interfaces._setObject('test',tmpIface)
     self.iface = self.dev.getDeviceComponents()[0]
     self.iface.addIpAddress('1.2.3.4')
     self.addr = self.iface.getIpAddressObj()
Пример #8
0
def add_interface(dev, macaddress='', clientmacs=[], vlans=None):
    ''' Add new interface to device '''
    eth_id = random_id()
    eth = IpInterface(eth_id, eth_id)
    eth.macaddress = macaddress
    eth.clientmacs = clientmacs
    if vlans:
        eth.vlans = vlans
    dev.os.interfaces._setObject('unused_id_param', eth)
    def test_Platform_Physical(self):
        linux_dc = self.dmd.Devices.createOrganizer('/Server/Linux')
        linux_server = linux_dc.createInstance('test-linux-host1')

        from Products.ZenModel.IpInterface import IpInterface
        linux_iface = add_contained(linux_server.os, 'interfaces',
                                    IpInterface('eth0'))
        linux_iface.macaddress = '00:0c:29:fe:ab:bc'
        linux_iface.index_object()

        from Products.ZenModel.HardDisk import HardDisk
        linux_disk = add_contained(linux_server.hw, 'harddisks',
                                   HardDisk('sda3'))

        host1 = self.endpoint().getObjByPath('hosts/host1')
        host1.address = '192.168.66.71'

        pif1 = self.endpoint().getObjByPath('hosts/host1/pifs/pif1')
        pif1.pif_device = linux_iface.id
        pif1.macaddress = linux_iface.macaddress
        pif1.index_object()

        pbd1 = self.endpoint().getObjByPath('hosts/host1/pbds/pbd1')
        pbd1.dc_device = '/dev/{}'.format(linux_disk.id)

        host1_impacts, host1_impacted_by = impacts_for(host1)
        pbd1_impacts, pbd1_impacted_by = impacts_for(pbd1)
        pif1_impacts, pif1_impacted_by = impacts_for(pif1)

        server_impacts, server_impacted_by = impacts_for(linux_server)
        iface_impacts, iface_impacted_by = impacts_for(linux_iface)
        disk_impacts, disk_impacted_by = impacts_for(linux_disk)

        # Physical Server -> Host
        self.assertTrue(linux_server.id in host1_impacted_by,
                        'missing impact: {} -> {}'.format(linux_server, host1))

        self.assertTrue(host1.id in server_impacts,
                        'missing impact: {} <- {}'.format(host1, linux_server))

        # Physical Server IpInterface -> PIF
        self.assertTrue(linux_iface.id in pif1_impacted_by,
                        'missing impact: {} -> {}'.format(linux_iface, pif1))

        self.assertTrue(pif1.id in iface_impacts,
                        'missing impact: {} <- {}'.format(pif1, linux_iface))

        # Physical Server HardDisk -> PBD
        self.assertTrue(linux_disk.id in pbd1_impacted_by,
                        'missing impact: {} -> {}'.format(linux_disk, pbd1))

        self.assertTrue(pbd1.id in disk_impacts,
                        'missing impact: {} <- {}'.format(pbd1, linux_disk))
    def test_Platform_Virtual(self):
        linux_dc = self.dmd.Devices.createOrganizer('/Server/Linux')
        linux_server = linux_dc.createInstance('test-linux-guest1')

        from Products.ZenModel.IpInterface import IpInterface
        linux_iface = add_contained(linux_server.os, 'interfaces',
                                    IpInterface('eth0'))
        linux_iface.macaddress = '00:0c:29:fe:ab:bc'
        linux_iface.index_object()

        from Products.ZenModel.HardDisk import HardDisk
        linux_disk = add_contained(linux_server.hw, 'harddisks',
                                   HardDisk('xvda'))

        vm1 = self.endpoint().getObjByPath('vms/vm1')

        vif1 = self.endpoint().getObjByPath('vms/vm1/vifs/vif1')
        vif1.vif_device = linux_iface.id
        vif1.macaddress = linux_iface.macaddress
        vif1.index_object()

        vbd1 = self.endpoint().getObjByPath('vms/vm1/vbds/vbd1')
        vbd1.vbd_device = linux_disk.id

        vm1_impacts, vm1_impacted_by = impacts_for(vm1)
        vbd1_impacts, vbd1_impacted_by = impacts_for(vbd1)
        vif1_impacts, vif1_impacted_by = impacts_for(vif1)

        server_impacts, server_impacted_by = impacts_for(linux_server)
        iface_impacts, iface_impacted_by = impacts_for(linux_iface)
        disk_impacts, disk_impacted_by = impacts_for(linux_disk)

        # VM -> Guest Device
        self.assertTrue(vm1.id in server_impacted_by,
                        'missing impact: {} -> {}'.format(vm1, linux_server))

        self.assertTrue(linux_server.id in vm1_impacts,
                        'missing impact: {} <- {}'.format(linux_server, vm1))

        # PIF -> Guest IpInterface
        self.assertTrue(vif1.id in iface_impacted_by,
                        'missing impact: {} -> {}'.format(vif1, linux_iface))

        self.assertTrue(linux_iface.id in vif1_impacts,
                        'missing impact: {} <- {}'.format(linux_iface, vif1))

        # PBD -> Guest HardDisk
        self.assertTrue(vbd1.id in disk_impacted_by,
                        'missing impact: {} -> {}'.format(vbd1, linux_disk))

        self.assertTrue(linux_disk.id in vbd1_impacts,
                        'missing impact: {} <- {}'.format(linux_disk, vbd1))
Пример #11
0
    def afterSetUp(self):
        super(TestIpRouteEntry, self).afterSetUp()

        self.dev = self.dmd.Devices.createInstance('testdev')

        tmpo = IpInterface('iface0')
        self.dev.os.interfaces._setObject('iface0', tmpo)
        self.iface0 = self.dev.os.interfaces._getOb('iface0')
        self.iface0.setIpAddresses('1.2.3.4/24')
        self.iface0.ifindex = 0
        self.iface0.interfaceName = 'iface0'

        tmpo = IpInterface('iface1')
        self.dev.os.interfaces._setObject('iface1', tmpo)
        self.iface1 = self.dev.os.interfaces._getOb('iface1')
        self.iface1.setIpAddresses('2.3.4.5/24')
        self.iface1.ifindex = 1
        self.iface1.interfaceName = 'iface1'

        tmpo = IpRouteEntry('rEntry')
        self.dev.os.routes._setObject('rEntry', tmpo)
        self.rEntry = self.dev.os.routes()[0]
Пример #12
0
    def testGetIpAddresses(self):
        # No interfaces defined
        self.assertEquals(self.ipsvc.getNonLoopbackIpAddresses(), [])

        # Have one IP address
        tmpo = IpInterface('test')
        self.dev.os.interfaces._setObject('test', tmpo)
        self.iface = self.dev.getDeviceComponents()[1]
        self.iface.addIpAddress('1.2.3.4')
        self.dev.setManageIp('1.2.3.4/24')

        self.assertEquals(self.ipsvc.getNonLoopbackIpAddresses(), ['1.2.3.4'])

        # Have two IP addresses
        tmpo = IpInterface('test1')
        self.dev.os.interfaces._setObject('test1', tmpo)
        self.iface1 = self.dev.getDeviceComponents()[2]
        self.iface1.addIpAddress('2.3.4.5')
        self.assertEquals(self.ipsvc.getNonLoopbackIpAddresses(),
                          ['1.2.3.4', '2.3.4.5'])
        self.assertEquals(
            self.ipsvc.getNonLoopbackIpAddresses(showNetMask=True),
            ['1.2.3.4/24', '2.3.4.5/24'])
Пример #13
0
 def testSetNextHopIp(self):
     tempdev = self.dmd.Devices.createInstance('testdev2')
     tmpo = IpInterface('test2')
     tempdev.os.interfaces._setObject('test2', tmpo)
     iface2 = tempdev.os.interfaces()[0]
     iface2.setIpAddresses('3.4.5.6/24')
     self.rEntry.setNextHopIp('3.4.5.6')
     self.assert_(self.rEntry.getNextHopIp() == '3.4.5.6')
     self.assertEqual(
         self.rEntry.getNextHopIpLink(),
         "<a href='/zport/dmd/Networks/3.4.5.0/ipaddresses/3.4.5.6'>3.4.5.6</a>"
     )
     self.assertEqual(self.rEntry.getNextHopDevice(), tempdev)
     self.assertEqual(
         self.rEntry.getNextHopDeviceLink(),
         "<a href='/zport/dmd/Devices/devices/testdev2/'>testdev2</a>")
Пример #14
0
    def testManage_createDeviceWithIpFromInterface(self):
        # create device with ip that is on Interface of another device
        testIp = '1.2.3.4'
        dev1 = manage_createDevice(self.dmd,
                                   'myfirstdevice',
                                   '/',
                                   manageIp='1.2.3.5')

        # Need a network interface on that device
        from Products.ZenModel.IpInterface import IpInterface
        tmpIface = IpInterface('testNIC')
        dev1.os.interfaces._setObject('testNIC', tmpIface)
        iface = dev1.getDeviceComponents()[0]
        iface.addIpAddress(testIp)

        ip = dev1.getNetworkRoot().findIp(testIp)
        self.assert_(ip is not None)

        dev2 = manage_createDevice(self.dmd,
                                   'myseconddevice',
                                   '/',
                                   manageIp=testIp)
        self.assertNotEqual(dev1.manageIp, dev2.manageIp)
        self.assert_(dev2 is not None)