예제 #1
0
파일: xenservernet.py 프로젝트: sadig/DC2
def xenserver_network_list(xenhost=None, session_id=None):
    if xenhost is not None and session_id is not None:
        s = xmlrpclib.ServerProxy(
            "https://{0}/".format(xenhost),
            allow_none=True)
        network_names = []
        network_list = parse_output(s.network.get_all(session_id))
        if network_list:
            for network in network_list:
                d = parse_output(s.network.get_record(session_id, network))
                d["network_id"] = network
                d["xen_host"] = xenhost
                d["session_id"] = session_id
                network_names.append(d)
            return network_names
    return None
예제 #2
0
파일: xen_login.py 프로젝트: sadig/DC2
def xenserver_login(xenhost=None, xenuser=None, xenpw=None):
    if xenhost is not None and xenuser is not None and xenpw is not None:
        try:
            s = xmlrpclib.ServerProxy("https://{0}/".format(xenhost))
            session_id = parse_output(
                s.session.login_with_password(
                    xenuser, xenpw))
            return session_id
        except Exception, e:
            return xmlrpclib.Fault(500, "Exception: {0}".format(e))
예제 #3
0
파일: xenserver_vms.py 프로젝트: sadig/DC2
def xenserver_get_vms(xenhost=None, session_id=None, vmtype=None):
    if xenhost is None:
        return False
    if session_id is None:
        return False
    if vmtype is None:
        return False
    if vmtype != "template" and vmtype != "vms" and vmtype != "both":
        return False
    s = xmlrpclib.ServerProxy("https://%s/" % xenhost, allow_none=True)
    vmlist = parse_output(s.VM.get_all(session_id))
    vmlist_dict = []
    if len(vmlist) > 0:
        for vm in vmlist:
            if (not parse_output(
                    s.VM.get_is_control_domain(
                        session_id, vm)) and
                    parse_output(s.VM.get_is_a_template(session_id, vm)) and
                    (vmtype == "template" or vmtype == "both")):
                vmlist_dict.append({
                    "session_id": session_id,
                    "xen_host": xenhost,
                    "vm_name": parse_output(
                        s.VM.get_name_label(session_id, vm)),
                    "vm_description": parse_output(
                        s.VM.get_name_description(session_id, vm)),
                    "vm_id": vm})
            if (not parse_output(
                s.VM.get_is_control_domain(session_id, vm)) and
                not parse_output(s.VM.get_is_a_template(session_id, vm)) and
                (vmtype == "vms" or
                    vmtype == "both")):
                vmlist_dict.append({
                    "session_id": session_id,
                    "xen_host": xenhost,
                    "vm_name": parse_output(
                        s.VM.get_name_label(session_id, vm)),
                    "vm_description": parse_output(
                        s.VM.get_name_description(session_id, vm)),
                    "vm_id": vm})
        return vmlist_dict
    return None
예제 #4
0
파일: xenserver_vms.py 프로젝트: sadig/DC2
def xenserver_get_vms_record(xenhost=None, session_id=None, vm_id=None):
    if xenhost is None:
        return None
    if session_id is None:
        return None
    if vm_id is None:
        return None
    try:
        s = xmlrpclib.ServerProxy("https://%s/" % xenhost, allow_none=True)
        vm_record = parse_output(s.VM.get_record(session_id, vm_id))
        for key in vm_record.keys():
            if isinstance(vm_record[key], xmlrpclib.DateTime):
                vm_record[key] = rpc_datetime_isoformat(vm_record[key])
        return vm_record
    except Exception, e:
        raise Exception(e)
예제 #5
0
파일: xenservernet.py 프로젝트: sadig/DC2
def xenserver_network_get_record(
    xenhost=None,
    session_id=None,
        network_id=None):
    if (xenhost is not None and
            session_id is not None and
            network_id is not None and
            xenhost != "" and
            session_id != "" and
            network_id != ""):
        s = xmlrpclib.ServerProx(
            "https://{0}/".format(xenhost),
            allow_none=True)
        d = parse_output(s.network.get_record(session_id, network_id))
        d["network_id"] = network_id
        d["xen_host"] = xenhost
        d["session_id"] = session_id
        return d
    return None