Skip to content

Commit 483b106

Browse files
Merge pull request #886 from allmightyspiff/issues885
Issues885
2 parents fc8d42c + 34cd23a commit 483b106

File tree

5 files changed

+45
-52
lines changed

5 files changed

+45
-52
lines changed

SoftLayer/CLI/hardware/power.py

+17
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,20 @@ def power_cycle(env, identifier):
7777
raise exceptions.CLIAbort('Aborted.')
7878

7979
env.client['Hardware_Server'].powerCycle(id=hw_id)
80+
81+
82+
@click.command()
83+
@click.argument('identifier')
84+
@environment.pass_env
85+
def rescue(env, identifier):
86+
"""Reboot server into a rescue image."""
87+
88+
mgr = SoftLayer.HardwareManager(env.client)
89+
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
90+
91+
if not (env.skip_confirmations or
92+
formatting.confirm("This action will reboot this server. Continue?")):
93+
94+
raise exceptions.CLIAbort('Aborted')
95+
96+
env.client['Hardware_Server'].bootToRescueLayer(id=hw_id)

SoftLayer/CLI/hardware/rescue.py

-28
This file was deleted.

SoftLayer/CLI/routes.py

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
('hardware:reload', 'SoftLayer.CLI.hardware.reload:cli'),
211211
('hardware:credentials', 'SoftLayer.CLI.hardware.credentials:cli'),
212212
('hardware:update-firmware', 'SoftLayer.CLI.hardware.update_firmware:cli'),
213+
('hardware:rescue', 'SoftLayer.CLI.hardware.power:rescue'),
213214

214215
('securitygroup', 'SoftLayer.CLI.securitygroup'),
215216
('securitygroup:list', 'SoftLayer.CLI.securitygroup.list:cli'),

SoftLayer/transports.py

+10-24
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ def __init__(self, items, total_count):
9999

100100
class XmlRpcTransport(object):
101101
"""XML-RPC transport."""
102-
def __init__(self,
103-
endpoint_url=None,
104-
timeout=None,
105-
proxy=None,
106-
user_agent=None,
107-
verify=True):
102+
def __init__(self, endpoint_url=None, timeout=None, proxy=None, user_agent=None, verify=True):
108103

109104
self.endpoint_url = (endpoint_url or
110105
consts.API_PUBLIC_ENDPOINT).rstrip('/')
@@ -202,19 +197,13 @@ def __call__(self, request):
202197
class RestTransport(object):
203198
"""REST transport.
204199
205-
Currently only supports GET requests (no POST, PUT, DELETE) and lacks
206-
support for masks, filters, limits and offsets.
200+
REST calls should mostly work, but is not fully tested.
201+
XML-RPC should be used when in doubt
207202
"""
208203

209-
def __init__(self,
210-
endpoint_url=None,
211-
timeout=None,
212-
proxy=None,
213-
user_agent=None,
214-
verify=True):
204+
def __init__(self, endpoint_url=None, timeout=None, proxy=None, user_agent=None, verify=True):
215205

216-
self.endpoint_url = (endpoint_url or
217-
consts.API_PUBLIC_ENDPOINT_REST).rstrip('/')
206+
self.endpoint_url = (endpoint_url or consts.API_PUBLIC_ENDPOINT_REST).rstrip('/')
218207
self.timeout = timeout or None
219208
self.proxy = proxy
220209
self.user_agent = user_agent or consts.USER_AGENT
@@ -223,12 +212,12 @@ def __init__(self,
223212
def __call__(self, request):
224213
"""Makes a SoftLayer API call against the REST endpoint.
225214
226-
This currently only works with GET requests
215+
REST calls should mostly work, but is not fully tested.
216+
XML-RPC should be used when in doubt
227217
228218
:param request request: Request object
229219
"""
230-
request.transport_headers.setdefault('Content-Type',
231-
'application/json')
220+
request.transport_headers.setdefault('Content-Type', 'application/json')
232221
request.transport_headers.setdefault('User-Agent', self.user_agent)
233222

234223
params = request.headers.copy()
@@ -252,9 +241,8 @@ def __call__(self, request):
252241
)
253242

254243
method = REST_SPECIAL_METHODS.get(request.method)
255-
is_special_method = True
244+
256245
if method is None:
257-
is_special_method = False
258246
method = 'GET'
259247

260248
body = {}
@@ -272,9 +260,7 @@ def __call__(self, request):
272260
if request.identifier is not None:
273261
url_parts.append(str(request.identifier))
274262

275-
# Special methods (createObject, editObject, etc) use the HTTP verb
276-
# to determine the action on the resource
277-
if request.method is not None and not is_special_method:
263+
if request.method is not None:
278264
url_parts.append(request.method)
279265

280266
url = '%s.%s' % ('/'.join(url_parts), 'json')

tests/CLI/modules/server_tests.py

+17
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,20 @@ def test_edit(self):
445445
args=(100,),
446446
identifier=100,
447447
)
448+
449+
@mock.patch('SoftLayer.CLI.formatting.confirm')
450+
def test_rescue(self, confirm_mock):
451+
confirm_mock.return_value = True
452+
result = self.run_command(['server', 'rescue', '1000'])
453+
454+
self.assert_no_fail(result)
455+
self.assertEqual(result.output, "")
456+
self.assert_called_with('SoftLayer_Hardware_Server', 'bootToRescueLayer', identifier=1000)
457+
458+
@mock.patch('SoftLayer.CLI.formatting.confirm')
459+
def test_server_rescue_negative(self, confirm_mock):
460+
confirm_mock.return_value = False
461+
result = self.run_command(['server', 'rescue', '1000'])
462+
463+
self.assertEqual(result.exit_code, 2)
464+
self.assertIsInstance(result.exception, exceptions.CLIAbort)

0 commit comments

Comments
 (0)