Exemplo n.º 1
0
    def _create_ip_range_from_xml(self, subnet_id, network_name,
                                  ip_address, start_ip, end_ip):
        lib_utils = XMLUtils()
        net_xml = '<network><name>' + \
            network_name + '</name><forward mode=\'nat\'/><ip address=\' ' + \
            ip_address + \
            '\' netmask=\'255.255.255.0\'><dhcp><range start=\'' + \
            start_ip + '\' end=\'' + end_ip + '\'/>''</dhcp></ip></network>'

        ipRange = IpAddressRange()
        if lib_utils.parseXML(net_xml, '//network/ip/dhcp') is not None:
                startIpAddress = IpAddress()
                startIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'start'))
                ipRange.set_id(startIpAddress.get_address())
                startIpAddress.set_id(startIpAddress.get_address())
                startIpAddress.set_allocationType('DHCP')
                ipRange.set_startAddress(startIpAddress)
                endIpAddress = IpAddress()
                endIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'end'))
                endIpAddress.set_id(endIpAddress.get_address())
                endIpAddress.set_allocationType('DHCP')
                ipRange.set_endAddress(endIpAddress)
                ipRange.set_allocationType('DHCP')
        else:
                ipRange.set_id(subnet_id + '_AUTO_STATIC')
                ipRange.set_allocationType('AUTO_STATIC')
        return ipRange
    def _create_ip_range_from_xml(self, subnet_id, network_name,
                                  ip_address, start_ip, end_ip):
        lib_utils = XMLUtils()
        net_xml = '<network><name>' + \
            network_name + '</name><forward mode=\'nat\'/><ip address=\' ' + \
            ip_address + \
            '\' netmask=\'255.255.255.0\'><dhcp><range start=\'' + \
            start_ip + '\' end=\'' + end_ip + '\'/>''</dhcp></ip></network>'

        ipRange = IpAddressRange()
        if lib_utils.parseXML(net_xml, '//network/ip/dhcp') is not None:
                startIpAddress = IpAddress()
                startIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'start'))
                ipRange.set_id(startIpAddress.get_address())
                startIpAddress.set_id(startIpAddress.get_address())
                startIpAddress.set_allocationType('DHCP')
                ipRange.set_startAddress(startIpAddress)
                endIpAddress = IpAddress()
                endIpAddress.set_address(lib_utils.parseXMLAttributes(
                    net_xml, '//network/ip/dhcp/range', 'end'))
                endIpAddress.set_id(endIpAddress.get_address())
                endIpAddress.set_allocationType('DHCP')
                ipRange.set_endAddress(endIpAddress)
                ipRange.set_allocationType('DHCP')
        else:
                ipRange.set_id(subnet_id + '_AUTO_STATIC')
                ipRange.set_allocationType('AUTO_STATIC')
        return ipRange
Exemplo n.º 3
0
 def setUp(self):
     self.utils = XMLUtils()
     self.ipProfile = IpProfile()
     self.ip_profile_list = []
     self.ipProfile.set_ipAddress('10.10.0.0')
     self.ipProfile.set_hostname('LOCALHOST')
     self.ipProfile.set_ipType("IPV4")
     self.ip_profile_list.append(self.ipProfile)
Exemplo n.º 4
0
 def setUp(self):
     self.utils = XMLUtils()
     self.ipProfile = IpProfile()
     self.ip_profile_list = []
     self.ipProfile.set_ipAddress('10.10.0.0')
     self.ipProfile.set_hostname('LOCALHOST')
     self.ipProfile.set_ipType("IPV4")
     self.ip_profile_list.append(self.ipProfile)
Exemplo n.º 5
0
 def __init__(self, conn, uuid):
     self.conn = conn
     self.libvirtconn = conn
     self.uuid = uuid
     self.domainObj = None
     self.old_stats = None
     self.new_stats = None
     self.temp_stats = Stats()
     self.utils = XMLUtils()
Exemplo n.º 6
0
class test_XMLUtils(unittest.TestCase):

    def setUp(self):
        self.utils = XMLUtils()
        self.ipProfile = IpProfile()
        self.ip_profile_list = []
        self.ipProfile.set_ipAddress('10.10.0.0')
        self.ipProfile.set_hostname('LOCALHOST')
        self.ipProfile.set_ipType("IPV4")
        self.ip_profile_list.append(self.ipProfile)

    def test_is_profile_in_list(self):
        result = self.utils.is_profile_in_list(
            self.ipProfile, self.ip_profile_list)
        self.assertTrue(result)

    def test_getNodeXML(self):
        xml = '<network><name> NAME </name></network>'
        result = self.utils.getNodeXML(xml, "address")
        self.assertTrue(len(result) == 0)
