Exemple #1
0
def import_vapp(resource_pool,
                import_spec,
                host=None,
                folder=None,
                server=None):
    u"""Deploy VM

    @param resource_pool  Resource Pool name
    @param import_spec    Spec for VM
    @param host           Host name
    @param folder         DataCenter name
    @param server         Instance of VIServer
    """
    # Import
    from pysphere.resources import VimService_services as VI

    if not server:
        raise VIApiException('Not found server.')

    # hostがNoneでなければ取得してくる
    if host:
        hosts = server.get_hosts()
        host = [k for k, v in hosts.items() if v == host][0]
        if not host:
            raise ValueError("invalid ESXi host name")

    #get the vm folder MOR
    if folder:
        folder = find_vmfolder_by_name(folder)
    request = VI.ImportVAppRequestMsg()
    _this = request.new__this(resource_pool)
    _this.set_attribute_type(resource_pool.get_attribute_type())
    request.set_element__this(_this)
    request.set_element_spec(import_spec.ImportSpec)
    if host:
        h = request.new_host(host)
        h.set_attribute_type(host.get_attribute_type())
        request.set_element_host(h)
    if folder:
        f = request.new_folder(folder)
        f.set_attribute_type(folder.get_attribute_type())
        request.set_element_folder(f)
    return server._proxy.ImportVApp(request)._returnval
def import_vapp(resource_pool, import_spec, host=None, folder=None):
    #get the vm folder MOR
    if folder:
        folder = find_vmfolder_by_name(folder)
    request = VI.ImportVAppRequestMsg()
    _this = request.new__this(resource_pool)
    _this.set_attribute_type(resource_pool.get_attribute_type())
    request.set_element__this(_this)
    #print str(dir(import_spec))
    #print ""
    #print str(dir(import_spec.ImportSpec))
    request.set_element_spec(import_spec.ImportSpec)
    if host:
        h = request.new_host(host)
        h.set_attribute_type(host.get_attribute_type())
        request.set_element_host(h)
    if folder:
        f = request.new_folder(folder)
        f.set_attribute_type(folder.get_attribute_type())
        request.set_element_folder(f)
    return s._proxy.ImportVApp(request)._returnval