Skip to content

Commit b205067

Browse files
authored
Always excludes metadata disks from image capturing (#776)
* Fixed metadata disk exclusion issue in vs capture command. (#723) * Always excludes metadata disks from image capturing (fixes #723) * Fix a test issue where the types might not match in reality * Filter caputer images by type being SWAP
1 parent 7aca9ce commit b205067

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ docs/_build/*
1212
build/*
1313
dist/*
1414
*.egg-info
15+
.cache
16+

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
"primaryNetworkComponent": {"speed": 10, "maxSpeed": 100},
3434
'hourlyBillingFlag': False,
3535
'createDate': '2013-08-01 15:23:45',
36-
'blockDevices': [{"device": 0, 'mountType': 'Disk', "uuid": 1},
37-
{"device": 1, 'mountType': 'Disk'},
38-
{"device": 2, 'mountType': 'CD'},
39-
{"device": 3, 'mountType': 'Disk', "uuid": 3}],
36+
'blockDevices': [{'device': 0, 'mountType': 'Disk', "uuid": 1},
37+
{'device': 1, 'mountType': 'Disk',
38+
'diskImage': {'type': {'keyName': 'SWAP'}}},
39+
{'device': 2, 'mountType': 'CD'},
40+
{'device': 3, 'mountType': 'Disk', 'uuid': 3},
41+
{'device': 4, 'mountType': 'Disk', 'uuid': 4,
42+
'diskImage': {'metadataFlag': True}}],
4043
'notes': 'notes',
4144
'networkVlans': [{'networkSpace': 'PUBLIC',
4245
'vlanNumber': 23,

SoftLayer/managers/vs.py

+32-9
Original file line numberDiff line numberDiff line change
@@ -721,19 +721,42 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
721721
notes = "Some notes about this image"
722722
result = mgr.capture(instance_id=12345, name=name, notes=notes)
723723
"""
724-
vsi = self.get_instance(instance_id)
725724

726-
disk_filter = lambda x: x['device'] == '0'
727-
# Skip disk 1 (swap partition) and CD mounts
728-
if additional_disks:
729-
disk_filter = lambda x: (str(x['device']) != '1' and
730-
x['mountType'] != 'CD')
725+
vsi = self.client.call(
726+
'Virtual_Guest',
727+
'getObject',
728+
id=instance_id,
729+
mask="""id,
730+
blockDevices[id,device,mountType,
731+
diskImage[id,metadataFlag,type[keyName]]]""")
731732

732-
disks = [block_device for block_device in vsi['blockDevices']
733-
if disk_filter(block_device)]
733+
disks_to_capture = []
734+
for block_device in vsi['blockDevices']:
735+
736+
# We never want metadata disks
737+
if utils.lookup(block_device, 'diskImage', 'metadataFlag'):
738+
continue
739+
740+
# We never want swap devices
741+
type_name = utils.lookup(block_device,
742+
'diskImage',
743+
'type',
744+
'keyName')
745+
if type_name == 'SWAP':
746+
continue
747+
748+
# We never want CD images
749+
if block_device['mountType'] == 'CD':
750+
continue
751+
752+
# Only use the first block device if we don't want additional disks
753+
if not additional_disks and str(block_device['device']) != '0':
754+
continue
755+
756+
disks_to_capture.append(block_device)
734757

735758
return self.guest.createArchiveTransaction(
736-
name, disks, notes, id=instance_id)
759+
name, disks_to_capture, notes, id=instance_id)
737760

738761
def upgrade(self, instance_id, cpus=None, memory=None,
739762
nic_speed=None, public=True):

tests/managers/vs_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def test_captures(self):
615615

616616
expected = fixtures.SoftLayer_Virtual_Guest.createArchiveTransaction
617617
self.assertEqual(result, expected)
618-
args = ('a', [], None)
618+
args = ('a', [{'device': 0, 'uuid': 1, 'mountType': 'Disk'}], None)
619619
self.assert_called_with('SoftLayer_Virtual_Guest',
620620
'createArchiveTransaction',
621621
args=args,

0 commit comments

Comments
 (0)