def creating(context, subscription_id, tenant_id, item_name, resource_uuid, created_at, updated_at, expires_at, order_unit, order_size, price, currency, region_name, interval_unit, interval_size, is_prepaid): app = context.app conn = driver.get_connection(item_name) if not conn.is_running(resource_uuid): app.info("wait:%s creating, but %s not running." % (str(subscription_id), item_name)) if created_at + relativedelta(minutes=10) < utils.utcnow(): app.info("%s(%s) status creating-->error" % (str(subscription_id), item_name)) db.subscription_error(context, subscription_id) # TODO(lzyeval): report else: interval_info = { interval_unit: interval_size, } app.info("%s(%s) status creating-->verify" % (str(subscription_id), item_name)) db.subscription_verify(context, subscription_id) if is_prepaid: quantity = conn.get_usage(resource_uuid, expires_at - relativedelta(**interval_info), expires_at, order_size) print "creating and is running", tenant_id, subscription_id, \ quantity, order_size, "\033[1;33m", price, "\033[0m" app.info("creating %s:subid=%s,tid=%s,price=%s" % (item_name, subscription_id, tenant_id, str(price))) charge(context, tenant_id, subscription_id, quantity, order_size, price) else: app.info("%s/%s/%s is_prepaid" % (tenant_id, str(subscription_id), item_name)) db.subscription_extend(context, subscription_id, expires_at + relativedelta(**interval_info))
def deleting(context, subscription_id, tenant_id, item_name, resource_uuid, created_at, updated_at, expires_at, order_unit, order_size, price, currency, region_name, interval_unit, interval_size, is_prepaid): app = context.app conn = driver.get_connection(item_name) if not conn.is_terminated(resource_uuid): app.info("wait:%s deleting, but %s not terminated." % (str(subscription_id), item_name)) if updated_at + relativedelta(minutes=10) < utils.utcnow(): app.info("%s(%s) status deleting-->error" % (str(subscription_id), item_name)) db.subscription_error(context, subscription_id) # TODO(lzyeval): report else: # TODO(lzyeval): implement app.info("%s(%s) status deleting-->terminated" % (str(subscription_id), item_name)) db.subscription_terminate(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) print "deleting", tenant_id, subscription_id, \ quantity, order_size, "\033[1;33m", price, "\033[0m" app.info("deleting %s(%s),tid=%s,price=%s" % (subscription_id, item_name, tenant_id, str(price))) charge(context, tenant_id, subscription_id, quantity, order_size, price) else: app.info("%s/%s/%s is_prepaid" % (tenant_id, str(subscription_id), item_name))
def deleting(context, subscription_id, tenant_id, item_name, resource_uuid, created_at, updated_at, expires_at, order_unit, order_size, price, currency, region_name, interval_unit, interval_size, is_prepaid): app = context.app conn = driver.get_connection(item_name) if not conn.is_terminated(resource_uuid): app.info("wait:%s deleting, but %s not terminated." % (str(subscription_id), item_name)) if updated_at + relativedelta(minutes=10) < utils.utcnow(): app.info("%s(%s) status deleting-->error" % (str(subscription_id), item_name)) db.subscription_error(context, subscription_id) # TODO(lzyeval): report else: # TODO(lzyeval): implement app.info("%s(%s) status deleting-->terminated" % (str(subscription_id), item_name)) db.subscription_terminate(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) print "deleting", tenant_id, subscription_id, \ quantity, order_size, "\033[1;33m", price, "\033[0m" app.info("deleting %s(%s),tid=%s,price=%s" % (subscription_id, item_name, tenant_id, str(price))) charge(context, tenant_id, subscription_id, quantity, order_size, price) else: app.info("%s/%s/%s is_prepaid" % (tenant_id, str(subscription_id), item_name))
def creating(context, subscription_id, tenant_id, item_name, resource_uuid, created_at, updated_at, expires_at, order_unit, order_size, price, currency, region_name, interval_unit, interval_size, is_prepaid): app = context.app conn = driver.get_connection(item_name) if not conn.is_running(resource_uuid): app.info("wait:%s creating, but %s not running." % (str(subscription_id), item_name)) if created_at + relativedelta(minutes=10) < utils.utcnow(): app.info("%s(%s) status creating-->error" % (str(subscription_id), item_name)) db.subscription_error(context, subscription_id) # TODO(lzyeval): report else: interval_info = { interval_unit: interval_size, } app.info("%s(%s) status creating-->verify" % (str(subscription_id), item_name)) db.subscription_verify(context, subscription_id) if is_prepaid: quantity = conn.get_usage( resource_uuid, expires_at - relativedelta(**interval_info), expires_at, order_size) print "creating and is running", tenant_id, subscription_id, \ quantity, order_size, "\033[1;33m", price, "\033[0m" app.info("creating %s:subid=%s,tid=%s,price=%s" % (item_name, subscription_id, tenant_id, str(price))) charge(context, tenant_id, subscription_id, quantity, order_size, price) else: app.info("%s/%s/%s is_prepaid" % (tenant_id, str(subscription_id), item_name)) db.subscription_extend(context, subscription_id, expires_at + relativedelta(**interval_info))
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)
def deleting(context, subscription_id, tenant_id, resource_uuid, created_at, updated_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 updated_at + relativedelta(minutes=10) < utils.utcnow(): db.subscription_error(context, subscription_id) # TODO(lzyeval): report else: # TODO(lzyeval): implement db.subscription_terminate(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)
def test_subscription_error(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_error(self.context, expect.id) actual = db.subscription_get(self.context, expect.id) expect.status = "error" self.compare_records(expect, actual)
def creating(context, subscription_id, tenant_id, resource_uuid, created_at, updated_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_running(resource_uuid): if created_at + relativedelta(minutes=10) < utils.utcnow(): db.subscription_error(context, subscription_id) # TODO(lzyeval): report else: interval_info = { interval_unit: interval_size, } db.subscription_verify(context, subscription_id) if is_prepaid: 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) db.subscription_extend(context, subscription_id, expires_at + relativedelta(**interval_info))
def test_subscription_error(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_error(self.context, expect.id) actual = db.subscription_get(self.context, expect.id) expect.status = "error" self.compare_records(expect, actual)