// getVirtualNetworkClient returns a new virtual network client.
338652
func (vm *VM) getVirtualNetworkClient() (virtualnetwork.VirtualNetworkClient, error) {
	c, err := vm.getClient()
	if err != nil {
		return virtualnetwork.VirtualNetworkClient{}, err
	}

	return virtualnetwork.NewClient(c), nil
}
811543
func (cf *ClientFactory) GetClient(ctx context.Context) (*Client, error) {
	cf.mux.Lock()
	defer cf.mux.Unlock()
	if cf.client == nil {
		var err error
		if cf.client, err = NewClient(ctx, cf.url, cf.parent); err != nil {
			return nil, err
		}
	}

	// Execute a dummy call against the server to make sure the client is
	// still functional. If not, try to log back in. If that doesn't work,
	// we give up.
	ctx1, cancel1 := context.WithTimeout(ctx, cf.parent.Timeout.Duration)
	defer cancel1()
	if _, err := methods.GetCurrentTime(ctx1, cf.client.Client); err != nil {
		log.Printf("I! [inputs.vsphere]: Client session seems to have time out. Reauthenticating!")
		ctx2, cancel2 := context.WithTimeout(ctx, cf.parent.Timeout.Duration)
		defer cancel2()
		if cf.client.Client.SessionManager.Login(ctx2, url.UserPassword(cf.parent.Username, cf.parent.Password)) != nil {
			return nil, fmt.Errorf("Renewing authentication failed: %v", err)
		}
	}

	return cf.client, nil
}
524695
func GetDockerNetworkName(nwID string) (string, string, string, error) {
	// first see if we can find the network in docknet oper state
	dnetOper, err := docknet.FindDocknetByUUID(nwID)
	if err == nil {
		return dnetOper.TenantName, dnetOper.NetworkName, dnetOper.ServiceName, nil
	}
	if pluginMode == core.SwarmMode {
		log.Errorf("Unable to find docknet info in objstore")
		return "", "", "", err
	}

	// create docker client
	docker, err := dockerclient.NewClient("unix:///var/run/docker.sock", "", nil, nil)
	if err != nil {
		log.Errorf("Unable to connect to docker. Error %v", err)
		return "", "", "", errors.New("unable to connect to docker")
	}

	nwIDFilter := filters.NewArgs()
	nwIDFilter.Add("id", nwID)
	nwList, err := docker.NetworkList(context.Background(), types.NetworkListOptions{Filters: nwIDFilter})
	if err != nil {
		log.Infof("Error: %v", err)
		return "", "", "", err
	}

	if len(nwList) != 1 {
		if len(nwList) == 0 {
			err = errors.New("network UUID not found")
		} else {
			err = errors.New("more than one network found with the same ID")
		}
		return "", "", "", err
	}
	nw := nwList[0]
	log.Infof("Returning network name %s for ID %s", nw.Name, nwID)

	// parse the network name
	var tenantName, netName, serviceName string
	names := strings.Split(nw.Name, "/")
	if len(names) == 2 {
		// has service.network/tenant format.
		tenantName = names[1]

		// parse service and network names
		sNames := strings.Split(names[0], ".")
		if len(sNames) == 2 {
			// has service.network format
			netName = sNames[1]
			serviceName = sNames[0]
		} else {
			netName = sNames[0]
		}
	} else if len(names) == 1 {
		// has service.network in default tenant
		tenantName = defaultTenantName

		// parse service and network names
		sNames := strings.Split(names[0], ".")
		if len(sNames) == 2 {
			// has service.network format
			netName = sNames[1]
			serviceName = sNames[0]
		} else {
			netName = sNames[0]
		}
	} else {
		log.Errorf("Invalid network name format for network %s", nw.Name)
		return "", "", "", errors.New("invalid format")
	}

	return tenantName, netName, serviceName, nil
}
1123839
func (c *controller) defaultGwNetwork() (Network, error) {
	procGwNetwork <- true
	defer func() { <-procGwNetwork }()

	n, err := c.NetworkByName(libnGWNetwork)
	if _, ok := err.(types.NotFoundError); ok {
		n, err = c.createGWNetwork()
	}
	return n, err
}
176886
func (f *FakeVtctlClient) FakeVtctlClientFactory(addr string) (vtctlclient.VtctlClient, error) {
	return f, nil
}
875357
func (a *Client) GetWorkflowsInstanceID(params *GetWorkflowsInstanceIDParams, authInfo runtime.ClientAuthInfoWriter) (*GetWorkflowsInstanceIDOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewGetWorkflowsInstanceIDParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "GetWorkflowsInstanceID",
		Method:             "GET",
		PathPattern:        "/workflows/{instanceId}",
		ProducesMediaTypes: []string{"application/json", "application/x-gzip"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http", "https"},
		Params:             params,
		Reader:             &GetWorkflowsInstanceIDReader{formats: a.formats},
		AuthInfo:           authInfo,
	})
	if err != nil {
		return nil, err
	}
	return result.(*GetWorkflowsInstanceIDOK), nil
}
446802
func GetVHost(conn client.Connection, key VHostKey) (string, string, error) {
	pth := path.Join("/net/vhost", key.HostID, key.Subdomain)

	logger := plog.WithFields(log.Fields{
		"hostid":    key.HostID,
		"subdomain": key.Subdomain,
		"zkpath":    pth,
	})

	vhost := &VHost{}
	err := conn.Get(pth, vhost)
	if err == client.ErrNoNode {
		logger.WithError(err).Debug("Virtual host subdomain not found")
		return "", "", nil
	} else if err != nil {
		logger.WithError(err).Debug("Could not look up virtual host subdomain")
		return "", "", &RegistryError{
			Action:  "get",
			Path:    pth,
			Message: "could not look up virtual host subdomain",
		}
	}

	logger.WithFields(log.Fields{
		"tenantid":    vhost.TenantID,
		"application": vhost.Application,
	}).Debug("Found vhost subdomain")

	return vhost.ServiceID, vhost.Application, nil
}
888257
func (as *availabilitySet) getPrimaryInterfaceWithVMSet(nodeName, vmSetName string) (network.Interface, error) {
	var machine compute.VirtualMachine

	machine, err := as.GetVirtualMachineWithRetry(types.NodeName(nodeName))
	if err != nil {
		klog.V(2).Infof("GetPrimaryInterface(%s, %s) abort backoff", nodeName, vmSetName)
		return network.Interface{}, err
	}

	primaryNicID, err := getPrimaryInterfaceID(machine)
	if err != nil {
		return network.Interface{}, err
	}
	nicName, err := getLastSegment(primaryNicID)
	if err != nil {
		return network.Interface{}, err
	}
	nodeResourceGroup, err := as.GetNodeResourceGroup(nodeName)
	if err != nil {
		return network.Interface{}, err
	}

	// Check availability set name. Note that vmSetName is empty string when getting
	// the Node's IP address. While vmSetName is not empty, it should be checked with
	// Node's real availability set name:
	// - For basic SKU load balancer, errNotInVMSet should be returned if the node's
	//   availability set is mismatched with vmSetName.
	// - For standard SKU load balancer, backend could belong to multiple VMAS, so we
	//   don't check vmSet for it.
	if vmSetName != "" && !as.useStandardLoadBalancer() {
		expectedAvailabilitySetName := as.getAvailabilitySetID(nodeResourceGroup, vmSetName)
		if machine.AvailabilitySet == nil || !strings.EqualFold(*machine.AvailabilitySet.ID, expectedAvailabilitySetName) {
			klog.V(3).Infof(
				"GetPrimaryInterface: nic (%s) is not in the availabilitySet(%s)", nicName, vmSetName)
			return network.Interface{}, errNotInVMSet
		}
	}

	nicResourceGroup, err := extractResourceGroupByNicID(primaryNicID)
	if err != nil {
		return network.Interface{}, err
	}

	ctx, cancel := getContextWithCancel()
	defer cancel()
	nic, err := as.InterfacesClient.Get(ctx, nicResourceGroup, nicName, "")
	if err != nil {
		return network.Interface{}, err
	}

	return nic, nil
}
537565
func (a *Client) GetWorkflowsTasksLibrary(params *GetWorkflowsTasksLibraryParams, authInfo runtime.ClientAuthInfoWriter) (*GetWorkflowsTasksLibraryOK, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewGetWorkflowsTasksLibraryParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "GetWorkflowsTasksLibrary",
		Method:             "GET",
		PathPattern:        "/workflows/tasks/library",
		ProducesMediaTypes: []string{"application/json", "application/x-gzip"},
		ConsumesMediaTypes: []string{"application/json"},
		Schemes:            []string{"http", "https"},
		Params:             params,
		Reader:             &GetWorkflowsTasksLibraryReader{formats: a.formats},
		AuthInfo:           authInfo,
	})
	if err != nil {
		return nil, err
	}
	return result.(*GetWorkflowsTasksLibraryOK), nil
}
48581
func (c *VSphereCloud) GetVirtualMachines(args []string) ([]*object.VirtualMachine, error) {
	var out []*object.VirtualMachine

	// List virtual machines
	if len(args) == 0 {
		return nil, errors.New("no argument")
	}

	f := find.NewFinder(c.Client.Client, true)
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	dc, err := f.Datacenter(ctx, c.Datacenter)
	if err != nil {
		return nil, err
	}
	f.SetDatacenter(dc)

	var nfe error

	// List virtual machines for every argument
	for _, arg := range args {
		vms, err := f.VirtualMachineList(context.TODO(), arg)
		if err != nil {
			if _, ok := err.(*find.NotFoundError); ok {
				// Let caller decide how to handle NotFoundError
				nfe = err
				continue
			}
			return nil, err
		}

		out = append(out, vms...)
	}

	return out, nfe
}
926918
func (i ImportBinding) GetVirtualAddress(instanceID int) (string, error) {
	t := template.Must(template.New(i.Application).Funcs(funcs).Parse(i.VirtualAddress))

	var buffer bytes.Buffer
	if err := t.Execute(&buffer, struct{ InstanceID int }{instanceID}); err != nil {
		return "", &TemplateError{
			Application: i.Application,
			Field:       i.VirtualAddress,
			Message:     "could not interpret value",
		}
	}

	return buffer.String(), nil
}
979301
func (c *Client) GetVirtualMachineUserData(p *GetVirtualMachineUserDataParameter) (*VirtualMachineUserData, error) {
	obj, err := c.Request("getVirtualMachineUserData", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*VirtualMachineUserData), err
}
1002453
func (vm *VM) getNetworkInterfaces() []*compute.NetworkInterface {
	if len(vm.Attributes.GetNetworkInterface()) == 0 {
		return nil
	}
	nics := make([]*compute.NetworkInterface, len(vm.Attributes.NetworkInterface))
	for i, nic := range vm.Attributes.NetworkInterface {
		nics[i] = &compute.NetworkInterface{
			Network: nic.Network,
		}
		if len(nic.GetAccessConfig()) > 0 {
			nics[i].AccessConfigs = make([]*compute.AccessConfig, len(nic.AccessConfig))
			for j, cfg := range nic.AccessConfig {
				nics[i].AccessConfigs[j] = &compute.AccessConfig{
					Type: cfg.Type.String(),
				}
			}
		}
	}
	return nics
}
705831
func (runner *runner) GetVirtualServer(vs *VirtualServer) (*VirtualServer, error) {
	svc, err := toIPVSService(vs)
	if err != nil {
		return nil, err
	}
	runner.mu.Lock()
	ipvsSvc, err := runner.ipvsHandle.GetService(svc)
	runner.mu.Unlock()

	if err != nil {
		return nil, err
	}
	vServ, err := toVirtualServer(ipvsSvc)
	if err != nil {
		return nil, err
	}
	return vServ, nil
}
697058
func (uvm *UtilityVM) isNetworkNamespaceSupported() bool {
	p, err := uvm.ComputeSystem().Properties(schema1.PropertyTypeGuestConnection)
	if err == nil {
		return p.GuestConnectionInfo.GuestDefinedCapabilities.NamespaceAddRequestSupported
	}

	return false
}
399715
func getNetwork(svc *compute.Service, networkProjectID, networkID string) (*compute.Network, error) {
	return svc.Networks.Get(networkProjectID, networkID).Do()
}
1316788
func getV6Network(config *networkConfiguration, i *bridgeInterface) *net.IPNet {
	if config.AddressIPv6 != nil {
		return config.AddressIPv6
	}
	if i.bridgeIPv6 != nil && i.bridgeIPv6.IP != nil && !i.bridgeIPv6.IP.IsLinkLocalUnicast() {
		return i.bridgeIPv6
	}

	return nil
}