Beispiel #1
0
# -*- coding: utf-8 -*-
__author__ = 'liujiahua'
from flask import jsonify
from flask import request
from mana_api.api import zt_api
from mana_api.config import logging
from mana_api.api.vm.api_util import MyError, openstack_error
from mana_api.api.vm.tools.compute import InstanceManager
from mana_api.apiUtil import getUserProjByToken
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

logger = logging.getLogger(__name__)


@zt_api.route('/vm', methods=['GET'])
def vm():
    """
    :param project_id: 租户id
    :param region: 区域
    :param  f: 起始位置
    :param  t: 结束位置
    :return: 返回虚拟机列表
    """
    tenant_id = request.args.get('tenant_id', None)
    region = request.args.get('region', None)

    if not tenant_id or not region:
        return jsonify({"code": 400, "msg": "Could not find tenant_id or region"}), 400
Beispiel #2
0
# -*- coding: utf-8 -*-
# 星云延伸功能,如改密码,限速,创建私网
__author__ = 'liujiahua'
from flask import jsonify
from flask import request
from mana_api.api import zt_api
from mana_api.config import logging
from mana_api.apiUtil import getUserProjByToken
from mana_api.api.vm.api_util import MyError, chg_linux_pwd, chg_win_pwd
from .tools.compute import InstanceManager

logger = logging.getLogger(__name__)

@zt_api.route('/chgPwd/<tenant_id>/<region>/<uuid>/<pwd>', methods=['GET'])
def chg_pwd(tenant_id, region, uuid, pwd):
    if not tenant_id or not region:
        return jsonify({"code": 400, "msg": "Could not find tenant_id or region"}), 400

    # 禁止跨项目操作
    user = getUserProjByToken(tenant_id)
    if not user or tenant_id not in user.proj_dict.keys():
        return jsonify({"code": 403, "msg": "project is not yours"}), 403

    try:
        client = InstanceManager(token=user.token, endpoint=user.get_endpoint(region, 'nova'))
        instance = client.nova_show(uuid)
        chg_linux_pwd(instance, pwd)
        chg_win_pwd(instance, pwd)
    except MyError, e:
        logger.exception('MyError raised')
        return jsonify({"code": 400, "msg": '%s' % e.value}), 400