Permalink
Browse files

Merge pull request #81 from sudorandom/issue_80

Metadata Bug Fixes
  • Loading branch information...
2 parents 2503816 + 7f490e8 commit dee204bc56bd44640bc00a684fca8a6d91aac8d5 @CrackerJackMack CrackerJackMack committed Apr 5, 2013
Showing with 24 additions and 7 deletions.
  1. +4 −4 SoftLayer/CLI/modules/metadata.py
  2. +14 −3 SoftLayer/metadata.py
  3. +6 −0 SoftLayer/tests/API/metadata_tests.py
@@ -42,7 +42,7 @@ def execute(client, args):
class Datacenter(CLIRunnable):
"""
-usage: sl metadata name [options]
+usage: sl metadata datacenter [options]
Get datacenter name
"""
@@ -55,7 +55,7 @@ def execute(client, args):
class DatacenterId(CLIRunnable):
"""
-usage: sl metadata id [options]
+usage: sl metadata datacenter_id [options]
Get datacenter id
"""
@@ -208,7 +208,7 @@ def execute(client, args):
'mac addresses',
listing(network['mac_addresses'], separator=',')])
t.add_row([
- 'router', network['routers']])
+ 'router', network['router']])
t.add_row([
'vlans', listing(network['vlans'], separator=',')])
t.add_row([
@@ -225,7 +225,7 @@ def execute(client, args):
'mac addresses',
listing(network['mac_addresses'], separator=',')])
t.add_row([
- 'router', network['routers']])
+ 'router', network['router']])
t.add_row([
'vlans', listing(network['vlans'], separator=',')])
t.add_row([
View
@@ -72,6 +72,13 @@ def make_request(self, path):
except urllib2.HTTPError, e: # pragma: no cover
if e.code == 404:
return None
+
+ try:
+ content = json.loads(e.read())
+ raise SoftLayerAPIError(content['code'], content['error'])
+ except (ValueError, KeyError):
+ pass
+
raise SoftLayerAPIError(e.code, e.reason)
except urllib2.URLError, e:
raise SoftLayerAPIError(0, e.reason)
@@ -89,16 +96,20 @@ def get(self, name, param=None):
raise SoftLayerError('Unknown metadata attribute.')
call_details = self.attribs[name]
+ extension = '.json'
+ if self.attribs[name]['call'] == 'UserMetadata':
+ extension = '.txt'
+
if call_details.get('param_req'):
if not param:
raise SoftLayerError(
'Parameter required to get this attribute.')
- url = "%s/%s.json" % (self.attribs[name]['call'], param)
+ url = "%s/%s%s" % (self.attribs[name]['call'], param, extension)
else:
- url = "%s.json" % self.attribs[name]['call']
+ url = "%s%s" % (self.attribs[name]['call'], extension)
data = self.make_request(url)
- if data:
+ if data and extension == '.json':
return json.loads(data)
return data
@@ -42,6 +42,12 @@ def test_w_param(self):
self.make_request.assert_called_with("Vlans/1:2:3:4:5.json")
self.assertEqual([123], r)
+ def test_user_data(self):
+ self.make_request.return_value = 'user_data'
+ r = self.metadata.get('user_data')
+ self.make_request.assert_called_with("UserMetadata.txt")
+ self.assertEqual('user_data', r)
+
def test_return_none(self):
self.make_request.return_value = None
r = self.metadata.get('datacenter')

0 comments on commit dee204b

Please sign in to comment.