def get_initial(self): projects, more = api.keystone.tenant_list(self.request) billing_client = chakra.AccountBilling() accounts, resultStatus = billing_client.get_accounts() if resultStatus == 200: accounts = json.loads(accounts) for account in accounts['accounts']: for id, project in enumerate(projects): if project.id == account['ref_resource'] \ or project.name == 'service': projects.pop(id) return {'projects': projects} else: return {'projects': ''}
def get_object(self): if not hasattr(self, "_object"): try: billing_client = chakra.AccountBilling() self._object, resultStatus = \ billing_client.get_account(self.kwargs['account_id']) self._object = json.loads(self._object) if resultStatus == 500: return [] except Exception: redirect = reverse("horizon:admin:billing:index") exceptions.handle(self.request, _('Unable to update user.'), redirect=redirect) return self._object
def get_data(self): accounts = [] try: billing_client = chakra.AccountBilling() accounts, resultStatus = billing_client.get_accounts() if accounts: accounts = json.loads(accounts) for i, account in enumerate(accounts['accounts']): accounts['accounts'][i] = json2object.get_account(account) if resultStatus == 500: return [] except Exception: exceptions.handle(self.request, _('Unable to retrieve user list.')) if accounts: return accounts.get('accounts') else: return accounts
def handle(self, request, data): name = data.pop('name') project = data.pop('project') try: billing_client = chakra.AccountBilling() body = {"balance": 0, "ref_resource": project, "name": name} accounts, resultStatus = billing_client.create_account(body) if resultStatus != 200: messages.error(request, _('Unable to create the account.')) else: messages.success(request, _('Account has been created successfully.')) except Exception: messages.error(request, _('Unable to create the account.')) return True
def action(self, request, obj_id): billing_client = chakra.AccountBilling() billing_client.delete_account(obj_id)