예제 #1
0
def unsubscribe_item(context,
                     region=None,
                     item=None,
                     resource_uuid=None,
                     **kwargs):
    """
    """
    try:
        subscription_id = 0
        subscriptions = db.subscription_get_all_by_resource_uuid(
            context, resource_uuid)
        if not subscriptions:
            raise exception.SubscriptionNotFoundByResourceUUID(
                resource_uuid=resource_uuid)
        for subscription in subscriptions:
            if subscription['product']['region']['name'] != region:
                continue
            elif subscription['product']['item']['name'] != item:
                continue
            subscription_id = subscription['id']
        if not subscription_id:
            raise exception.SubscriptionNotFoundByRegionOrItem(region=region,
                                                               item=item)
        db.subscription_destroy(context, subscription_id)
    except Exception, e:
        # TODO(lzyeval): report
        raise
예제 #2
0
 def test_unsubscribe_item(self):
     self.mox.StubOutWithMock(db, 'subscription_get_all_by_resource_uuid')
     self.mox.StubOutWithMock(db, 'subscription_destroy')
     db.subscription_get_all_by_resource_uuid(self.context,
                                              self.resource_uuid).\
             AndReturn([self.subscription])
     db.subscription_destroy(self.context, self.subscription_id).\
             AndReturn(None)
     self.mox.ReplayAll()
     result = api.unsubscribe_item(self.context, self.region_name,
                                   self.item_name, self.resource_uuid)
     self.mox.VerifyAll()
     self.assertEqual(result, {})
예제 #3
0
 def test_unsubscribe_item(self):
     self.mox.StubOutWithMock(db, 'subscription_get_all_by_resource_uuid')
     self.mox.StubOutWithMock(db, 'subscription_destroy')
     db.subscription_get_all_by_resource_uuid(self.context,
                                              self.resource_uuid).\
             AndReturn([self.subscription])
     db.subscription_destroy(self.context, self.subscription_id).\
             AndReturn(None)
     self.mox.ReplayAll()
     result = api.unsubscribe_item(self.context, self.region_name,
                                   self.item_name, self.resource_uuid)
     self.mox.VerifyAll()
     self.assertEqual(result, {})
예제 #4
0
파일: api.py 프로젝트: soloxf/dough
def unsubscribe_item(context, region=None, item=None,
                     resource_uuid=None, **kwargs):
    """
    """
    filters = {
        'project_id': context.project_id,
        'resource_uuid': resource_uuid,
        }
    try:
        filters['region_id'] = db.region_get_by_name(context, region)['id']
        filters['item_id'] = db.item_get_by_name(context, item)['id']
        subscriptions = db.subscription_get_all(context, filters=filters)
        # TODO(lzyeval): check if subscriptions size is not 1
        db.subscription_destroy(context, subscriptions[0]['id'])
    except Exception, e:
        # TODO(lzyeval): report
        raise
예제 #5
0
파일: __init__.py 프로젝트: soloxf/dough
def deleting(context, subscription_id, tenant_id, resource_uuid,
             created_at, deleted_at, expires_at,
             order_unit, order_size, price, currency, region_name, 
             item_name, interval_unit, interval_size, is_prepaid):
    conn = driver.get_connection(item_name)
    if not conn.is_terminated(resource_uuid):
        if deleted_at + relativedelta(minutes=10) < utils.utcnow():
            db.subscription_error(context, subscription_id)
            # TODO(lzyeval): report
    else:
        # TODO(lzyeval): implement
        db.subscription_destroy(context, subscription_id)
        if not is_prepaid:
            interval_info = {
                interval_unit: interval_size,
                }
            quantity = conn.get_usage(resource_uuid,
                    expires_at - relativedelta(**interval_info),
                    expires_at, order_size)
            charge(context, tenant_id, subscription_id, quantity, order_size, price)
