def get_resources(project_id, region_name=None): params = dict(project_id=project_id, region_name=region_name) _, resources = client.get('/resources', params=params) for r in resources: print "%s %s %s %s" % (r['region_name'], r['resource_id'], r['resource_type'], r['resource_name'])
def get_accounts(region_name=None): client = get_gringclient(region_name) __, accounts = client.get('/accounts') # for compatibility try: return accounts['accounts'] except Exception: return accounts
def get_new_accounts(y): __, accounts = client.get('/accounts') user_ids = [] start_time = datetime.datetime(y.year, y.month, y.day, 1, 0, 0).replace(tzinfo=None) end_time = start_time + datetime.timedelta(days=1) for account in accounts['accounts']: created_at = timeutils.parse_isotime(account['created_at']).replace(tzinfo=None) if created_at > start_time and created_at < end_time: user_ids.append(account['user_id']) return user_ids
def get_coupons(remarks=None): __, precharges = client.get('/precharge') codes = [] for precharge in precharges: if precharge['used'] or precharge['dispatched']: continue code = precharge['code'] dispatch_coupon(code, remarks) code = "%s-%s-%s-%s" % (code[0:4], code[4:8], code[8:12], code[12:16]) print code, precharge['price']
def get_new_accounts(y): __, accounts = client.get('/accounts') user_ids = [] start_time = datetime.datetime(y.year, y.month, y.day, 1, 0, 0).replace(tzinfo=None) end_time = start_time + datetime.timedelta(days=1) for account in accounts['accounts']: created_at = timeutils.parse_isotime( account['created_at']).replace(tzinfo=None) if created_at > start_time and created_at < end_time: user_ids.append(account['user_id']) return user_ids
from xlwt import Workbook import sys reload(sys) sys.setdefaultencoding('utf-8') OS_AUHT_URL = 'http://localhost:35357/v3' client = client.Client(username='******', password='******', project_name='admin', auth_url=OS_AUHT_URL) __, accounts = client.get('/accounts') def get_uos_user(user_id): internal_api = lambda api: OS_AUHT_URL + '/US-INTERNAL'+ '/' + api query = {'query': {'id': user_id}} r = requests.post(internal_api('get_user'), data=json.dumps(query), headers={'Content-Type': 'application/json'}) if r.status_code == 404: return return r.json()['user']
def check_avaliable(region_name=None): client = get_gringclient(region_name) client.get('/')
def get_one_active_order(client, region_id): _, resp = client.get('/orders/active?region_id=%s&limit=1&offset=0' % region_id) return resp[0] if resp else None
def get_accounts(): __, accounts = client.get('/accounts') return accounts['accounts']
from gringotts.services import keystone from xlwt import Workbook import sys reload(sys) sys.setdefaultencoding('utf-8') OS_AUHT_URL = 'http://localhost:35357/v3' client = client.Client(username='******', password='******', project_name='admin', auth_url=OS_AUHT_URL) __, accounts = client.get('/accounts') def get_uos_user(user_id): internal_api = lambda api: OS_AUHT_URL + '/US-INTERNAL' + '/' + api query = {'query': {'id': user_id}} r = requests.post(internal_api('get_user'), data=json.dumps(query), headers={'Content-Type': 'application/json'}) if r.status_code == 404: return return r.json()['user']
def get_account(user_id): try: __, account = client.get('/accounts/%s' % user_id) except Exception: return None return account