Ejemplo n.º 1
0
def update_template():
    handler = ApiPortal()
    handler_vm = SQLHandler()
    rep_data = json.loads(request.data)
    tem_name = rep_data["name"].strip()
    new_name = rep_data["new_name"].strip()
    interval = rep_data["interval_time"].strip()
    interval_begin = handler.api_get_template_interval(tem_name)
    host_list = handler.api_get_host_from_template(tem_name)
    if int(interval_begin) != int(interval):
        if host_list:
            for host in host_list:
                handler_vm.update_db("interval_time",interval_time=interval,hostname=host)
    if not handler.api_update_template(tem_name, new_name, interval):
        abort(500)
    data = handler.api_get_template(new_name)
    return jsonify(msg="success",data=data,action="update"),200
Ejemplo n.º 2
0
def add_many_vm():
    #### params: {"stra_name":"template_name","instances":[{"hostname":"hostname", "node":"compute01"}]}
    handler = SQLHandler()
    handler_model = ApiPortal()
    rep_data = json.loads(request.data)
    tem_name = rep_data["stra_name"].strip()
    instances_list = rep_data["instances"]
    state = 1
    ip = "192.168.1.1"
    interval_time = handler_model.api_get_template_interval(tem_name) or 300
    for instance in instances_list:
        ## instance is dict
        hostname = instance["hostname"]
        node = instance["node"]
        uuid = instance["uuid"]
        if not handler.update_db(hostname=hostname,node=node,interval_time=int(interval_time),
            uuid=uuid, state=state):
            abort(500)
######## add instance in table host
        handler.create_host(hostname,ip)
# add host in host group
        _insert_host_group(tem_name,hostname)
    return jsonify(msg="success",action="create"),200