Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 3
0
def start_vnc(user_product_id):
    import nova
    from user.serv import get_user_tenant
    userproduct = g.db.query(UserProduct).get(user_product_id)
    usertenant = get_user_tenant(userproduct.user_id)
    tenant = g.db.query(Tenant).get(usertenant.tenant_id)
    api = nova.api()
    return userproduct, api.get_vnc_url(tenant.name, userproduct.server_id)
Exemplo n.º 4
0
def start_vnc(user_product_id):
    import nova
    from user.serv import get_user_tenant
    userproduct = g.db.query(UserProduct).get(user_product_id)
    usertenant = get_user_tenant(userproduct.user_id)
    tenant = g.db.query(Tenant).get(usertenant.tenant_id)
    api = nova.api()
    return userproduct, api.get_vnc_url(tenant.name,userproduct.server_id)
Exemplo n.º 5
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"))
Exemplo n.º 6
0
def fresh_server_status(user_product_id):
    import nova
    userproduct = g.db.query(UserProduct).get(user_product_id)
    api = nova.api()
    server = api.server_status(userproduct.server_id)
    if server.status == "ACTIVE":
        userproduct.instance_ip = server.server_ip
        userproduct.status = 2
    else:
        userproduct.status = 4
    g.db.flush()
    g.db.commit()
    return server.status
Exemplo n.º 7
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"))
Exemplo n.º 8
0
def fresh_server_status(user_product_id):
    import nova
    userproduct = g.db.query(UserProduct).get(user_product_id)
    api = nova.api()
    server = api.server_status(userproduct.server_id)
    if server.status=="ACTIVE":
        userproduct.instance_ip = server.server_ip
        userproduct.status = 2
    else:
        userproduct.status = 4
    g.db.flush()
    g.db.commit()
    return server.status
Exemplo n.º 9
0
def create_server(user_product_id, server_name, image_id, secury):
    import nova
    from json import loads
    from user.serv import get_user_tenant
    userproduct = g.db.query(UserProduct).get(user_product_id)
    usertenant = get_user_tenant(userproduct.user_id)
    keypair = loads(usertenant.keypair)
    product = g.db.query(Product).filter(Product.key==userproduct.product_key).one()
    rs, server_id = nova.api().create_server(server_name, product.flover_id, image_id, secury, keypair["keypair"]["name"])
    if rs:
        userproduct.image_id = image_id
        userproduct.instance_name = server_name
        userproduct.server_id = server_id
        userproduct.status = 1
    g.db.flush()
    g.db.commit()
    return server_id
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
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())
Exemplo n.º 13
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)
Exemplo n.º 14
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())
Exemplo n.º 15
0
def show_create_server(user_product_id):
    import nova
    userproduct = g.db.query(UserProduct).get(user_product_id)
    images = nova.api().get_images()
    return render_template("creator.html",**locals())
Exemplo n.º 16
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)