You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/01/31 19:32:52 UTC
[2/7] git commit: Add ex_create_subscription method to CloudSigma
driver. Also modify subscription class so the amount attribute is an int.
Add ex_create_subscription method to CloudSigma driver. Also modify
subscription class so the amount attribute is an int.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0d7b5a57
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0d7b5a57
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0d7b5a57
Branch: refs/heads/trunk
Commit: 0d7b5a5787400eda65c4418fd49fc0e17e4ba244
Parents: 3f84e6b
Author: Tomaz Muraus <to...@apache.org>
Authored: Fri Jan 31 18:11:47 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Fri Jan 31 18:11:47 2014 +0100
----------------------------------------------------------------------
libcloud/compute/drivers/cloudsigma.py | 36 +++++++++++++++++++-
.../cloudsigma_2_0/create_subscription.json | 23 +++++++++++++
libcloud/test/compute/test_cloudsigma_v2_0.py | 16 ++++++++-
3 files changed, 73 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d7b5a57/libcloud/compute/drivers/cloudsigma.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudsigma.py b/libcloud/compute/drivers/cloudsigma.py
index 266708e..5000a33 100644
--- a/libcloud/compute/drivers/cloudsigma.py
+++ b/libcloud/compute/drivers/cloudsigma.py
@@ -1736,6 +1736,40 @@ class CloudSigma_2_0_NodeDriver(CloudSigmaNodeDriver):
method='POST')
return response.status == httplib.OK
+ def ex_create_subscription(self, amount, period, resource,
+ auto_renew=False):
+ """
+ Create a new subscription.
+
+ :param amount: Subscription amount. For example, in dssd case this
+ would be disk size in gigabytes.
+ :type amount: ``int``
+
+ :param period: Subscription period. For example: 30 days, 1 week, 1
+ month, ...
+ :type period: ``str``
+
+ :param resource: Resource the purchase the subscription for.
+ :type resource: ``str``
+
+ :param auto_renew: True to automatically renew the subscription.
+ :type auto_renew: ``bool``
+ """
+ data = [
+ {
+ 'amount': amount,
+ 'period': period,
+ 'auto_renew': auto_renew,
+ 'resource': resource
+ }
+ ]
+
+ response = self.connection.request(action='/subscriptions/',
+ data=data, method='POST')
+ data = response.object['objects'][0]
+ subscription = self._to_subscription(data=data)
+ return subscription
+
# Misc extension methods
def ex_list_capabilities(self):
@@ -1869,7 +1903,7 @@ class CloudSigma_2_0_NodeDriver(CloudSigmaNodeDriver):
subscription = CloudSigmaSubscription(id=data['id'],
resource=data['resource'],
- amount=data['amount'],
+ amount=int(data['amount']),
period=data['period'],
status=data['status'],
price=data['price'],
http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d7b5a57/libcloud/test/compute/fixtures/cloudsigma_2_0/create_subscription.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudsigma_2_0/create_subscription.json b/libcloud/test/compute/fixtures/cloudsigma_2_0/create_subscription.json
new file mode 100644
index 0000000..7699d40
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudsigma_2_0/create_subscription.json
@@ -0,0 +1,23 @@
+{
+ "objects": [
+ {
+ "amount": "1",
+ "auto_renew": false,
+ "descendants": [],
+ "discount_amount": "0",
+ "discount_percent": "0",
+ "end_time": "2014-03-01T12:00:00+00:00",
+ "id": "228816",
+ "period": "1 month",
+ "price": "10.26666666666666666666666667",
+ "remaining": "1",
+ "resource": "vlan",
+ "resource_uri": "/api/2.0/subscriptions/228816/",
+ "start_time": "2014-01-31T17:06:19.388295+00:00",
+ "status": "active",
+ "subscribed_object": "2494079f-8376-40bf-9b37-34d633b8a7b7",
+ "uuid": "0dd25c5c-6c01-498f-b009-e07d76552a1a"
+ }
+ ],
+ "price": "10.26666666666666666666666667"
+}
http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d7b5a57/libcloud/test/compute/test_cloudsigma_v2_0.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudsigma_v2_0.py b/libcloud/test/compute/test_cloudsigma_v2_0.py
index 966a072..7d04682 100644
--- a/libcloud/test/compute/test_cloudsigma_v2_0.py
+++ b/libcloud/test/compute/test_cloudsigma_v2_0.py
@@ -332,11 +332,21 @@ class CloudSigmaAPI20BaseTestCase(object):
self.assertEqual(len(subscriptions), 5)
self.assertEqual(subscription.id, '7272')
self.assertEqual(subscription.resource, 'vlan')
- self.assertEqual(subscription.amount, '1')
+ self.assertEqual(subscription.amount, 1)
self.assertEqual(subscription.period, '345 days, 0:00:00')
self.assertEqual(subscription.status, 'active')
self.assertEqual(subscription.price, '0E-20')
+ def test_ex_create_subscription(self):
+ CloudSigmaMockHttp.type = 'CREATE_SUBSCRIPTION'
+ subscription = self.driver.ex_create_subscription(amount=1,
+ period='1 month',
+ resource='vlan')
+ self.assertEqual(subscription.amount, 1)
+ self.assertEqual(subscription.period, '1 month')
+ self.assertEqual(subscription.resource, 'vlan')
+ self.assertEqual(subscription.price, '10.26666666666666666666666667')
+
def test_ex_list_subscriptions_status_filterting(self):
CloudSigmaMockHttp.type = 'STATUS_FILTER'
self.driver.ex_list_subscriptions(status='active')
@@ -577,6 +587,10 @@ class CloudSigmaMockHttp(MockHttpTestCase):
body = ''
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+ def _api_2_0_subscriptions_CREATE_SUBSCRIPTION(self, method, url, body, headers):
+ body = self.fixtures.load('create_subscription.json')
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
def _api_2_0_capabilities(self, method, url, body, headers):
body = self.fixtures.load('capabilities.json')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])