Example #1
0
def create_vm(controller_id, ucpe_sn):
    # precondition: it must be possible to create a vm from the given parameters (sufficient memory, hugepage memory, etc)
    method = 'define_vm_from_params'
    data = request.get_json()
    # TODO: database for image paths
    form = data["form"]
    UNTAGGED_VLAN_INDICATOR = '0' #magic string - this is REALLLY bad - fix in grpc api
    vlans = [interface['vlan'] for interface in form['vmOVSInterfaceVLANs']]
    for i in range(len(vlans)):
        if vlans[i] == '':
            vlans[i] = UNTAGGED_VLAN_INDICATOR  # todo: change this to a map
    create_vm_ovs_interfaces(form['vmName'], int(form['vmOVSInterfaceCount']), vlans)
    image_file = IMAGE_FILE_INFO[form['vmImage']]['filename']
    image_path = os.path.join(IMAGE_ACTIVE_PATH, form['vmName'], image_file)
    body = {
        "username": HOST_USERNAME,
        "hostname": HOST_IP,
        "vm_name": form['vmName'],
        "vm_image_path": image_path,
        "vm_memory": parseMemoryGB(form['vmMemory']),
        "vm_vcpu_count": form['vmCPUs'],
        "vm_use_hugepages": form['hugepagesEnabled'],
        "vm_hugepage_memory": parseMemoryGB(form['vmHugepageMemory']),
        "vm_ovs_interface_count": int(form['vmOVSInterfaceCount']),
    }
    if form['vmBridge'] != 'No Bridge':
        body['vm_bridge_name'] = form['vmBridge']
    message_data = get_message_data(method, body)
    response = call_ucpe_function(message_data, controller_id, ucpe_sn)
    return jsonify(response)
Example #2
0
def set_pvlans(vlanid, pbm):
    messagedata = {"method": "bcm_controller_set_pvlan", "params": {
        "body": {"hostname": "10.10.81.250", "port": "50051",
                 "vlanid": int(vlanid), "pbm": pbm}},
                   "jsonrpc": "2.0", "id": 0
                   }
    return jsonify(call_ucpe_function(messagedata))
