// ProvisioningInfo implements MachineProvisioner.ProvisioningInfo.
349392
func (m *Machine) ProvisioningInfo() (*params.ProvisioningInfo, error) {
	var results params.ProvisioningInfoResults
	args := params.Entities{Entities: []params.Entity{{m.tag.String()}}}
	err := m.st.facade.FacadeCall("ProvisioningInfo", args, &results)
	if err != nil {
		return nil, err
	}
	if len(results.Results) != 1 {
		return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, result.Error
	}
	return result.Result, nil
}
1242588
func (s *Server) ImageFsInfo(ctx context.Context, req *pb.ImageFsInfoRequest) (resp *pb.ImageFsInfoResponse, err error) {
	const operation = "image_fs_info"
	defer func() {
		recordOperation(operation, time.Now())
		recordError(operation, err)
	}()

	store := s.StorageImageServer().GetStore()
	fsUsage, err := getStorageFsInfo(store)

	if err != nil {
		return nil, err
	}

	return &pb.ImageFsInfoResponse{
		ImageFilesystems: []*pb.FilesystemUsage{fsUsage},
	}, nil
}
14840
func (s *Service) AppSetupInfo(ctx context.Context, appSetupIdentity string) (*AppSetup, error) {
	var appSetup AppSetup
	return &appSetup, s.Get(ctx, &appSetup, fmt.Sprintf("/app-setups/%v", appSetupIdentity), nil, nil)
}
666315
func (vm *VM) Provision() error {

	if vm.Template.ID == "" {
		if err := vm.fillTemplateID(); err != nil {
			return err
		}
	}

	if vm.ServiceOffering.ID == "" {
		if err := vm.fillServiceOfferingID(); err != nil {
			return err
		}
	}

	for _, sg := range vm.SecurityGroups {
		if sg.ID == "" {
			vm.fillSecurityGroupsID()
			break
		}
	}

	if vm.Zone.ID == "" {
		if err := vm.fillZoneID(); err != nil {
			return err
		}
	}

	securityGroups := make([]string, len(vm.SecurityGroups))
	for i := range vm.SecurityGroups {
		securityGroups[i] = vm.SecurityGroups[i].ID
	}

	profile := egoscale.MachineProfile{
		Template:        vm.Template.ID,
		ServiceOffering: vm.ServiceOffering.ID,
		SecurityGroups:  securityGroups,
		Keypair:         vm.KeypairName,
		Userdata:        vm.Userdata,
		Zone:            vm.Zone.ID,
		Name:            vm.Name,
	}

	client := vm.getExoClient()
	jobID, err := client.CreateVirtualMachine(profile)
	if err != nil {
		return err
	}

	vm.JobID = jobID

	return nil
}
1106416
func (c *Client) OAuthAuthorizationInfo(oauthAuthorizationIdentity string) (*OAuthAuthorization, error) {
	var oauthAuthorization OAuthAuthorization
	return &oauthAuthorization, c.Get(&oauthAuthorization, "/oauth/authorizations/"+oauthAuthorizationIdentity)
}
1152820
func (nc *Conn) processInfo(info string) error {
	if info == _EMPTY_ {
		return nil
	}
	ncInfo := serverInfo{}
	if err := json.Unmarshal([]byte(info), &ncInfo); err != nil {
		return err
	}

	// Copy content into connection's info structure.
	nc.info = ncInfo
	// The array could be empty/not present on initial connect,
	// if advertise is disabled on that server, or servers that
	// did not include themselves in the async INFO protocol.
	// If empty, do not remove the implicit servers from the pool.
	if len(ncInfo.ConnectURLs) == 0 {
		return nil
	}
	// Note about pool randomization: when the pool was first created,
	// it was randomized (if allowed). We keep the order the same (removing
	// implicit servers that are no longer sent to us). New URLs are sent
	// to us in no specific order so don't need extra randomization.
	hasNew := false
	// This is what we got from the server we are connected to.
	urls := nc.info.ConnectURLs
	// Transform that to a map for easy lookups
	tmp := make(map[string]struct{}, len(urls))
	for _, curl := range urls {
		tmp[curl] = struct{}{}
	}
	// Walk the pool and removed the implicit servers that are no longer in the
	// given array/map
	sp := nc.srvPool
	for i := 0; i < len(sp); i++ {
		srv := sp[i]
		curl := srv.url.Host
		// Check if this URL is in the INFO protocol
		_, inInfo := tmp[curl]
		// Remove from the temp map so that at the end we are left with only
		// new (or restarted) servers that need to be added to the pool.
		delete(tmp, curl)
		// Keep servers that were set through Options, but also the one that
		// we are currently connected to (even if it is a discovered server).
		if !srv.isImplicit || srv.url == nc.current.url {
			continue
		}
		if !inInfo {
			// Remove from server pool. Keep current order.
			copy(sp[i:], sp[i+1:])
			nc.srvPool = sp[:len(sp)-1]
			sp = nc.srvPool
			i--
		}
	}
	// Figure out if we should save off the current non-IP hostname if we encounter a bare IP.
	saveTLS := nc.current != nil && !hostIsIP(nc.current.url)

	// If there are any left in the tmp map, these are new (or restarted) servers
	// and need to be added to the pool.
	for curl := range tmp {
		// Before adding, check if this is a new (as in never seen) URL.
		// This is used to figure out if we invoke the DiscoveredServersCB
		if _, present := nc.urls[curl]; !present {
			hasNew = true
		}
		nc.addURLToPool(fmt.Sprintf("%s://%s", nc.connScheme(), curl), true, saveTLS)
	}
	if hasNew && !nc.initc && nc.Opts.DiscoveredServersCB != nil {
		nc.ach.push(func() { nc.Opts.DiscoveredServersCB(nc) })
	}

	return nil
}
141186
func (m *MockMachineProvisioner) ProvisioningInfo() (*params.ProvisioningInfo, error) {
	ret := m.ctrl.Call(m, "ProvisioningInfo")
	ret0, _ := ret[0].(*params.ProvisioningInfo)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
638277
func (c *SystemInfo) GetProcessInfo() ([]*SystemInfoProcessInfo, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "SystemInfo.getProcessInfo"})
	if err != nil {
		return nil, err
	}

	var chromeData struct {
		Result struct {
			ProcessInfo []*SystemInfoProcessInfo
		}
	}

	if resp == nil {
		return nil, &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return nil, &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return nil, err
	}

	return chromeData.Result.ProcessInfo, nil
}
1361250
func (c *Client) OperatorProvisioningInfo() (OperatorProvisioningInfo, error) {
	var result params.OperatorProvisioningInfo
	if err := c.facade.FacadeCall("OperatorProvisioningInfo", nil, &result); err != nil {
		return OperatorProvisioningInfo{}, err
	}
	info := OperatorProvisioningInfo{
		ImagePath:    result.ImagePath,
		Version:      result.Version,
		APIAddresses: result.APIAddresses,
		Tags:         result.Tags,
		CharmStorage: filesystemFromParams(result.CharmStorage),
	}
	return info, nil
}
1096872
func (st *State) SetStateServingInfo(info StateServingInfo) error {
	if info.StatePort == 0 || info.APIPort == 0 ||
		info.Cert == "" || info.PrivateKey == "" {
		return errors.Errorf("incomplete state serving info set in state")
	}
	if info.CAPrivateKey == "" {
		// No CA certificate key means we can't generate new controller
		// certificates when needed to add to the certificate SANs.
		// Older Juju deployments discard the key because no one realised
		// the certificate was flawed, so at best we can log a warning
		// until an upgrade process is written.
		logger.Warningf("state serving info has no CA certificate key")
	}
	ops := []txn.Op{{
		C:      controllersC,
		Id:     stateServingInfoKey,
		Update: bson.D{{"$set", info}},
	}}
	if err := st.db().RunTransaction(ops); err != nil {
		return errors.Annotatef(err, "cannot set state serving info")
	}
	return nil
}
794089
func (web *webAPIHandlers) StorageInfo(r *http.Request, args *WebGenericArgs, reply *StorageInfoRep) error {
	objectAPI := web.ObjectAPI()
	if objectAPI == nil {
		return toJSONError(errServerNotInitialized)
	}
	_, _, authErr := webRequestAuthenticate(r)
	if authErr != nil {
		return toJSONError(authErr)
	}
	reply.StorageInfo = objectAPI.StorageInfo(context.Background())
	reply.UIVersion = browser.UIVersion
	return nil
}
400595
func (d *DeployerAPI) ConnectionInfo() (result params.DeployerConnectionValues, err error) {
	apiAddrs, err := d.APIAddresses()
	if err != nil {
		return result, err
	}
	result = params.DeployerConnectionValues{
		APIAddresses: apiAddrs.Result,
	}
	return result, err
}
1002636
func ProvisionMachine(args manual.ProvisionMachineArgs) (machineId string, err error) {
	defer func() {
		if machineId != "" && err != nil {
			logger.Errorf("provisioning failed, removing machine %v: %v", machineId, err)
			if cleanupErr := args.Client.ForceDestroyMachines(machineId); cleanupErr != nil {
				logger.Errorf("error cleaning up machine: %s", cleanupErr)
			}
			machineId = ""
		}
	}()

	if err = InitAdministratorUser(&args); err != nil {
		return "", errors.Annotatef(err,
			"Cannot provision machine because no WinRM http/https standard listener is enabled for user %q, on host %q",
			args.User, args.Host)
	}

	machineParams, err := gatherMachineParams(args.Host, args.WinRM.Client)
	if err != nil {
		return "", err
	}

	machineId, err = manual.RecordMachineInState(args.Client, *machineParams)
	if err != nil {
		return "", err
	}

	provisioningScript, err := args.Client.ProvisioningScript(params.ProvisioningScriptParams{
		MachineId:              machineId,
		Nonce:                  machineParams.Nonce,
		DisablePackageCommands: true,
	})

	if err != nil {
		return "", err
	}

	// Finally, provision the machine agent.
	err = runProvisionScript(provisioningScript, args.WinRM.Client, args.Stdout, args.Stderr)
	if err != nil {
		return "", err
	}

	logger.Infof("Provisioned machine %v", machineId)
	return machineId, nil
}
1278930
func (api *API) Info() serverInfo {
	si := api.server.systemInfo
	// we don't report errors on failures to get this information
	physicalCores, logicalCores, _ := si.CPUCores()
	mhz, _ := si.CPUMHz()
	mem, _ := si.MemTotal()
	return serverInfo{
		ShardWidth:       ShardWidth,
		CPUPhysicalCores: physicalCores,
		CPULogicalCores:  logicalCores,
		CPUMHz:           mhz,
		CPUType:          si.CPUModel(),
		Memory:           mem,
	}
}
547693
func (c *Client) ProvisioningScript(args params.ProvisioningScriptParams) (params.ProvisioningScriptResult, error) {
	if err := c.checkCanWrite(); err != nil {
		return params.ProvisioningScriptResult{}, err
	}

	var result params.ProvisioningScriptResult
	icfg, err := InstanceConfig(c.api.state(), args.MachineId, args.Nonce, args.DataDir)
	if err != nil {
		return result, common.ServerError(errors.Annotate(
			err, "getting instance config",
		))
	}
	// Until DisablePackageCommands is retired, for backwards
	// compatibility, we must respect the client's request and
	// override any model settings the user may have specified.
	// If the client does specify this setting, it will only ever be
	// true. False indicates the client doesn't care and we should use
	// what's specified in the environment config.
	if args.DisablePackageCommands {
		icfg.EnableOSRefreshUpdate = false
		icfg.EnableOSUpgrade = false
	} else if cfg, err := c.api.stateAccessor.ModelConfig(); err != nil {
		return result, common.ServerError(errors.Annotate(
			err, "getting model config",
		))
	} else {
		icfg.EnableOSUpgrade = cfg.EnableOSUpgrade()
		icfg.EnableOSRefreshUpdate = cfg.EnableOSRefreshUpdate()
	}

	osSeries, err := series.GetOSFromSeries(icfg.Series)
	if err != nil {
		return result, common.ServerError(errors.Annotatef(err,
			"cannot decide which provisioning script to generate based on this series %q", icfg.Series))
	}

	getProvisioningScript := sshprovisioner.ProvisioningScript
	if osSeries == os.Windows {
		getProvisioningScript = winrmprovisioner.ProvisioningScript
	}

	result.Script, err = getProvisioningScript(icfg)
	if err != nil {
		return result, common.ServerError(errors.Annotate(
			err, "getting provisioning script",
		))
	}

	return result, nil
}
166271
func (c *Client) ProvisioningInfo(appName string) (*ProvisioningInfo, error) {
	appTag, err := applicationTag(appName)
	if err != nil {
		return nil, errors.Trace(err)
	}
	args := entities(appTag)

	var results params.KubernetesProvisioningInfoResults
	if err := c.facade.FacadeCall("ProvisioningInfo", args, &results); err != nil {
		return nil, err
	}
	if n := len(results.Results); n != 1 {
		return nil, errors.Errorf("expected 1 result, got %d", n)
	}
	if err := results.Results[0].Error; err != nil {
		return nil, maybeNotFound(err)
	}
	result := results.Results[0].Result
	info := &ProvisioningInfo{
		PodSpec:     result.PodSpec,
		Constraints: result.Constraints,
		Tags:        result.Tags,
	}
	if result.DeploymentInfo != nil {
		info.DeploymentInfo = DeploymentInfo{
			DeploymentType: result.DeploymentInfo.DeploymentType,
			ServiceType:    result.DeploymentInfo.ServiceType,
		}
	}

	for _, fs := range result.Filesystems {
		fsInfo, err := filesystemFromParams(fs)
		if err != nil {
			return nil, errors.Trace(err)
		}
		info.Filesystems = append(info.Filesystems, *fsInfo)
	}

	var devs []devices.KubernetesDeviceParams
	for _, device := range result.Devices {
		devs = append(devs, devices.KubernetesDeviceParams{
			Type:       devices.DeviceType(device.Type),
			Count:      device.Count,
			Attributes: device.Attributes,
		})
	}
	info.Devices = devs
	return info, nil
}
484354
func (vm *VM) Provision() error {
	b, err := json.Marshal(vm.Config)
	if err != nil {
		return err
	}

	client := &http.Client{}
	req, err := BuildRequest(vm.APIToken, "POST", apiBaseURL+apiDropletURL, bytes.NewReader(b))
	if err != nil {
		return err
	}
	rsp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer rsp.Body.Close()
	b, err = ioutil.ReadAll(rsp.Body)
	if err != nil {
		return err
	}
	if rsp.Status[0] != StatusOk {
		return fmt.Errorf("Error: %s: %s", rsp.Status, string(b))
	}

	// Fill out vm.Droplet with data on new droplet
	r := &DropletResponse{}
	err = json.Unmarshal(b, r)
	if err != nil {
		return err
	}
	vm.Droplet = r.Droplet
	return nil
}