Skip to content

Commit 9cff949

Browse files
Merge pull request softlayer#648 from sudorandom/issue-485
Improves Virtual Reload
2 parents 1396b40 + 3715cd0 commit 9cff949

5 files changed

Lines changed: 47 additions & 13 deletions

File tree

SoftLayer/CLI/image/list.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,29 @@
1111

1212

1313
@click.command()
14+
@click.option('--name', default=None, help='Filter on image name')
1415
@click.option('--public/--private',
1516
is_flag=True,
1617
default=None,
1718
help='Display only public or private images')
1819
@environment.pass_env
19-
def cli(env, public):
20+
def cli(env, name, public):
2021
"""List images."""
2122

2223
image_mgr = SoftLayer.ImageManager(env.client)
2324

2425
images = []
2526
if public in [False, None]:
26-
for image in image_mgr.list_private_images(mask=image_mod.MASK):
27+
for image in image_mgr.list_private_images(name=name,
28+
mask=image_mod.MASK):
2729
images.append(image)
2830

2931
if public in [True, None]:
30-
for image in image_mgr.list_public_images(mask=image_mod.MASK):
32+
for image in image_mgr.list_public_images(name=name,
33+
mask=image_mod.MASK):
3134
images.append(image)
3235

33-
table = formatting.Table(['guid',
36+
table = formatting.Table(['id',
3437
'name',
3538
'type',
3639
'visibility',
@@ -42,7 +45,7 @@ def cli(env, public):
4245
visibility = (image_mod.PUBLIC_TYPE if image['publicFlag']
4346
else image_mod.PRIVATE_TYPE)
4447
table.add_row([
45-
image.get('globalIdentifier', formatting.blank()),
48+
image.get('id', formatting.blank()),
4649
formatting.FormattedItem(image['name'],
4750
click.wrap_text(image['name'], width=50)),
4851
formatting.FormattedItem(

SoftLayer/CLI/virt/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _parse_create_args(client, args):
145145
@click.option('--os', '-o',
146146
help="OS install code. Tip: you can specify <OS>_LATEST")
147147
@click.option('--image',
148-
help="Image GUID. See: 'slcli image list' for reference")
148+
help="Image ID. See: 'slcli image list' for reference")
149149
@click.option('--billing',
150150
type=click.Choice(['hourly', 'monthly']),
151151
default='hourly',

SoftLayer/CLI/virt/reload.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
@click.command()
1414
@click.argument('identifier')
1515
@click.option('--postinstall', '-i', help="Post-install script to download")
16+
@click.option(
17+
'--image',
18+
help="""Image ID. The default is to use the current operating system.
19+
See: 'slcli image list' for reference""")
1620
@helpers.multi_option('--key', '-k',
1721
help="SSH keys to add to the root user")
1822
@environment.pass_env
19-
def cli(env, identifier, postinstall, key):
23+
def cli(env, identifier, postinstall, key, image):
2024
"""Reload operating system on a virtual server."""
2125

2226
vsi = SoftLayer.VSManager(env.client)
@@ -30,4 +34,7 @@ def cli(env, identifier, postinstall, key):
3034
if not (env.skip_confirmations or formatting.no_going_back(vs_id)):
3135
raise exceptions.CLIAbort('Aborted')
3236

33-
vsi.reload_instance(vs_id, postinstall, keys)
37+
vsi.reload_instance(vs_id,
38+
post_uri=postinstall,
39+
ssh_keys=keys,
40+
image_id=image)

SoftLayer/managers/vs.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,21 @@ def cancel_instance(self, instance_id):
240240
"""
241241
return self.guest.deleteObject(id=instance_id)
242242

243-
def reload_instance(self, instance_id, post_uri=None, ssh_keys=None):
244-
"""Perform an OS reload of an instance with its current configuration.
243+
def reload_instance(self, instance_id,
244+
post_uri=None,
245+
ssh_keys=None,
246+
image_id=None):
247+
"""Perform an OS reload of an instance.
245248
246249
:param integer instance_id: the instance ID to reload
247250
:param string post_url: The URI of the post-install script to run
248251
after reload
249252
:param list ssh_keys: The SSH keys to add to the root user
253+
:param int image_id: The ID of the image to load onto the server
250254
251255
.. warning::
252-
Post-provision script MUST be HTTPS for it to be executed.
253256
This will reformat the primary drive.
257+
Post-provision script MUST be HTTPS for it to be executed.
254258
255259
Example::
256260
@@ -268,8 +272,11 @@ def reload_instance(self, instance_id, post_uri=None, ssh_keys=None):
268272
if ssh_keys:
269273
config['sshKeyIds'] = [key_id for key_id in ssh_keys]
270274

271-
return self.guest.reloadOperatingSystem('FORCE', config,
272-
id=instance_id)
275+
if image_id:
276+
config['imageTemplateId'] = image_id
277+
278+
return self.client.call('Virtual_Guest', 'reloadOperatingSystem',
279+
'FORCE', config, id=instance_id)
273280

274281
def _generate_create_dict(
275282
self, cpus=None, memory=None, hourly=True,

tests/managers/vs_tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ def test_cancel_instance(self):
126126
identifier=1)
127127

128128
def test_reload_instance(self):
129+
self.vs.reload_instance(1)
130+
131+
self.assert_called_with('SoftLayer_Virtual_Guest',
132+
'reloadOperatingSystem',
133+
args=('FORCE', {}),
134+
identifier=1)
135+
136+
def test_reload_instance_posturi_sshkeys(self):
129137
post_uri = 'http://test.sftlyr.ws/test.sh'
130138

131139
self.vs.reload_instance(1, post_uri=post_uri, ssh_keys=[1701])
@@ -137,6 +145,15 @@ def test_reload_instance(self):
137145
args=args,
138146
identifier=1)
139147

148+
def test_reload_instance_with_new_os(self):
149+
self.vs.reload_instance(1, image_id=1234)
150+
151+
args = ('FORCE', {'imageTemplateId': 1234})
152+
self.assert_called_with('SoftLayer_Virtual_Guest',
153+
'reloadOperatingSystem',
154+
args=args,
155+
identifier=1)
156+
140157
@mock.patch('SoftLayer.managers.vs.VSManager._generate_create_dict')
141158
def test_create_verify(self, create_dict):
142159
create_dict.return_value = {'test': 1, 'verify': 1}

0 commit comments

Comments
 (0)