예제 #6
0
 def test_subscription_destroy(self):
     self.truncate_table("regions")
     self.truncate_table("items")
     self.truncate_table("item_types")
     self.truncate_table("payment_types")
     self.truncate_table("products")
     self.truncate_table("subscriptions")
     region_ref = db.region_create(self.context, {'name': 'a_region'})
     item_ref = db.item_create(self.context, {'name': 'an_item'})
     item_type_ref = db.item_type_create(self.context,
                                         {'name': 'an_item_type'})
     payment_type_ref = db.payment_type_create(
         self.context, {
             'name': 'a_payment_type',
             'interval_unit': 'days',
             'interval_size': 12345,
             'is_prepaid': False
         })
     values = {
         'region_id': region_ref.id,
         'item_id': item_ref.id,
         'item_type_id': item_type_ref.id,
         'payment_type_id': payment_type_ref.id,
         'order_unit': 'some_measure',
         'order_size': 1,
         'price': 11.24,
         'currency': 'CNY',
     }
     product_ref = db.product_create(self.context, values)
     values = {
         'project_id': self.context.project_id,
         'product_id': product_ref.id,
         'resource_uuid': self.resource_uuid,
         'resource_name': self.resource_name,
     }
     expect = db.subscription_create(self.context, values)
     db.subscription_destroy(self.context, expect.id)
     actual = db.subscription_get(self.context, expect.id)
     expect.status = "deleting"
     self.compare_records(expect, actual)
예제 #7
0
파일: test_api.py 프로젝트: soloxf/dough
 def test_unsubscribe_item(self):
     self.mox.StubOutWithMock(db, 'region_get_by_name')
     self.mox.StubOutWithMock(db, 'item_get_by_name')
     self.mox.StubOutWithMock(db, 'subscription_get_all')
     self.mox.StubOutWithMock(db, 'subscription_destroy')
     db.region_get_by_name(self.context, self.region_name).\
             AndReturn(self.region)
     db.item_get_by_name(self.context, self.item_name).AndReturn(self.item)
     db.subscription_get_all(self.context,
                             filters={
                                 'region_id': self.region_id,
                                 'item_id': self.item_id,
                                 'project_id': self.context.project_id,
                                 'resource_uuid': self.resource_uuid
                                 }).AndReturn(self.subscriptions)
     db.subscription_destroy(self.context, self.subscription_id).\
             AndReturn(None)
     self.mox.ReplayAll()
     result = api.unsubscribe_item(self.context, self.region_name,
                                   self.item_name, self.resource_uuid)
     self.mox.VerifyAll()
     self.assertEqual(result, {})
예제 #8
0
 def test_subscription_destroy(self):
     self.truncate_table("regions")
     self.truncate_table("items")
     self.truncate_table("item_types")
     self.truncate_table("payment_types")
     self.truncate_table("products")
     self.truncate_table("subscriptions")
     region_ref = db.region_create(self.context, {'name': 'a_region'})
     item_ref = db.item_create(self.context, {'name': 'an_item'})
     item_type_ref = db.item_type_create(self.context,
                                         {'name': 'an_item_type'})
     payment_type_ref = db.payment_type_create(self.context,
                                               {'name': 'a_payment_type',
                                                'interval_unit': 'days',
                                                'interval_size': 12345,
                                                'is_prepaid': False})
     values = {
         'region_id': region_ref.id,
         'item_id': item_ref.id,
         'item_type_id': item_type_ref.id,
         'payment_type_id': payment_type_ref.id,
         'order_unit': 'some_measure',
         'order_size': 1,
         'price': 11.24,
         'currency': 'CNY',
         }
     product_ref = db.product_create(self.context, values)
     values = {
         'project_id': self.context.project_id,
         'product_id': product_ref.id,
         'resource_uuid': self.resource_uuid,
         'resource_name': self.resource_name,
         }
     expect = db.subscription_create(self.context, values)
     db.subscription_destroy(self.context, expect.id)
     actual = db.subscription_get(self.context, expect.id)
     expect.status = "deleting"
     self.compare_records(expect, actual)
