Example #1
0
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'])
Example #2
0
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
Example #3
0
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
Example #4
0
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']
Example #5
0
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
Example #7
0
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']

Example #8
0
def check_avaliable(region_name=None):
    client = get_gringclient(region_name)
    client.get('/')
Example #9
0
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
Example #10
0
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'])
Example #11
0
def get_accounts():
    __, accounts = client.get('/accounts')
    return accounts['accounts']
Example #12
0
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']

Example #13
0
def get_account(user_id):
    try:
        __, account = client.get('/accounts/%s' % user_id)
    except Exception:
        return None
    return account
Example #14
0
def get_account(user_id):
    try:
        __, account = client.get('/accounts/%s' % user_id)
    except Exception:
        return None
    return account
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
Example #16
0
def get_accounts():
    __, accounts = client.get('/accounts')
    return accounts['accounts']