Skip to content

Commit

Permalink
Merge pull request apache#3 from rphillips/monitoring
Browse files Browse the repository at this point in the history
Notification Plan Bug Fix
  • Loading branch information
pquerna committed Sep 28, 2011
2 parents e2f1cfd + 5cbcc65 commit fff45bc
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions libcloud/monitoring/drivers/rackspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ def _to_entity(self, entity):
return Entity(id=entity['key'], name=entity['label'], extra=entity['metadata'], driver=self, ip_addresses = ips)

def _to_notification_plan(self, notification_plan):
error_state = notification_plan.get('error_state', [])
warning_state = notification_plan.get('warning_state', [])
ok_state = notification_plan.get('ok_state', [])
return NotificationPlan(id=notification_plan['key'], name=notification_plan['name'],
error_state=notification_plan['error_state'], warning_state=notification_plan['warning_state'],
ok_state=notification_plan['ok_state'], driver=self)
error_state=error_state, warning_state=warning_state, ok_state=ok_state,
driver=self)

def _to_entity_list(self, response):
# @TODO: Handle more then 10k containers - use "lazy list"?
Expand All @@ -195,6 +198,14 @@ def _to_entity_list(self, response):
entities.append(self._to_entity(entity))
return entities

def _to_notification_plan_list(self, response):
notification_plans = []

for notification_plan in response:
notification_plans.append(self._to_notification_plan(notification_plan))

return notification_plans

def list_check_types(self):
resp = self.connection.request("/check_types",
method='GET')
Expand Down Expand Up @@ -241,17 +252,19 @@ def create_notification(self, **kwargs):
else:
raise LibcloudError('Unexpected status code: %s' % (response.status))

def delete_notification_plans(self, notification_plan):
resp = self.connection.request("/notifications_plans/%s" % (notification_plan.id),
method='DELETE')
def delete_notification_plan(self, notification_plan):
resp = self.connection.request("/notification_plans/%s" % (notification_plan.id), method='DELETE')
return resp.status == httplib.NO_CONTENT


def list_notification_plans(self):
resp = self.connection.request("/notification_plans",
response = self.connection.request("/notification_plans",
method='GET')
print resp.object
return resp.status == httplib.NO_CONTENT
print response.object
if response.status == httplib.NO_CONTENT:
return []
elif response.status == httplib.OK:
return self._to_notification_plan_list(json.loads(response.body))

def create_notification_plan(self, **kwargs):
data = {'name': kwargs.get('name'),
Expand Down

0 comments on commit fff45bc

Please sign in to comment.