// Changes the default NIC on a VM
176654
func (c *Client) UpdateDefaultNicForVirtualMachine(p *UpdateDefaultNicForVirtualMachineParameter) (*VirtualMachine, error) {
	obj, err := c.Request("updateDefaultNicForVirtualMachine", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*VirtualMachine), err
}
928421
func SetDefaults_DNS(obj *ClusterConfiguration) {
	if obj.DNS.Type == "" {
		obj.DNS.Type = CoreDNS
	}
}
631440
func (b *BigIP) PatchVirtualServer(name string, config *VirtualServer) error {
	return b.patch(config, uriLtm, uriVirtual, name)
}
296241
func (t *VLANsTable) computeChanges(c context.Context, vlans []*config.VLAN) {
	cfgs := make(map[int64]*VLAN, len(vlans))
	for _, cfg := range vlans {
		cfgs[cfg.Id] = &VLAN{
			VLAN: config.VLAN{
				Id:        cfg.Id,
				Alias:     cfg.Alias,
				State:     cfg.State,
				CidrBlock: cfg.CidrBlock,
			},
		}
	}

	for _, vlan := range t.current {
		if cfg, ok := cfgs[vlan.Id]; ok {
			// VLAN found in the config.
			if t.needsUpdate(vlan, cfg) {
				// VLAN doesn't match the config.
				t.updates = append(t.updates, cfg)
			}
			// Record that the VLAN config has been seen.
			delete(cfgs, cfg.Id)
		} else {
			// VLAN not found in the config.
			t.removals = append(t.removals, vlan)
		}
	}

	// VLANs remaining in the map are present in the config but not the database.
	// Iterate deterministically over the slice to determine which VLANs need to be added.
	for _, cfg := range vlans {
		if p, ok := cfgs[cfg.Id]; ok {
			t.additions = append(t.additions, p)
		}
	}
}
311207
func defaultIP(addr *net.TCPAddr) string {
	if !addr.IP.IsUnspecified() {
		return addr.IP.String()
	}

	nics, err := net.Interfaces()
	if err != nil {
		return addr.IP.String()
	}

	for _, nic := range nics {
		if nic.Name == "docker0" || strings.HasPrefix(nic.Name, "vmnet") {
			continue
		}
		addrs, aerr := nic.Addrs()
		if aerr != nil {
			continue
		}
		for _, addr := range addrs {
			if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
				if ip.IP.To4() != nil {
					return ip.IP.String()
				}
			}
		}
	}

	return addr.IP.String()
}
1010476
func (b *BigIP) ModifyVirtualAddress(vaddr string, config *VirtualAddress) error {
	return b.put(config, uriLtm, uriVirtualAddress, vaddr)
}
263029
func (s *VirtualMachineService) ChangeServiceForVirtualMachine(p *ChangeServiceForVirtualMachineParams) (*ChangeServiceForVirtualMachineResponse, error) {
	resp, err := s.cs.newRequest("changeServiceForVirtualMachine", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r ChangeServiceForVirtualMachineResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
1371375
func (vmap *masterVNIDMap) assignVNID(networkClient networkclient.Interface, nsName string) error {
	vmap.lock.Lock()
	defer vmap.lock.Unlock()

	netid, exists, err := vmap.allocateNetID(nsName)
	if err != nil {
		return err
	}

	if !exists {
		// Create NetNamespace Object and update vnid map
		netns := &networkv1.NetNamespace{
			TypeMeta:   metav1.TypeMeta{Kind: "NetNamespace"},
			ObjectMeta: metav1.ObjectMeta{Name: nsName},
			NetName:    nsName,
			NetID:      netid,
		}
		if _, err := networkClient.NetworkV1().NetNamespaces().Create(netns); err != nil {
			if er := vmap.releaseNetID(nsName); er != nil {
				utilruntime.HandleError(er)
			}
			return err
		}
	}
	return nil
}
1220162
func (s *VirtualMachineService) RebootVirtualMachine(p *RebootVirtualMachineParams) (*RebootVirtualMachineResponse, error) {
	resp, err := s.cs.newRequest("rebootVirtualMachine", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r RebootVirtualMachineResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
1153485
func (runner *runner) UpdateVirtualServer(vs *VirtualServer) error {
	svc, err := toIPVSService(vs)
	if err != nil {
		return err
	}
	runner.mu.Lock()
	defer runner.mu.Unlock()
	return runner.ipvsHandle.UpdateService(svc)
}
1074190
func (vm VirtualMachine) NicsByType(nicType string) []Nic {
	nics := make([]Nic, 0)
	for _, nic := range vm.Nic {
		if nic.Type == nicType {
			// XXX The API forgets to specify it
			n := nic
			n.VirtualMachineID = vm.ID
			nics = append(nics, n)
		}
	}
	return nics
}
222621
func DefaultEnvConfig() (*Config, error) {
	if !env.OnGCE() {
		return nil, nil
	}
	auth := "none"
	user, _ := metadata.InstanceAttributeValue("camlistore-username")
	pass, _ := metadata.InstanceAttributeValue("camlistore-password")
	confBucket, err := metadata.InstanceAttributeValue("camlistore-config-dir")
	if confBucket == "" || err != nil {
		return nil, fmt.Errorf("VM instance metadata key 'camlistore-config-dir' not set: %v", err)
	}
	blobBucket, err := metadata.InstanceAttributeValue("camlistore-blob-dir")
	if blobBucket == "" || err != nil {
		return nil, fmt.Errorf("VM instance metadata key 'camlistore-blob-dir' not set: %v", err)
	}
	if user != "" && pass != "" {
		auth = "userpass:" + user + ":" + pass
	}

	if v := osutil.SecretRingFile(); !strings.HasPrefix(v, "/gcs/") {
		return nil, fmt.Errorf("Internal error: secret ring path on GCE should be at /gcs/, not %q", v)
	}
	keyID, secRing, err := getOrMakeKeyring()
	if err != nil {
		return nil, err
	}

	highConf := &serverconfig.Config{
		Auth:               auth,
		HTTPS:              true,
		Identity:           keyID,
		IdentitySecretRing: secRing,
		GoogleCloudStorage: ":" + strings.TrimPrefix(blobBucket, "gs://"),
		PackRelated:        true,
		ShareHandler:       true,
	}

	externalIP, _ := metadata.ExternalIP()
	hostName, _ := metadata.InstanceAttributeValue("camlistore-hostname")
	// If they specified a hostname (probably with pk-deploy), then:
	// if it looks like an FQDN, perkeepd is going to rely on Let's
	// Encrypt, else perkeepd is going to generate some self-signed for that
	// hostname.
	// Also, if the hostname is in camlistore.net, we want Perkeep to initialize
	// exactly as if the instance had no hostname, so that it registers its hostname/IP
	// with the camlistore.net DNS server (possibly needlessly, if the instance IP has
	// not changed) again.
	if hostName != "" && !strings.HasSuffix(hostName, CamliNetDomain) {
		highConf.BaseURL = fmt.Sprintf("https://%s", hostName)
		highConf.Listen = "0.0.0.0:443"
	} else {
		highConf.CamliNetIP = externalIP
	}

	// Detect a linked Docker MySQL container. It must have alias "mysqldb".
	mysqlPort := os.Getenv("MYSQLDB_PORT")
	if !strings.HasPrefix(mysqlPort, "tcp://") {
		// No MySQL
		// TODO: also detect Cloud SQL.
		highConf.KVFile = "/index.kv"
		return genLowLevelConfig(highConf)
	}
	hostPort := strings.TrimPrefix(mysqlPort, "tcp://")
	highConf.MySQL = "root@" + hostPort + ":" // no password
	configVersion, err := metadata.InstanceAttributeValue("perkeep-config-version")
	if configVersion == "" || err != nil {
		// the launcher is deploying a pre-"perkeep-config-version" Perkeep, which means
		// we want the old configuration, with DBNames
		highConf.DBUnique = useDBNamesConfig
	} else if configVersion != "1" {
		return nil, fmt.Errorf("unexpected value for VM instance metadata key 'perkeep-config-version': %q", configVersion)
	}

	conf, err := genLowLevelConfig(highConf)
	if err != nil {
		return nil, err
	}

	if err := conf.readFields(); err != nil {
		return nil, err
	}
	return conf, nil
}
665235
func DefaultVaultConfig() *VaultConfig {
	return &VaultConfig{
		Addr:                "https://vault.service.consul:8200",
		ConnectionRetryIntv: DefaultVaultConnectRetryIntv,
		AllowUnauthenticated: func(b bool) *bool {
			return &b
		}(true),
	}
}
872269
func (d *HypervPS4Driver) ReplaceVirtualMachineNetworkAdapter(vmName string, virtual bool) error {
	return hyperv.ReplaceVirtualMachineNetworkAdapter(vmName, virtual)
}
427106
func (d *domainClient) SetVirtualTimePolicy(ctx context.Context, args *SetVirtualTimePolicyArgs) (reply *SetVirtualTimePolicyReply, err error) {
	reply = new(SetVirtualTimePolicyReply)
	if args != nil {
		err = rpcc.Invoke(ctx, "Emulation.setVirtualTimePolicy", args, reply, d.conn)
	} else {
		err = rpcc.Invoke(ctx, "Emulation.setVirtualTimePolicy", nil, reply, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: "Emulation", Op: "SetVirtualTimePolicy", Err: err}
	}
	return
}
583242
func (o HostNetworkSystem) UpdateNetworkConfig(ctx context.Context, config types.HostNetworkConfig, changeMode string) (*types.HostNetworkConfigResult, error) {
	req := types.UpdateNetworkConfig{
		This:       o.Reference(),
		Config:     config,
		ChangeMode: changeMode,
	}

	res, err := methods.UpdateNetworkConfig(ctx, o.c, &req)
	if err != nil {
		return nil, err
	}

	return &res.Returnval, nil
}
176369
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
	var settings types.DefaultNetworkSettings

	if defaultNetwork, ok := networks["bridge"]; ok && defaultNetwork.EndpointSettings != nil {
		settings.EndpointID = defaultNetwork.EndpointID
		settings.Gateway = defaultNetwork.Gateway
		settings.GlobalIPv6Address = defaultNetwork.GlobalIPv6Address
		settings.GlobalIPv6PrefixLen = defaultNetwork.GlobalIPv6PrefixLen
		settings.IPAddress = defaultNetwork.IPAddress
		settings.IPPrefixLen = defaultNetwork.IPPrefixLen
		settings.IPv6Gateway = defaultNetwork.IPv6Gateway
		settings.MacAddress = defaultNetwork.MacAddress
	}
	return settings
}