示例#1
0
 def test_delete_subnet(self):
     """Delete a subnet; return True"""
     subnet = '172.16.4.1'
     mask = 24
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     self.assertTrue(sub.delete())
示例#2
0
文件: test_ip.py 项目: mattmb/spoke
 def test_delete_subnet(self):
     """Delete a subnet; return True"""
     subnet = '172.16.4.1'
     mask = 24
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     self.assertTrue(sub.delete())
示例#3
0
文件: test_ip.py 项目: mattmb/spoke
 def test_get_empty_subnet_ip_info(self):
     """Get a non-existent subnet's free/aloc IP status; return empty list"""
     ip = '172.16.3.1'
     mask = 24
     expected_result = []
     sub = SpokeSubnet(ip, mask)
     result = sub.get()['data']
     self.assertEqual(result, expected_result)
示例#4
0
文件: ip.py 项目: KrisSaxton/spoke
def release(network, mask, ip):
    try:
        conf = _spoke_config(_salt_config('config'))
        subnet = SpokeSubnet(ip=network, mask=mask, dc=None)
        result = subnet.modify(release=ip, reserve=None)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
示例#5
0
 def test_get_empty_subnet_ip_info(self):
     """Get a non-existent subnet's free/aloc IP status; return empty list"""
     ip = '172.16.3.1'
     mask = 24
     expected_result = []
     sub = SpokeSubnet(ip, mask)
     result = sub.get()['data']
     self.assertEqual(result, expected_result)
示例#6
0
def release(network, mask, ip):
    try:
        from spoke.lib.ip import SpokeSubnet
        subnet = SpokeSubnet(ip=network, mask=mask, dc=None)
        result = subnet.modify(release=ip, reserve=None)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
示例#7
0
文件: ip.py 项目: KrisSaxton/spoke
def delete(network, mask):
    try:
        conf = _spoke_config(_salt_config('config'))
        subnet = SpokeSubnet(ip=network, mask=mask, dc=None)
        result = subnet.delete()
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
示例#8
0
 def test_reserve_ip_from_exhausted_subnet(self):
     """Request an ip from an exhausted subnet; raise InsufficientResouce."""
     subnet = '172.16.1.1'
     mask = '30'
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     self.assertRaises(error.InsufficientResource, sub.modify, reserve=3)
     sub.delete()
示例#9
0
def delete(network, mask):
    try:
        from spoke.lib.ip import SpokeSubnet
        subnet = SpokeSubnet(ip=network, mask=mask, dc=None)
        result = subnet.delete()
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
示例#10
0
文件: test_ip.py 项目: mattmb/spoke
 def test_create_subnet_mask_string(self):
     """Create a subnet with a mask as string; return True"""
     subnet = '10.0.0.0'
     mask = '30'
     expected_result = [(subnet, {'aloc': [0], 'free': [2]})]
     sub = SpokeSubnet(subnet, mask)
     result = sub.create()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#11
0
 def test_create_subnet(self):
     """Create a subnet object; return results object."""
     subnet = '10.0.0.0'
     mask = 30
     expected_result = [(subnet, {'aloc': [0], 'free': [2]})]
     sub = SpokeSubnet(subnet, mask)
     result = sub.create()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#12
0
文件: test_ip.py 项目: mattmb/spoke
 def test_create_subnet(self):
     """Create a subnet object; return results object."""
     subnet = '10.0.0.0'
     mask = 30
     expected_result = [(subnet, {'aloc': [0], 'free': [2]})]
     sub = SpokeSubnet(subnet, mask)
     result = sub.create()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#13
0
 def test_create_subnet_mask_string(self):
     """Create a subnet with a mask as string; return True"""
     subnet = '10.0.0.0'
     mask = '30'
     expected_result = [(subnet, {'aloc': [0], 'free': [2]})]
     sub = SpokeSubnet(subnet, mask)
     result = sub.create()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#14
0
 def test_release_ip_twice_from_subnet(self):
     """Release an ip twice from a subnet; return True."""
     ip = '172.16.2.1'
     mask = '30'
     sub = SpokeSubnet(ip, mask)
     sub.create()
     sub.modify(reserve=2)
     sub.modify(release='172.16.1.2')
     self.assertTrue(sub.modify(release='172.16.1.2'))
     sub.delete()
示例#15
0
文件: test_ip.py 项目: mattmb/spoke
 def test_create_subnet_with_dc_prefix(self):
     """Create a subnet with a data centre prefix; return True."""
     dc = 'dc1'
     subnet = '10.0.0.0'
     mask = 30
     expected_result = [(dc + subnet, {'aloc': [0], 'free': [2]})]
     sub = SpokeSubnet(subnet, mask, dc)
     result = sub.create()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#16
0
 def test_create_subnet_with_dc_prefix(self):
     """Create a subnet with a data centre prefix; return True."""
     dc = 'dc1'
     subnet = '10.0.0.0'
     mask = 30
     expected_result = [(dc + subnet, {'aloc': [0], 'free': [2]})]
     sub = SpokeSubnet(subnet, mask, dc)
     result = sub.create()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#17
0
 def test_free_aloc_release_ip_from_subnet(self):
     """Release an ip from a subnet; verify free/aloc addresses."""
     ip = '172.16.1.1'
     network = '172.16.1.0'
     mask = '30'
     expected_result = [(network, {'free': [1], 'aloc': [1]})]
     sub = SpokeSubnet(ip, mask)
     sub.create()
     sub.modify(reserve=2)
     sub.modify(release='172.16.1.2')
     result = sub.get()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#18
