Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Metadata Bug Fixes #81

Merged
merged 2 commits into from

2 participants

@sudorandom
Collaborator

Resolves issue #80

$ sl my network public
:...............:...................:
:          Name : Value             :
:...............:...................:
: mac addresses : 06:8a:0d:8c:d8:80 :
:        router : fcr04.dal05       :
:         vlans : 1134              :
:      vlan ids : 236267            :
:...............:...................:
$ sl my datacenter
dal05
$ sl my user_data
No user metadata.
$ echo $?
2
  • Since the REST API gives errors (if you're using json) in json format, I made make_request raise an exception (if it can) based on the json body instead of just HTTP Error codes.
  • Fixed datacenter CLI doc block
  • Fixed datacenter_id CLI doc block
  • Improves user_metadata error when there is no metadata
  • Fixes typo/refactor issue that broke sl my network public/private
@CrackerJackMack CrackerJackMack merged commit dee204b into softlayer:master
@CrackerJackMack CrackerJackMack referenced this pull request
Closed

metadata is broken #80

@sudorandom sudorandom deleted the sudorandom:issue_80 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2013
  1. @sudorandom

    Metadata Bug Fixes

    sudorandom authored
  2. @sudorandom

    Adds coverage tests to fix

    sudorandom authored
This page is out of date. Refresh to see the latest.
View
8 SoftLayer/CLI/modules/metadata.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
17 SoftLayer/metadata.py
@@ -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
View
6 SoftLayer/tests/API/metadata_tests.py
@@ -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')
Something went wrong with that request. Please try again.