Exemplo n.º 7
0
class test_XMLUtils(unittest.TestCase):

    def setUp(self):
        self.utils = XMLUtils()
        self.ipProfile = IpProfile()
        self.ip_profile_list = []
        self.ipProfile.set_ipAddress('10.10.0.0')
        self.ipProfile.set_hostname('LOCALHOST')
        self.ipProfile.set_ipType("IPV4")
        self.ip_profile_list.append(self.ipProfile)

    def test_is_profile_in_list(self):
        result = self.utils.is_profile_in_list(
            self.ipProfile, self.ip_profile_list)
        self.assertTrue(result)

    def test_getNodeXML(self):
        xml = '<network><name> NAME </name></network>'
        result = self.utils.getNodeXML(xml, "address")
        self.assertTrue(len(result) == 0)
Exemplo n.º 8
0
class XMLUtilsTest(unittest.TestCase):

    def setUp(self):
        self.utils = XMLUtils()

    def test_parseXML(self):
        self.assertEqual(self.utils.parseXML(
            """<outer><inner a='90'>mytext1</inner>
                      <inner>mytext2</inner>
               </outer>""",
            "//outer/inner"),
            ['mytext1', 'mytext2'])
        self.assertEqual(self.utils.parseXML(
            "<outer><inner>mytext1</inner></outer>", "//outer/inner"),
            'mytext1')

    def test_parseXMLAttributes(self):
        xml = """<outer><inner>mytext1</inner>
                        <inner b='23'>mytext2</inner>
                 </outer>"""
        self.assertEqual(
            self.utils.parseXMLAttributes(xml, '//outer/inner', 'b'), None)
        self.assertEqual(self.utils.parseXMLAttributes(
            xml, '//outer/inner', 'b', True), ['23'])

    def test_getNodeXML(self):
        xml = """<outer><inner>mytext1</inner>
                        <inner b='23'>mytext2</inner>
                        <a><b>88</b><b>87</b></a><b>89</b></outer>"""
        self.assertEquals(
            self.utils.getNodeXML(xml, "//outer/b"), ['<b>89</b>'])
        self.assertEquals(self.utils.getNodeXML(
            xml, "//outer/a/b"), ['<b>88</b>', '<b>87</b>'])

        xml = """<outer xmlns=\"http://namespace\">
                    <inner>mytext1</inner>
                    <inner b='23'>mytext2</inner>
                    <a><b>88</b><b>87</b></a><b>89</b>
                </outer>"""
        namespaces = {'a': 'http://namespace'}
        self.assertEquals(self.utils.getNodeXML(xml,
                                                "//a:outer/a:b",
                                                namespaces),
                          ['<b xmlns="http://namespace">89</b>'])
        self.assertEquals(
            self.utils.getNodeXML(xml, "//a:outer/a:a/a:b", namespaces),
            ['<b xmlns="http://namespace">88</b>',
             '<b xmlns="http://namespace">87</b>'])
Exemplo n.º 9
0
class XMLUtilsTest(unittest.TestCase):
    def setUp(self):
        self.utils = XMLUtils()

    def test_parseXML(self):
        self.assertEqual(
            self.utils.parseXML(
                "<outer><inner a='90'>mytext1</inner><inner>mytext2</inner></outer>",
                "//outer/inner"), ['mytext1', 'mytext2'])
        self.assertEqual(
            self.utils.parseXML("<outer><inner>mytext1</inner></outer>",
                                "//outer/inner"), 'mytext1')

    def test_parseXMLAttributes(self):
        xml = "<outer><inner>mytext1</inner><inner b='23'>mytext2</inner></outer>"
        self.assertEqual(
            self.utils.parseXMLAttributes(xml, '//outer/inner', 'b'), None)
        self.assertEqual(
            self.utils.parseXMLAttributes(xml, '//outer/inner', 'b', True),
            ['23'])

    def test_getNodeXML(self):
        xml = "<outer><inner>mytext1</inner><inner b='23'>mytext2</inner><a><b>88</b><b>87</b></a><b>89</b></outer>"
        self.assertEquals(self.utils.getNodeXML(xml, "//outer/b"),
                          ['<b>89</b>'])
        self.assertEquals(self.utils.getNodeXML(xml, "//outer/a/b"),
                          ['<b>88</b>', '<b>87</b>'])

        xml = "<outer xmlns=\"http://namespace\"><inner>mytext1</inner><inner b='23'>mytext2</inner><a><b>88</b><b>87</b></a><b>89</b></outer>"
        namespaces = {'a': 'http://namespace'}
        self.assertEquals(
            self.utils.getNodeXML(xml, "//a:outer/a:b", namespaces),
            ['<b xmlns="http://namespace">89</b>'])
        self.assertEquals(
            self.utils.getNodeXML(xml, "//a:outer/a:a/a:b", namespaces), [
                '<b xmlns="http://namespace">88</b>',
                '<b xmlns="http://namespace">87</b>'
            ])
Exemplo n.º 10
0
 def setUp(self):
     self.utils = XMLUtils()
Exemplo n.º 11
0
 def setUp(self):
     self.utils = XMLUtils()