Example #3
0
def create_network():
    network_name = request.args.get('create_name')
    driver = request.args.get('create_driver')
    scope = request.args.get('create_scope')
    subnet = request.args.get('create_subnet')
    gateway = request.args.get('create_gateway')
    enable_ipv6 = request.args.get('create_ipv6')
    messagedata = {
        "method": "docker_controller_create_network",
        "params": {
            "body": {
                "network_name": network_name,
                'driver': driver,
                'scope': scope,
                'subnet': subnet,
                'gateway': gateway,
                'enable_ipv6': enable_ipv6,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #4
0
def all_vm_info(controller_id, ucpe_sn):
    method = 'get_all_vm_info'
    body = {"username": HOST_USERNAME, "hostname": HOST_IP}
    message_data = get_message_data(method, body)
    response = call_ucpe_function(message_data, controller_id, ucpe_sn)
    rename_images(response)
    return jsonify(response)
Example #5
0
def prepare_vm_console(controller_id, ucpe_sn, vm_name):
    get_vnc_port_method = 'get_vm_vnc_port'
    body = {"username": HOST_USERNAME, "hostname": HOST_IP, 'vm_name': vm_name}
    message_data = get_message_data(get_vnc_port_method, body)
    response = call_ucpe_function(message_data, controller_id, ucpe_sn)
    print(response)
    ucpe_vnc_port = response['result']['return']

    # if vnc_process is not None:
    #     vnc_process.terminate()
    #     print("terminating")
    # todo: error handling
    # vnc_process = Process(target = prepare_vm_console_helper, args=(HOST_IP, vnc_port))
    # vnc_process.start()
    local_vnc_port = 6080
    kill_subprocess = pexpect.spawn(f'fuser -k {local_vnc_port}/tcp',
                                    timeout=None)  # timeout=None means wait indefinitely
    # kill_subprocess.expect(f'{local_vnc_port}/tcp')
    # kill_subprocess.expect(f'{local_vnc_port}')
    # print('before', kill_subprocess.before)
    # print('after', kill_subprocess.after)
    # print("starting sleep")
    time.sleep(3)  # todo: remove the need for this
    # print("ending sleep")
    # result = prepare_vm_console_helper(HOST_IP, vnc_port)
    prepare_vm_console_helper(HOST_IP, ucpe_vnc_port, local_vnc_port)
    return jsonify(result="attempted to start vnc console", warning="no error handling")  # todo: error handling
def ovs_docker_add_port():
    bridge = 'br0'
    interface = request.args.get('ovs_int')
    # print(interface)
    container = request.args.get('create_name')
    # print(container)
    port = request.args.get('int_port')
    # print(port)
    ipaddress = request.args.get('int_ip')
    vlan = request.args.get('vlan_tag')
    # print(ipaddress)
    messagedata = {
        "method": "grpc_modify_ovs_docker_add_port",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051",
                "str_param1": f'{bridge}',
                "str_param2": f'{interface}',
                "str_param3": f'{container}',
                "str_param4": f'{port}',
                "str_param5": f'{ipaddress}',
                "str_param6": f'{vlan}'
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #7
0
def list_images():
    messagedata = {
        "method": "docker_controller_list_images",
        "params": {
            "body": {}
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
def total_mem():
    messagedata = {
        "method": "grpc_get_totalmem",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
def linux_bridge_list():
    messagedata = {
        "method": "grpc_get_linux_bridges_list",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
def get_net_devices():
    messagedata = {
        "method": "grpc_get_dpdk_devices",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
def hugepage_free_mem_bytes():
    messagedata = {
        "method": "grpc_get_hugepages_freemem_b",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #12
0
def list_volumes():
    messagedata = {
        "method": "docker_controller_list_volumes",
        "params": {
            "body": {
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
def ovs_del_port_helper(vm_name):
    bridge = 'br0'
    messagedata = {
        "method": "grpc_modify_ovs_del_port",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051",
                "str_param1": f'{bridge}',
                "str_param2": f'{vm_name}'
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    # return jsonify(call_ucpe_function(messagedata))
    return call_ucpe_function(messagedata)
def dpdk_bind():
    slot = request.args.get('slot')
    current_driver = request.args.get('current_driver')
    messagedata = {
        "method": "grpc_modify_dpdk_bind",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051",
                "str_param1": f'{slot}',
                "str_param2": f'{current_driver}'
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #15
0
def create_volume():
    name = request.args.get('name')
    messagedata = {
        "method": "docker_controller_create_volume",
        "params": {
            "body": {
                "name": name,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #16
0
def remove_network():
    network_id = request.args.get('net_id')
    messagedata = {
        "method": "docker_controller_remove_network",
        "params": {
            "body": {
                "network_id": network_id,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
def ovs_add_port_helper(if_port, type, vlan):
    bridge = 'br0'
    messagedata = {
        "method": "grpc_modify_ovs_add_port",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051",
                "str_param1": bridge,
                "str_param2": if_port,
                "str_param3": type,
                "str_param4": vlan
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return call_ucpe_function(messagedata)
def ovs_docker_del_port():
    bridge = 'br0'
    container = request.args.get('container')
    messagedata = {
        "method": "grpc_modify_ovs_docker_del_port",
        "params": {
            "body": {
                "hostname": "10.10.81.100",
                "port": "50051",
                "str_param1": f'{bridge}',
                "str_param2": f'{container}'
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    # return jsonify(call_ucpe_function(messagedata))
    p = call_ucpe_function(messagedata)
    return jsonify(p)
Example #19
0
def rename_container():
    newName = request.args.get('newName')
    id_name = request.args.get('id_name')
    messagedata = {
        'method': 'docker_controller_rename_container',
        "params": {
            "body": {
                "newName": newName,
                'id_name': id_name,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #20
0
def change_status():
    change_to = request.args.get('change_to')
    id_name = request.args.get('id_name')
    messagedata = {
        "method": "docker_controller_change_status",
        "params": {
            "body": {
                "change_to": change_to,
                'id_name': id_name,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #21
0
def pull_image():
    name = request.args.get('name')
    tag = request.args.get('tag')
    # registry = request.args.get('pull_registry')
    # timeout = request.args.get('timeout')
    messagedata = {
        "method": "docker_controller_pull_image",
        "params": {
            "body": {
                "repo": name,
                "tag": tag,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #22
0
def commit():
    id_name = request.args.get('id_name')
    repo = request.args.get('repo')
    tag = request.args.get('tag')
    messagedata = {
        "method": "docker_controller_commit",
        "params": {
            "body": {
                "id_name": id_name,
                "repo": repo,
                "tag": tag,
                "username": "******",
                "hostname": "10.10.81.100",
                "vm_name": "test",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }
    return jsonify(call_ucpe_function(messagedata))
Example #23
0
def create_container():
    image_name = request.args.get('create_image')
    name = request.args.get('create_name')
    port = request.args.get('create_port')
    messagedata = {
        "method": "docker_controller_create_container",
        "params": {
            "body": {
                'image_name': image_name,
                'name': name,
                'ports': port,
                "username": "******",
                "hostname": "10.10.81.100",
                "all": "True",
                "autostart": 1,
                "save_path": "/home/potato/save_path.test"
            }
        },
        "jsonrpc": "2.0",
        "id": 0
    }

    return jsonify(call_ucpe_function(messagedata))
Example #24
0
def _handle_state_change(method, controller_id, ucpe_sn):
    data = request.get_json()
    body = {"username": HOST_USERNAME, "hostname": HOST_IP, "vm_names": data["vm_names"]}
    message_data = get_message_data(method, body)
    response = call_ucpe_function(message_data, controller_id, ucpe_sn)
    return jsonify(response)
Example #25
0
def show_pvlans():
    messagedata = {"method": "bcm_controller_show_pvlans", "params": {
        "body": {"hostname": "10.10.81.250", "port": "50051"}},
                   "jsonrpc": "2.0", "id": 0
                   }
    return jsonify(call_ucpe_function(messagedata))
Example #26
0
def destroy_vlan(vlanid):
    messagedata = {"method": "bcm_controller_destroy_vlan", "params": {
        "body": {"hostname": "10.10.81.250", "port": "50051", "vlanid": int(vlanid)}},
                   "jsonrpc": "2.0", "id": 0
                   }
    return jsonify(call_ucpe_function(messagedata))
Example #27
0
# print(red)

# print(VIR_DOMAIN_NOSTATE)
# print(VIR_DOMAIN_RUNNING)
# print(VIR_DOMAIN_BLOCKED)
# print(VIR_DOMAIN_PAUSED)
# print(VIR_DOMAIN_SHUTDOWN)
# print(VIR_DOMAIN_SHUTOFF)
# print(VIR_DOMAIN_CRASHED)
# print(VIR_DOMAIN_PMSUSPENDED)

start()
sleep(2)
messagedata = {
    "method": "libvirt_controller_get_all_vm_info",
    "params": {
        "body": {
            "username": "******",
            "hostname": "10.10.81.100",
            "vm_name": "test",
            "autostart": 1,
            "save_path": "/home/potato/save_path.test"
        }
    },
    "jsonrpc": "2.0",
    "id": 0
}

result = call_ucpe_function(messagedata)
print(result)