예제 #1
0
def get_gring_client(cloud):
    client = g_client.Client(username=cloud['admin_user'],
                             password=cloud['admin_password'],
                             project_name=cloud['admin_tenant_name'],
                             auth_url=cloud['os_auth_url'])
    client.management_url = force_v1_api(client.management_url)
    return client
예제 #2
0
def get_gringclient(region_name=None):
    ks_cfg = cfg.CONF.keystone_authtoken
    auth_url = keystone.get_auth_url()
    c = client.Client(username=ks_cfg.admin_user,
                      password=ks_cfg.admin_password,
                      project_name=ks_cfg.admin_tenant_name,
                      auth_url=auth_url)
    return c
예제 #3
0
 def __init__(self,
              auth_plugin="token",
              verify=True,
              cert=None,
              timeout=None,
              *args,
              **kwargs):
     self.client = client.Client(auth_plugin=auth_plugin,
                                 verify=verify,
                                 cert=cert,
                                 timeout=timeout,
                                 *args,
                                 **kwargs)
예제 #4
0
import sys
import json
import requests
from gringotts.client import client as gring_client
from novaclient.v1_1 import client as nova_client


gc = gring_client.Client(username='******',
                         password='******',
                         project_name='admin',
                         auth_url='http://localhost:35357/v3')


nc = nova_client.Client(username='******',
                        api_key='rachel',
                        project_id='admin',
                        auth_url='http://localhost:35357/v2.0')


def create_product(name, service, region_id, unit_price):
    body = dict(name=name,
                service=service,
                region_id=region_id,
                unit_price=unit_price,
                type="regular",
                unit="hour",
                description="some desc")
    gc.post('/products', body=body)


def _set_flavor_key(flavor_id, **meta):
예제 #5
0
def quantize(value):
    if isinstance(value, Decimal):
        return value.quantize(Decimal('0.0001'), rounding=ROUND_HALF_UP)
    return Decimal(str(value)).quantize(Decimal('0.0001'),
                                        rounding=ROUND_HALF_UP)


def force_v3_api(url):
    if url is None:
        return url
    return url.replace('/v2.0', '/v3')


gc = gring_client.Client(username=args.username,
                         password=args.password,
                         project_name=args.tenant_name,
                         auth_url=force_v3_api(args.auth_url))


def get_session():
    keystone_host = args.auth_url
    auth = v3.Password(auth_url=keystone_host,
                       username=args.username,
                       password=args.password,
                       project_name=args.tenant_name,
                       user_domain_id=args.user_domain_id,
                       project_domain_id=args.project_domain_id)
    session = ksc_session.Session(auth=auth)
    return session

예제 #6
0
import sys
import json
import requests
from gringotts.client import client

OS_AUHT_URL = 'http://localhost:35357/v3'

client = client.Client(username='******',
                       password='******',
                       project_name='demo',
                       auth_url=OS_AUHT_URL)


def get_uos_user(email):

    internal_api = lambda api: OS_AUHT_URL + '/US-INTERNAL'+ '/' + api

    query = {'query': {'email': email}}
    r = requests.post(internal_api('get_user'),
                      data=json.dumps(query),
                      headers={'Content-Type': 'application/json'})
    if r.status_code == 404:
        sys.exit('can not find the user')
    return r.json()['user']


def change_account_level(project_id, level):
    body = dict(level=level)
    client.put('/accounts/%s/level' % project_id, body=body)

예제 #7
0
# -*- coding: utf-8 -*-
import json
import requests
import datetime
from tempfile import TemporaryFile
from xlwt import Workbook

from gringotts.client import client
from gringotts.openstack.common import timeutils

OS_AUHT_URL = 'http://localhost:35357/v3'

client = client.Client(username='******',
                       password='******',
                       project_name='admin',
                       auth_url=OS_AUHT_URL)


def get_uos_users(user_ids):

    internal_api = lambda api: OS_AUHT_URL + '/US-INTERNAL' + '/' + api

    query = {'query': {'user_ids': user_ids}}
    r = requests.post(internal_api('get_users'),
                      data=json.dumps(query),
                      headers={'Content-Type': 'application/json'})
    return r.json()['users']


def get_new_accounts(y):
    __, accounts = client.get('/accounts')
예제 #8
0
    }

    utc_now = datetime.datetime.utcnow()
    for recip in recipients:
        params.update(phone=recip)
        resp = requests.get(SMS_API_URL + '?' + urllib.urlencode(params))
        print "%s %s" % (utc_now, resp.content)


if __name__ == '__main__':
    while True:
        for cloud_name, cloud in CLOUDS.items():
            try:
                gclient = client.Client(
                    username=cloud['admin_user'],
                    password=cloud['admin_password'],
                    project_name=cloud['admin_tenant_name'],
                    auth_url=cloud['os_auth_url'])
                for region_name in cloud['regions']:
                    order = get_one_active_order(gclient, region_name)
                    if not order:
                        print "there is no active order in [%s][%s]." % (
                            cloud_name, region_name)
                        continue
                    cron_time = parse_strtime(order['cron_time'])
                    utc_now = datetime.datetime.utcnow()
                    if utc_now > cron_time:
                        alert_to(
                            u"【UnitedStack有云】[%s][%s] gring-master maybe hanged, check it"
                            % (cloud_name, region_name), ["18500239557"])
            except Exception as e: