Beispiel #1
0
def get_disks_pconn(session, user_id, project_id, is_system=1):
    if not session:
        session = get_mysql_session("cinder")

    ret = []
    disk_size = 0
    #for row in session.execute('select * from  volumes  where       user_id="%s" and project_id="%s" ;'%(user_id, project_id)).fetchall():
    session.execute("use  cinder")
    for row in session.execute(
            'select * from  volumes  where ( status != "deleted" ) and user_id="%s" and project_id="%s" ;'
            % (user_id, project_id)).fetchall():
        #for row in session.execute('select * from  volumes  where  bootable=0  and ( status != "deleted" )  ;').fetchall():
        #for row in session.execute('select * from  volumes  where  ( status != "deleted" )  ;').fetchall():
        row = dict(zip(row.keys(), row.values()))
        tmp = {}

        id = row['id']
        user_id = row['user_id']
        project_id = row['project_id']
        size = row['size']
        disk_size += size
        #host=row['host'];
        bootable = row['bootable']

        tmp['id'] = id
        tmp['user_id'] = user_id
        tmp['project_id'] = project_id
        tmp['size'] = size
        tmp['bootable'] = bootable
        ret.append(tmp)
    return (ret, disk_size)
Beispiel #2
0
def add_discount_record():
    session = get_mysql_session("billing")
    account_id = "account_id"
    rows = session.execute(
        'insert discount values ( 222, 1, "%s", 0.77, null, null )  ;' %
        account_id)
    session.close()
Beispiel #3
0
def get_user_routers_pconn(session, project_id):
    if not session:
        session = get_mysql_session("neutron")

    ret = []
    session.execute("use neutron")
    for row in session.execute(
            'select * from  routers  where tenant_id="%s"  ;' %
            project_id).fetchall():
        #for row in session.execute('select * from  routers  ').fetchall():
        row = dict(zip(row.keys(), row.values()))

        tenant_id = row['tenant_id']
        id = row['id']
        #name=row['name'];
        status = row['status']
        bandwidth = row['bandwidth']

        tmp = {}
        tmp['tenant_id'] = tenant_id
        tmp['id'] = id
        tmp['status'] = status
        #tmp['name']=name;
        tmp['bandwidth'] = bandwidth
        ret.append(tmp)
    return ret
Beispiel #4
0
def get_disks():
    disks_size = []
    session = get_mysql_session("cinder")

    ret = get_disks_pconn(session)
    session.close()
    return ret
Beispiel #5
0
def get_cpu_count_pconn(session, uuid):
    if not session:
        session = get_mysql_session("nova")
    vcpus = 0
    session.execute("use nova")
    for row in session.execute('select * from  instances  where uuid="%s"  ;' %
                               uuid).fetchall():
        row = dict(zip(row.keys(), row.values()))
        vcpus = row['vcpus']
    return vcpus
Beispiel #6
0
#!/usr/bin/python
#coding: gbk
from mysql_db  import  get_mysql_session;
session=get_mysql_session("keystone");

#让密码验证 一定返回正确的方式: 
#1.  check_passwd  返回值  指定写成 True
#2.  把所有的 keystone user 表里面的 passwd 修改成   hash 值 . 

rows= session.execute("select user.name as user_name,user.password as user_passwd,project.name as tenant_name  from   user   left join  project  ON  project.id=user.default_project_id ;").fetchall();

for each in  rows:
    #print each['user_name'];
    url="""
    curl -s -X POST http://localhost:35357/v2.0/tokens \
    -d '{"auth": {"passwordCredentials": {"username":"******", "password":"******"}, "tenantName":"%s"}}'  -H "Content-type: application/json"  |jq -r .access.token.id
""" %(each['user_name'], each['tenant_name']);
    print url;