Skip to content

Always excludes metadata disks from image capturing #776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ docs/_build/*
build/*
dist/*
*.egg-info
.cache

11 changes: 7 additions & 4 deletions SoftLayer/fixtures/SoftLayer_Virtual_Guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
"primaryNetworkComponent": {"speed": 10, "maxSpeed": 100},
'hourlyBillingFlag': False,
'createDate': '2013-08-01 15:23:45',
'blockDevices': [{"device": 0, 'mountType': 'Disk', "uuid": 1},
{"device": 1, 'mountType': 'Disk'},
{"device": 2, 'mountType': 'CD'},
{"device": 3, 'mountType': 'Disk', "uuid": 3}],
'blockDevices': [{'device': 0, 'mountType': 'Disk', "uuid": 1},
{'device': 1, 'mountType': 'Disk',
'diskImage': {'type': {'keyName': 'SWAP'}}},
{'device': 2, 'mountType': 'CD'},
{'device': 3, 'mountType': 'Disk', 'uuid': 3},
{'device': 4, 'mountType': 'Disk', 'uuid': 4,
'diskImage': {'metadataFlag': True}}],
'notes': 'notes',
'networkVlans': [{'networkSpace': 'PUBLIC',
'vlanNumber': 23,
Expand Down
41 changes: 32 additions & 9 deletions SoftLayer/managers/vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,19 +721,42 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
notes = "Some notes about this image"
result = mgr.capture(instance_id=12345, name=name, notes=notes)
"""
vsi = self.get_instance(instance_id)

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

disks = [block_device for block_device in vsi['blockDevices']
if disk_filter(block_device)]
disks_to_capture = []
for block_device in vsi['blockDevices']:

# We never want metadata disks
if utils.lookup(block_device, 'diskImage', 'metadataFlag'):
continue

# We never want swap devices
type_name = utils.lookup(block_device,
'diskImage',
'type',
'keyName')
if type_name == 'SWAP':
continue

# We never want CD images
if block_device['mountType'] == 'CD':
continue

# Only use the first block device if we don't want additional disks
if not additional_disks and str(block_device['device']) != '0':
continue

disks_to_capture.append(block_device)

return self.guest.createArchiveTransaction(
name, disks, notes, id=instance_id)
name, disks_to_capture, notes, id=instance_id)

def upgrade(self, instance_id, cpus=None, memory=None,
nic_speed=None, public=True):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
[tool:pytest]
python_files = *_tests.py

[wheel]
Expand Down
2 changes: 1 addition & 1 deletion tests/managers/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def test_captures(self):

expected = fixtures.SoftLayer_Virtual_Guest.createArchiveTransaction
self.assertEqual(result, expected)
args = ('a', [], None)
args = ('a', [{'device': 0, 'uuid': 1, 'mountType': 'Disk'}], None)
self.assert_called_with('SoftLayer_Virtual_Guest',
'createArchiveTransaction',
args=args,
Expand Down