0
文件: test_ip.py 项目: mattmb/spoke
 def test_free_aloc_reserve_ip_from_subnet(self):
     """Request an ip from a subnet; verify free/aloc addresses."""
     ip = '172.16.1.1'
     network = '172.16.1.0'
     mask = '30'
     expected_result = [(network, {'free': [1], 'aloc': [1]})]
     sub = SpokeSubnet(ip, mask)
     sub.create()
     sub.modify(reserve=1)
     result = sub.get()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#19
0
文件: test_ip.py 项目: mattmb/spoke
 def test_release_ip_from_subnet(self):
     """Release an ip from a subnet; return a results object."""
     subnet = '172.16.2.1'
     network = '172.16.2.0'
     mask = '30'
     expected_result = [(network, {'free': [1], 'aloc': [2]})]
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     sub.modify(reserve=2)
     result = sub.modify(release='172.16.1.2')['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#20
0
 def test_release_ip_from_subnet(self):
     """Release an ip from a subnet; return a results object."""
     subnet = '172.16.2.1'
     network = '172.16.2.0'
     mask = '30'
     expected_result = [(network, {'free': [1], 'aloc': [2]})]
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     sub.modify(reserve=2)
     result = sub.modify(release='172.16.1.2')['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#21
0
文件: test_ip.py 项目: mattmb/spoke
 def test_len_reserve_single_ip_from_subnet(self):
     """Request an ip from a subnet; return a single IP address as list."""
     subnet = '172.16.1.1'
     mask = '30'
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     result = sub.modify(reserve=1)['data']
     self.assertEquals(len(result), 1)
     sub.delete()
示例#22
0
文件: test_ip.py 项目: mattmb/spoke
 def test_get_subnet_ip_info(self):
     """Get a subnet's free and aloc IP status; return as list"""
     ip = '172.16.1.1'
     network = '172.16.1.0'
     mask = 24
     expected_result = [(network, {'free': [254], 'aloc': [0]})]
     sub = SpokeSubnet(ip, mask)
     sub.create()
     result = sub.get()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#23
0
文件: test_ip.py 项目: mattmb/spoke
 def test_reserve_ip_from_exhausted_subnet(self):
     """Request an ip from an exhausted subnet; raise InsufficientResouce."""
     subnet = '172.16.1.1'
     mask = '30'
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     self.assertRaises(error.InsufficientResource, sub.modify, reserve=3)
     sub.delete()
示例#24
0
 def test_len_reserve_single_ip_from_subnet(self):
     """Request an ip from a subnet; return a single IP address as list."""
     subnet = '172.16.1.1'
     mask = '30'
     sub = SpokeSubnet(subnet, mask)
     sub.create()
     result = sub.modify(reserve=1)['data']
     self.assertEquals(len(result), 1)
     sub.delete()
示例#25
0
 def test_get_subnet_ip_info(self):
     """Get a subnet's free and aloc IP status; return as list"""
     ip = '172.16.1.1'
     network = '172.16.1.0'
     mask = 24
     expected_result = [(network, {'free': [254], 'aloc': [0]})]
     sub = SpokeSubnet(ip, mask)
     sub.create()
     result = sub.get()['data']
     self.assertEqual(result, expected_result)
     sub.delete()
示例#26
0
文件: test_ip.py 项目: mattmb/spoke
 def test_delete_missing_subnet(self):
     """Delete a missing subnet; raise NotFound"""
     subnet = '172.16.5.1'
     mask = 24
     sub = SpokeSubnet(subnet, mask)
     self.assertRaises(error.NotFound, sub.delete)
示例#27
0
文件: test_ip.py 项目: mattmb/spoke
 def test_release_ip_twice_from_subnet(self):
     """Release an ip twice from a subnet; return True."""
     ip = '172.16.2.1'
     mask = '30'
     sub = SpokeSubnet(ip, mask)
     sub.create()
     sub.modify(reserve=2)
     sub.modify(release='172.16.1.2')
     self.assertTrue(sub.modify(release='172.16.1.2'))
     sub.delete()
示例#28
0
文件: test_ip.py 项目: mattmb/spoke
 def setUp(self):
     sub = SpokeSubnet(self.subnet, self.mask)
     sub.create()
示例#29
0
文件: test_ip.py 项目: mattmb/spoke
 def tearDown(self):
     sub = SpokeSubnet(self.subnet, self.mask)
     sub.delete()
示例#30
0
文件: test_ip.py 项目: mattmb/spoke
 def test_create_subnet_too_large(self):
     """Create a subnet larger than /16; raise InputError"""
     subnet = '10.0.0.0'
     mask = 8
     sub = SpokeSubnet(subnet, mask)
     self.assertRaises(error.InputError, sub.create)
示例#31
0
 def tearDown(self):
     sub = SpokeSubnet(self.subnet, self.mask)
     sub.delete()
示例#32
0
 def setUp(self): 
     sub = SpokeSubnet(self.subnet, self.mask)
     sub.create()
示例#33
0
文件: mc_subnet.py 项目: mattmb/spoke
 mask = request['data']['mask']
 try:
     dc = request['data']['dc']
 except KeyError:
     dc = None
 try:
     qty = request['data']['qty']
 except KeyError:
     qty = 1
 try:
     ip = request['data']['ip']
 except KeyError:
     ip = None
 if request['action'] == 'search':
     try:
         mc.data = SpokeSubnet(network, mask, dc).get()['data']
     except Exception as e:
         mc.fail(e.msg, e.exit_code)
 elif request['action'] == 'reserve':
     try:
         mc.data = SpokeSubnet(network, mask,
                               dc).modify(reserve=qty)['data']
     except Exception as e:
         mc.fail(e.msg, e.exit_code)
 elif request['action'] == 'release':
     try:
         mc.data = SpokeSubnet(network, mask, dc).modify(release=ip)['data']
     except Exception as e:
         mc.fail(e.msg, e.exit_code)
 else:
     msg = "Unknown action: " + request['action']