Example #1
0
def finish_order(order):
    import nova
    from user import serv
    from json import dumps
    order.status = 2
    useraccount = serv.get_user_account(order.user_id)
    user = serv.get_user_login(order.user_id)
    if not useraccount.tenant_id:
        tenant = nova.api().get_tenent(useraccount)
        useraccount.tenant_id = tenant['id']
        usertenant = UserTenant(user)
        usertenant.tenant_id = tenant['id']
        usertenant.tenant_name = tenant['name']
        usertenant.admin_user_id = tenant['user_id']
        key_pair = nova.api().gen_key(useraccount, tenant["name"])
        usertenant.keypair = dumps(key_pair)
        uk = UserKey(key_content=key_pair)
        g.db.add(uk)
        g.db.add(usertenant)
    orderproducts = g.db.query(OrderProduct).filter(
        OrderProduct.order_id == order.id).all()
    for orderproduct in orderproducts:
        userproduct = UserProduct(user, orderproduct)
        g.db.add(userproduct)
    g.db.flush()
    g.db.commit()
Example #2
0
def finish_order(order):
    import nova
    from user import serv
    from json import dumps
    order.status = 2
    useraccount = serv.get_user_account(order.user_id)
    user = serv.get_user_login(order.user_id)
    if not useraccount.tenant_id:
        tenant = nova.api().get_tenent(useraccount)
        useraccount.tenant_id = tenant['id']
        usertenant = UserTenant(user)
        usertenant.tenant_id = tenant['id']
        usertenant.tenant_name = tenant['name']
        usertenant.admin_user_id = tenant['user_id']
        key_pair = nova.api().gen_key(useraccount, tenant["name"])
        usertenant.keypair = dumps(key_pair)
        uk = UserKey(key_content=key_pair)
        g.db.add(uk)
        g.db.add(usertenant)
    orderproducts = g.db.query(OrderProduct).filter(OrderProduct.order_id==order.id).all()
    for orderproduct in orderproducts:
        userproduct = UserProduct(user, orderproduct)
        g.db.add(userproduct)
    g.db.flush()
    g.db.commit()
Example #3
0
def create_key():
    from nova import api
    name = request.form.get("key_name")
    oper = api()
    ua = get_user_account(g.current_login_id)
    tn = get_user_tenant(g.current_login_id)
    key_pair = oper.gen_key(ua, tn.tenant_name, key_name=name)
    userkey = UserKey(key_content=key_pair)
    userkey.user_id = g.current_login_id
    g.db.add(userkey)
    g.db.flush()
    g.db.commit()
    return redirect(url_for("product.show_key_manage"))
Example #4
0
def create_key():
    from nova import api
    name = request.form.get("key_name")
    oper = api()
    ua = get_user_account(g.current_login_id)
    tn = get_user_tenant(g.current_login_id)
    key_pair = oper.gen_key(ua, tn.tenant_name, key_name = name)
    userkey = UserKey(key_content=key_pair)
    userkey.user_id = g.current_login_id
    g.db.add(userkey)
    g.db.flush()
    g.db.commit()
    return redirect(url_for("product.show_key_manage"))
Example #5
0
def create_server(user_product_id, server_name, image_id, secury, sec_key):
    import nova
    from json import loads
    from user.serv import get_user_tenant, get_user_account
    userproduct = g.db.query(UserProduct).get(user_product_id)
    usertenant = get_user_tenant(userproduct.user_id)
    useraccount = get_user_account(userproduct.user_id)
    tenant = g.db.query(Tenant).get(usertenant.tenant_id)
    product = g.db.query(Product).filter(Product.key==userproduct.product_key).one()
    rs, server_id, password = nova.api().create_server(useraccount, tenant.name,server_name, product.flover_id, image_id, secury, sec_key)
    if rs:
        userproduct.image_id = image_id
        userproduct.adminpass = password
        userproduct.instance_name = server_name
        userproduct.server_id = server_id
        userproduct.status = 1
    g.db.flush()
    g.db.commit()
    return server_id
Example #6
0
def create_server(user_product_id, server_name, image_id, secury, sec_key):
    import nova
    from json import loads
    from user.serv import get_user_tenant, get_user_account
    userproduct = g.db.query(UserProduct).get(user_product_id)
    usertenant = get_user_tenant(userproduct.user_id)
    useraccount = get_user_account(userproduct.user_id)
    tenant = g.db.query(Tenant).get(usertenant.tenant_id)
    product = g.db.query(Product).filter(
        Product.key == userproduct.product_key).one()
    rs, server_id, password = nova.api().create_server(
        useraccount, tenant.name, server_name, product.flover_id, image_id,
        secury, sec_key)
    if rs:
        userproduct.image_id = image_id
        userproduct.adminpass = password
        userproduct.instance_name = server_name
        userproduct.server_id = server_id
        userproduct.status = 1
    g.db.flush()
    g.db.commit()
    return server_id
Example #7
0
def show_access_control():
    from nova import api
    useraccount = get_user_account(g.current_login_id)
    tenant = get_user_tenant(g.current_login_id)
    groups = api().secury_groups(useraccount, tenant.tenant_name)
    return render_template("access_control.html", **locals())
Example #8
0
def get_status(user_id, server_id):
    import nova
    from user.serv import get_user_account
    useraccount = get_user_account(user_id)
    return nova.api().server_status(useraccount.tenant_id, server_id)
Example #9
0
def show_access_control():
    from nova import api
    useraccount = get_user_account(g.current_login_id)
    tenant = get_user_tenant(g.current_login_id)
    groups = api().secury_groups(useraccount,tenant.tenant_name)
    return render_template("access_control.html",**locals())
Example #10
0
def get_status(user_id, server_id):
    import nova
    from user.serv import  get_user_account
    useraccount = get_user_account(user_id)
    return nova.api().server_status(useraccount.tenant_id, server_id)