Commit 2d5162ce authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Simple code refactoring

parent 798393b8
......@@ -108,8 +108,8 @@ def nic_to_dict(nic):
d = {'id': util.construct_nic_id(nic),
'network_id': str(nic.network.id),
'mac_address': nic.mac,
'ipv4': nic.ipv4 if nic.ipv4 else None,
'ipv6': nic.ipv6 if nic.ipv6 else None,
'ipv4': nic.ipv4,
'ipv6': nic.ipv6,
'OS-EXT-IPS:type': ip_type}
if nic.firewall_profile:
......
......@@ -231,7 +231,7 @@ def _process_net_status(vm, etime, nics):
vm.nics.all().delete()
for nic in ganeti_nics:
ipv4 = nic.get('ipv4', '')
ipv4 = nic["ipv4"]
net = nic['network']
if ipv4:
net.reserve_address(ipv4)
......@@ -257,15 +257,12 @@ def process_ganeti_nics(ganeti_nics):
net = Network.objects.get(pk=pk)
# Get the new nic info
mac = new_nic.get('mac', '')
ipv4 = new_nic.get('ip', '')
if net.subnet6:
ipv6 = mac2eui64(mac, net.subnet6)
else:
ipv6 = ''
firewall = new_nic.get('firewall', '')
firewall_profile = _reverse_tags.get(firewall, '')
mac = new_nic.get('mac')
ipv4 = new_nic.get('ip')
ipv6 = mac2eui64(mac, net.subnet6) if net.subnet6 is not None else None
firewall = new_nic.get('firewall')
firewall_profile = _reverse_tags.get(firewall)
if not firewall_profile and net.public:
firewall_profile = settings.DEFAULT_FIREWALL_PROFILE
......
......@@ -470,14 +470,14 @@ class UpdateNetTest(TestCase):
nics = db_vm.nics.all()
self.assertEqual(len(nics), 1)
self.assertEqual(nics[0].index, 0)
self.assertEqual(nics[0].ipv4, '')
self.assertEqual(nics[0].ipv6, '')
self.assertEqual(nics[0].mac, '')
self.assertEqual(nics[0].ipv4, None)
self.assertEqual(nics[0].ipv6, None)
self.assertEqual(nics[0].mac, None)
if public:
self.assertEqual(nics[0].firewall_profile,
settings.DEFAULT_FIREWALL_PROFILE)
else:
self.assertEqual(nics[0].firewall_profile, '')
self.assertEqual(nics[0].firewall_profile, None)
def test_full_nic(self, client):
vm = mfactory.VirtualMachineFactory(operstate='ERROR')
......@@ -496,7 +496,7 @@ class UpdateNetTest(TestCase):
self.assertEqual(len(nics), 1)
self.assertEqual(nics[0].index, 0)
self.assertEqual(nics[0].ipv4, '10.0.0.22')
self.assertEqual(nics[0].ipv6, '')
self.assertEqual(nics[0].ipv6, None)
self.assertEqual(nics[0].mac, 'aa:bb:cc:00:11:22')
pool = net.get_pool()
self.assertFalse(pool.is_available('10.0.0.22'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment