Beispiel #1
0
    def testHost(self):
        # Create a host and check the etag also
        result = Host.create('api-test', '2.3.4.5')
        self.assertTrue(result.href.startswith('http'))

        # Get Etag
        host = Host('api-test')
        self.assertIsNotNone(host.etag)

        self.assertEqual(host.address, '2.3.4.5')

        self.assertEqual(host.data.get('address'), '2.3.4.5')
        host.modify_attribute(address='1.1.1.1')
        self.assertEqual(host.data.get('address'), '1.1.1.1')
        host.secondary = ['8.8.8.8', '9.9.9.9']
        for ip in host.secondary:
            self.assertIn(ip, ['8.8.8.8', '9.9.9.9'])
        host.ipv6_address = '2001:0db8:85a3:0000:0000:8a2e:0370:7334'
        self.assertEqual(host.ipv6_address,
                         '2001:0db8:85a3:0000:0000:8a2e:0370:7334')
        host.add_secondary(address=['25.25.25.25'], append_lists=True)

        self.assertIn('25.25.25.25', host.data.get('secondary'))

        with self.assertRaises(AttributeError):
            host.foobarattribute

        host.rename('renamedhost')
        self.assertEqual(host.data.get('name'),
                         'renamedhost')  # Cache refreshed
        host.update(etag=host.etag, name='anothername')
        self.assertEqual(host.name, 'anothername')

        host.delete()
Beispiel #2
0
 def test_get_resource_link_before_cache_called(self):
     Host.create(name='cachehost', address='1.1.1.1')
     h = Host('cachehost')
     self.assertFalse(vars(h).get('_cache'))
     h.data
     cache = vars(h).get('data')
     self.assertIsInstance(cache, SimpleElement)
     h.delete()
Beispiel #3
0
    def test_ipv6host(self):
        result = Host.create(name='mixedhost',
                             ipv6_address='2001:cdba::3257:9652')
        self.assertTrue(result.href.startswith('http'))

        host = Host('mixedhost')
        self.assertEqual(host.ipv6_address, '2001:cdba::3257:9652')
        host.delete()
Beispiel #4
0
    def test_ipv6_address_with_secondary_ipv4(self):
        result = Host.create(name='mixedhost',
                             ipv6_address='2001:cdba::3257:9652',
                             secondary=['1.1.1.1'])
        self.assertTrue(result.href.startswith('http'))

        host = Host('mixedhost')
        self.assertEqual(host.ipv6_address, '2001:cdba::3257:9652')
        self.assertIn('1.1.1.1', host.secondary)
        host.delete()
Beispiel #5
0
    def test_export_element(self):
        # Test exporting a non-system element, should just return href
        result = Host.create('api-export-test', '2.3.4.5')
        self.assertTrue(result.href.startswith('http'))
        host = Host('api-export-test')
        self.assertIsInstance(host.export(), DownloadTask)

        with self.assertRaises(TaskRunFailed):
            host.export(filename='/foo').wait()

        host.delete()
Beispiel #6
0
    def test_Expression(self):
        # Test creating an expression

        Host.create('host9', '9.9.9.9')
        Host.create('host10', '10.10.10.10')
        host9 = Host('host9')
        host10 = Host('host10')
        sub_expression = Expression.build_sub_expression(
            name='mytestexporession',
            ne_ref=[host9.href, host10.href],
            operator='union')

        expression = Expression.create(name='pythonexpression',
                                       ne_ref=[],
                                       sub_expression=sub_expression)
        self.assertTrue(expression.href.startswith('http'))
        expr = Expression('pythonexpression')
        expr.delete()
        host9.delete()
        host10.delete()