예제 #9
0
파일: api.py 프로젝트: pengyuwei/dough
def unsubscribe_item(context, region=None, item=None,
                     resource_uuid=None, **kwargs):
    """
    """
    try:
        app = context.app
        app.info("unsubscribe_item:" + str(region) + "/" + str(item) + "/" + str(resource_uuid))
        subscription_id = 0
        subscriptions = db.subscription_get_all_by_resource_uuid(context,
                                                                 resource_uuid)
        if not subscriptions:
            print "unsubscribe_item.SubscriptionNotFoundByResourceUUID", resource_uuid
            raise exception.SubscriptionNotFoundByResourceUUID(
                    resource_uuid=resource_uuid)
        for subscription in subscriptions:
            product = subscription['product']
            if product['region']['name'] != region:
                continue
            elif product['item']['name'] != item:
                continue
            # TODO: status==verified
            print subscription['status']
            if "floating_ip" == product['item']['name'] and "verified" != subscription['status']:
                continue
            subscription_id = subscription['id']
            break
        if not subscription_id:
            print "subscription_get_by_resource_uuid", resource_uuid, "item=", item, "region=", region
            raise exception.SubscriptionNotFoundByRegionOrItem(region=region,
                                                               item=item)
        app.info("\tsubs_id=" + str(subscription_id))
        db.subscription_destroy(context, subscription_id)
    except Exception, e:
        # TODO(lzyeval): report
        print e
        raise
예제 #10
0
파일: api.py 프로젝트: pperezrubio/dough
def unsubscribe_item(context, region=None, item=None,
                     resource_uuid=None, **kwargs):
    """
    """
    try:
        subscription_id = 0
        subscriptions = db.subscription_get_all_by_resource_uuid(context,
                                                                 resource_uuid)
        if not subscriptions:
            raise exception.SubscriptionNotFoundByResourceUUID(
                    resource_uuid=resource_uuid)
        for subscription in subscriptions:
            if subscription['product']['region']['name'] != region:
                continue
            elif subscription['product']['item']['name'] != item:
                continue
            subscription_id = subscription['id']
        if not subscription_id:
            raise exception.SubscriptionNotFoundByRegionOrItem(region=region,
                                                               item=item)
        db.subscription_destroy(context, subscription_id)
    except Exception, e:
        # TODO(lzyeval): report
        raise
예제 #11
0
파일: api.py 프로젝트: young8/dough
def unsubscribe_item(context, region=None, item=None,
                     resource_uuid=None, **kwargs):
    """
    """
    try:
        app = context.app
        app.info("unsubscribe_item:" + str(region) + "/" + str(item) + "/" + str(resource_uuid))
        subscription_id = 0
        subscriptions = db.subscription_get_all_by_resource_uuid(context,
                                                                 resource_uuid)
        if not subscriptions:
            print "unsubscribe_item.SubscriptionNotFoundByResourceUUID", resource_uuid
            raise exception.SubscriptionNotFoundByResourceUUID(
                    resource_uuid=resource_uuid)
        for subscription in subscriptions:
            product = subscription['product']
            if product['region']['name'] != region:
                continue
            elif product['item']['name'] != item:
                continue
            # TODO: status==verified
            print subscription['status']
            if "floating_ip" == product['item']['name'] and "verified" != subscription['status']:
                continue
            subscription_id = subscription['id']
            break
        if not subscription_id:
            print "subscription_get_by_resource_uuid", resource_uuid, "item=", item, "region=", region
            raise exception.SubscriptionNotFoundByRegionOrItem(region=region,
                                                               item=item)
        app.info("\tsubs_id=" + str(subscription_id))
        db.subscription_destroy(context, subscription_id)
    except Exception, e:
        # TODO(lzyeval): report
        print e
        raise