Skip to content

Commit 5988719

Browse files
author
Kevin McDonald
committed
Automatically convert integer image ID to GUID on virtual create command
1 parent 2cf4ed5 commit 5988719

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

SoftLayer/CLI/virt/create.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ def _parse_create_args(client, args):
8181
data['os_code'] = args['os']
8282

8383
if args.get('image'):
84-
data['image_id'] = args['image']
84+
if args.get('image').isdigit():
85+
image_mgr = SoftLayer.ImageManager(client)
86+
image_details = image_mgr.get_image(args.get('image'),
87+
mask="id,globalIdentifier")
88+
data['image_id'] = image_details['globalIdentifier']
89+
else:
90+
data['image_id'] = args['image']
8591

8692
if args.get('datacenter'):
8793
data['datacenter'] = args['datacenter']

tests/CLI/modules/vs_tests.py

+35
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,41 @@ def test_create(self, confirm_mock):
134134
self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject',
135135
args=args)
136136

137+
@mock.patch('SoftLayer.CLI.formatting.confirm')
138+
def test_create_with_integer_image_id(self, confirm_mock):
139+
confirm_mock.return_value = True
140+
result = self.run_command(['vs', 'create',
141+
'--cpu=2',
142+
'--domain=example.com',
143+
'--hostname=host',
144+
'--image=12345',
145+
'--memory=1',
146+
'--network=100',
147+
'--billing=hourly',
148+
'--datacenter=dal05'])
149+
150+
self.assertEqual(result.exit_code, 0)
151+
self.assertEqual(json.loads(result.output),
152+
{'guid': '1a2b3c-1701',
153+
'id': 100,
154+
'created': '2013-08-01 15:23:45'})
155+
156+
args = ({
157+
'datacenter': {'name': 'dal05'},
158+
'domain': 'example.com',
159+
'hourlyBillingFlag': True,
160+
'localDiskFlag': True,
161+
'maxMemory': 1024,
162+
'hostname': 'host',
163+
'startCpus': 2,
164+
'blockDeviceTemplateGroup': {
165+
'globalIdentifier': '0B5DEAF4-643D-46CA-A695-CECBE8832C9D',
166+
},
167+
'networkComponents': [{'maxSpeed': '100'}]
168+
},)
169+
self.assert_called_with('SoftLayer_Virtual_Guest', 'createObject',
170+
args=args)
171+
137172
@mock.patch('SoftLayer.CLI.formatting.confirm')
138173
def test_dns_sync_both(self, confirm_mock):
139174
confirm_mock.return_value = True

0 commit comments

Comments
 (0)