Skip to content

Commit e52b098

Browse files
committed
Switch to modern network attributes
1 parent 8e1f9ea commit e52b098

7 files changed

Lines changed: 57 additions & 35 deletions

File tree

igvm/commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,11 @@ def change_address(
295295
)
296296

297297
new_address = ip_address(new_address)
298+
new_address_attr = 'ipv6'
299+
if new_address.version == 4:
300+
new_address_attr = 'ipv4'
298301

299-
if vm.dataset_obj['intern_ip'] == new_address:
302+
if vm.dataset_obj[new_address_attr] == new_address:
300303
raise ConfigError('New IP address is the same as the old one!')
301304

302305
if not vm.hypervisor.get_vlan_network(new_address) and not migrate:
@@ -859,7 +862,8 @@ def host_info(vm_hostname):
859862
'status',
860863
)),
861864
('Network', (
862-
'intern_ip',
865+
'ipv4',
866+
'ipv6',
863867
'mac_address',
864868
)),
865869
('Resources', (

igvm/drbd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def get_host_config(self):
185185
' }}'
186186
.format(
187187
host=self.hv.dataset_obj['hostname'],
188-
addr=self.hv.dataset_obj['intern_ip'],
188+
addr=self.hv.dataset_obj['ipv6'],
189189
port=self.get_device_port(),
190190
dm_minor=self.get_device_minor(),
191191
lv_name=self.lv_name,

igvm/hypervisor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def check_vm(self, vm, offline):
212212
)
213213

214214
# Proper VLAN?
215-
if not self.get_vlan_network(vm.dataset_obj['intern_ip']):
215+
if not self.get_vlan_network(vm.dataset_obj['ipv6']):
216216
raise HypervisorError(
217217
'Hypervisor "{}" does not support route_network "{}".'
218218
.format(self.fqdn, vm.route_network)

igvm/kvm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ def generate_domain_xml(hypervisor, vm):
388388
# VM, instead the VM is updated to the latest settings.
389389
# Every KVM setting should be configurable via Serveradmin anyway.
390390
props = DomainProperties(hypervisor, vm)
391-
vlan_network = hypervisor.get_vlan_network(vm.dataset_obj['intern_ip'])
391+
vlan_network = hypervisor.get_vlan_network(
392+
vm.dataset_obj.get('ipv6') or vm.dataset_obj.get('ipv4')
393+
)
392394

393395
config = {
394396
'name': vm.uid_name,

igvm/settings.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,31 +119,34 @@
119119

120120
IMAGE_PATH = '/tmp'
121121

122+
HOST_ATTRIBUTES = [
123+
'environment',
124+
'hostname',
125+
'igvm_locked',
126+
'ipv4',
127+
'ipv6',
128+
'os',
129+
'state',
130+
]
131+
122132
NETWORK_ATTRIBUTES = [
123133
'hostname',
124134
'service_groups',
125135
]
126136

127-
HYPERVISOR_ATTRIBUTES = [
137+
HYPERVISOR_ATTRIBUTES = HOST_ATTRIBUTES + [
128138
'ceph_disks',
129139
'cpu_perffactor',
130140
'cpu_util_pct',
131-
'environment',
132141
'hardware_model',
133-
'hostname',
134-
'igvm_locked',
135142
'igvm_migration_log',
136-
'intern_ip',
137143
'iops_avg',
138-
'igvm_migration_log',
139144
'libvirt_memory_total_gib',
140145
'libvirt_memory_used_gib',
141146
'libvirt_pool_total_gib',
142147
'libvirt_pool_used_gib',
143148
'num_cpu',
144-
'os',
145149
{'route_network': NETWORK_ATTRIBUTES},
146-
'state',
147150
{
148151
'vlan_networks': [
149152
'hostname',
@@ -170,7 +173,7 @@
170173
},
171174
]
172175

173-
VM_ATTRIBUTES = [
176+
VM_ATTRIBUTES = HOST_ATTRIBUTES + [
174177
'aws_image_id',
175178
'aws_instance_id',
176179
'aws_instance_type',
@@ -181,22 +184,16 @@
181184
'datacenter',
182185
'datacenter_type',
183186
'disk_size_gib',
184-
'environment',
185187
'function',
186188
'game_market',
187189
'game_type',
188190
'game_world',
189-
'hostname',
190-
'igvm_locked',
191-
'intern_ip',
192191
'io_weight',
193192
'libvirt_pool_override',
194193
'load_99',
195194
'mac',
196195
'memory',
197196
'num_cpu',
198-
'os',
199-
'primary_ip6',
200197
'project',
201198
{'project_network': NETWORK_ATTRIBUTES},
202199
'puppet_ca',
@@ -206,7 +203,6 @@
206203
'served_game',
207204
'service_groups',
208205
'sshfp',
209-
'state',
210206
{'hypervisor': HYPERVISOR_ATTRIBUTES},
211207
]
212208

igvm/vm.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def start(self, force_stop_failed=True, transaction=None):
363363
raise VMError('VM did not come online in time')
364364

365365
host_up = wait_until(
366-
str(self.dataset_obj['intern_ip']),
366+
str(self.dataset_obj['ipv6']),
367367
waitmsg='Waiting for SSH to respond',
368368
)
369369
if not host_up and force_stop_failed:
@@ -408,7 +408,7 @@ def aws_start(self):
408408
raise VMError(e)
409409

410410
host_up = wait_until(
411-
str(self.dataset_obj['intern_ip']),
411+
str(self.dataset_obj['ipv6']),
412412
waitmsg='Waiting for SSH to respond',
413413
)
414414

@@ -431,7 +431,7 @@ def aws_restart(self):
431431
raise VMError(e)
432432

433433
host_up = wait_until(
434-
str(self.dataset_obj['intern_ip']),
434+
str(self.dataset_obj['ipv6']),
435435
waitmsg='Waiting for SSH to respond',
436436
timeout=180
437437
)
@@ -647,7 +647,8 @@ def disk_free(self):
647647
def info(self):
648648
result = {
649649
'hypervisor': self.hypervisor.fqdn,
650-
'intern_ip': self.dataset_obj['intern_ip'],
650+
'ipv4': self.dataset_obj['ipv4'],
651+
'ipv6': self.dataset_obj['ipv6'],
651652
'num_cpu': self.dataset_obj['num_cpu'],
652653
'memory': self.dataset_obj['memory'],
653654
'disk_size_gib': self.dataset_obj['disk_size_gib'],
@@ -807,8 +808,8 @@ def aws_build(self,
807808
self.dataset_obj['aws_placement']
808809
)
809810
},
810-
PrivateIpAddress=str(self.dataset_obj['intern_ip']),
811-
Ipv6Addresses=[{'Ipv6Address':str(self.dataset_obj['primary_ip6'])}],
811+
PrivateIpAddress=str(self.dataset_obj['ipv4']),
812+
Ipv6Addresses=[{'Ipv6Address':str(self.dataset_obj['ipv6'])}],
812813
UserData='' if postboot is None else postboot,
813814
TagSpecifications=[
814815
{
@@ -1045,16 +1046,19 @@ def copy_postboot_script(self, script):
10451046
self.put('/buildvm-postboot', script, '0755')
10461047

10471048
def restore_address(self):
1048-
self.dataset_obj['intern_ip'] = self.old_address
1049+
self.dataset_obj['ipv4'] = self.old_address_ipv4
1050+
self.dataset_obj['ipv6'] = self.old_address_ipv6
10491051
self.dataset_obj.commit()
10501052
self.route_network = self.old_network
10511053

1052-
def change_address(self, new_address, new_network, transaction=None):
1054+
def change_address(self, new_address_ipv4, new_address_ipv6, new_network, transaction=None):
10531055
# All queries to Serveradmin are kept in commands.py.
10541056
# That's why this metod receives both new address and new network.
1055-
self.old_address = self.dataset_obj['intern_ip']
1057+
self.old_address_ipv4 = self.dataset_obj['ipv4']
1058+
self.old_address_ipv6 = self.dataset_obj['ipv6']
10561059
self.old_network = self.route_network
1057-
self.dataset_obj['intern_ip'] = new_address
1060+
self.dataset_obj['ipv4'] = new_address_ipv4
1061+
self.dataset_obj['ipv6'] = new_address_ipv6
10581062
self.dataset_obj.commit()
10591063
self.route_network = new_network
10601064

tests/test_integration.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from adminapi import api
1313
from adminapi.dataset import Query
14-
from adminapi.filters import Any
14+
from adminapi.filters import Any, Not
1515
from fabric.api import env
1616
from fabric.network import disconnect_all
1717
from mock import patch
@@ -731,12 +731,28 @@ def test_new_address(self):
731731
# We don't have a way to ask for new IP address from Serveradmin
732732
# and lock it for us. The method below will usually work fine.
733733
# When it starts failing, we must develop retry method.
734-
new_address = get_next_address(VM_NET, 2, 'ipv4')
734+
735+
# First figure out if the network in which the tests are run
736+
# is IPv6-only or dual-stack. For dual-stack networks we must
737+
# use IPv4 and IPv6 will be auto-assigned.
738+
ip_attr = 'ipv4'
739+
test_net = Query(
740+
{
741+
'servertype': 'route_network',
742+
'state': Not('retired'),
743+
'hostname': VM_NET,
744+
},
745+
['hostname', 'ipv4', 'ipv6'],
746+
).get()
747+
if not test_net['ipv4']:
748+
ip_attr = 'ipv6'
749+
750+
new_address = get_next_address(VM_NET, 2, ip_attr)
735751

736752
change_address(VM_HOSTNAME, new_address, offline=True)
737753

738-
obj = Query({'hostname': VM_HOSTNAME}, ['intern_ip']).get()
739-
self.assertEqual(obj['intern_ip'], new_address)
754+
obj = Query({'hostname': VM_HOSTNAME}, [ip_attr]).get()
755+
self.assertEqual(obj[ip_attr], new_address)
740756
with _get_vm(VM_HOSTNAME) as vm:
741757
vm.run(cmd('ip a | grep {}', new_address))
742758
self.check_vm_present()

0 commit comments

Comments
 (0)