// CreateMachine tcp iaas
164483
func (p *Provider) CreateMachine() (*iaas.Machine, error) {
	return &iaas.Machine{
		IP:   p.Host,
		Port: p.Port,
		Kind: "TCP",
	}, nil
}
803941
func (s *MacroService) CreateMacro(ctx context.Context, m *platform.Macro) error {
	if err := m.Valid(); err != nil {
		return kerrors.InvalidDataf(err.Error())
	}

	url, err := newURL(s.Addr, macroPath)
	if err != nil {
		return err
	}

	octets, err := json.Marshal(m)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}

	if err := CheckError(resp, true); err != nil {
		return err
	}

	return json.NewDecoder(resp.Body).Decode(m)
}
1318699
func createMachineFilesystemAttachmentsOps(hostId string, attachments []filesystemAttachmentTemplate) []txn.Op {
	ops := make([]txn.Op, len(attachments))
	for i, attachment := range attachments {
		paramsCopy := attachment.params
		ops[i] = txn.Op{
			C:      filesystemAttachmentsC,
			Id:     filesystemAttachmentId(hostId, attachment.tag.Id()),
			Assert: txn.DocMissing,
			Insert: &filesystemAttachmentDoc{
				Filesystem: attachment.tag.Id(),
				Host:       hostId,
				Params:     &paramsCopy,
			},
		}
		if attachment.existing {
			ops = append(ops, txn.Op{
				C:      filesystemsC,
				Id:     attachment.tag.Id(),
				Assert: txn.DocExists,
				Update: bson.D{{"$inc", bson.D{{"attachmentcount", 1}}}},
			})
		}
	}
	return ops
}
682115
func (c *Conn) TerminateMachine(name string) error {
	return c.object.Call(dbusInterface+".TerminateMachine", 0, name).Err
}
796736
func (c *Client) CreateMachineSnapshot(machineID string, opts SnapshotOpts) (*Snapshot, error) {
	var resp Snapshot
	req := request{
		method:         client.POST,
		url:            makeURL(apiMachines, machineID, apiSnapshots),
		reqValue:       opts,
		resp:           &resp,
		expectedStatus: http.StatusCreated,
	}
	if _, err := c.sendRequest(req); err != nil {
		return nil, errors.Newf(err, "failed to create snapshot %s from machine with id %s", opts.Name, machineID)
	}
	return &resp, nil
}
1128728
func (ac *APIController) AciGwCreate(aci *contivModel.AciGw) error {
	log.Infof("Received AciGwCreate: %+v", aci)
	// Fail the create if app profiles exist
	profCount := contivModel.GetAppProfileCount()
	if profCount != 0 {
		log.Warnf("AciGwCreate: %d existing App-Profiles found.",
			profCount)
	}

	return nil
}
1114604
func (s *Service) CreateMacro(ctx context.Context, m *platform.Macro) error {
	op := OpPrefix + platform.OpCreateMacro
	m.ID = s.IDGenerator.ID()
	err := s.ReplaceMacro(ctx, m)
	if err != nil {
		return &platform.Error{
			Op:  op,
			Err: err,
		}
	}
	return nil
}
145137
func (s *Service) AddMachines(componentsmachineproviderrpcmessagescatalogmachinebatchadditionrequest *ComponentsMachineProviderRpcMessagesCatalogMachineBatchAdditionRequest) *AddMachinesCall {
	c := &AddMachinesCall{s: s, urlParams_: make(gensupport.URLParams)}
	c.componentsmachineproviderrpcmessagescatalogmachinebatchadditionrequest = componentsmachineproviderrpcmessagescatalogmachinebatchadditionrequest
	return c
}
396713
func (*Service) CreateMachine(c context.Context, req *crimson.CreateMachineRequest) (*crimson.Machine, error) {
	if err := createMachine(c, req.Machine); err != nil {
		return nil, err
	}
	return req.Machine, nil
}
46735
func (c *Client) StopMachine(machineID string) error {
	req := request{
		method:         client.POST,
		url:            fmt.Sprintf("%s/%s?action=%s", apiMachines, machineID, actionStop),
		expectedStatus: http.StatusAccepted,
	}
	if _, err := c.sendRequest(req); err != nil {
		return errors.Newf(err, "failed to stop machine with id: %s", machineID)
	}
	return nil
}
893458
func (fw *Firewaller) startMachine(tag names.MachineTag) error {
	machined := &machineData{
		fw:           fw,
		tag:          tag,
		unitds:       make(map[names.UnitTag]*unitData),
		ingressRules: make([]network.IngressRule, 0),
		definedPorts: make(map[names.UnitTag]portRanges),
	}
	m, err := machined.machine()
	if params.IsCodeNotFound(err) {
		logger.Debugf("not watching %q", tag)
		return nil
	} else if err != nil {
		return errors.Annotate(err, "cannot watch machine units")
	}
	manual, err := m.IsManual()
	if err != nil {
		return errors.Trace(err)
	}
	if manual {
		// Don't track manual machines, we can't change their ports.
		logger.Debugf("not watching manual %q", tag)
		return nil
	}
	unitw, err := m.WatchUnits()
	if err != nil {
		return errors.Trace(err)
	}
	// XXX(fwereade): this is the best of a bunch of bad options. We've started
	// the watch, so we're responsible for it; but we (probably?) need to do this
	// little dance below to update the machined data on the fw loop goroutine,
	// whence it's usually accessed, before we start the machined watchLoop
	// below. That catacomb *should* be the only one responsible -- and it *is*
	// responsible -- but having it in the main fw catacomb as well does no harm,
	// and greatly simplifies the code below (which would otherwise have to
	// manage unitw lifetime and errors manually).
	if err := fw.catacomb.Add(unitw); err != nil {
		return errors.Trace(err)
	}
	select {
	case <-fw.catacomb.Dying():
		return fw.catacomb.ErrDying()
	case change, ok := <-unitw.Changes():
		if !ok {
			return errors.New("machine units watcher closed")
		}
		fw.machineds[tag] = machined
		err = fw.unitsChanged(&unitsChange{machined, change})
		if err != nil {
			delete(fw.machineds, tag)
			return errors.Annotatef(err, "cannot respond to units changes for %q", tag)
		}
	}

	err = catacomb.Invoke(catacomb.Plan{
		Site: &machined.catacomb,
		Work: func() error {
			return machined.watchLoop(unitw)
		},
	})
	if err != nil {
		delete(fw.machineds, tag)
		return errors.Trace(err)
	}

	// register the machined with the firewaller's catacomb.
	err = fw.catacomb.Add(machined)
	if err == nil {
		logger.Debugf("started watching %q", tag)
	}
	return err
}
583776
func (m *networkMechanismManager) CreateNetwork() error {
	network := new(NetworkManagerContext)

	create := func(fn func() error) error {
		return m.BaseMechanismManager.Create(
			NetworkModel, network, fn,
		)
	}

	alter := func(port NetworkPort) error {
		networkContext, err := m.updateNetworkContext(port)
		if err != nil {
			return err
		}

		// Broadcast request to all activated network mechanisms
		err = m.do(func(nlmech NetworkMechanism) error {
			return nlmech.CreateNetworkPreCommit(networkContext)
		})

		if err != nil {
			log.ErrorLog("network/CREATE_NETWORK",
				"Failed to create network layer configuration: ", port.Port)
		}

		return err
	}

	m.lock.RLock()
	defer m.lock.RUnlock()

	return create(func() error {
		// If driver equals to empty string, that mechanism was not
		// previously activated, so there is nothing to configure
		if network.Driver == "" {
			return nil
		}

		// Restore state of the persited switch
		err := m.SetDriver(network.Driver)
		if err != nil {
			return err
		}

		for _, port := range network.Ports {
			if err := alter(port); err != nil {
				log.ErrorLog("network/CREATE_NETWORK",
					"Network create pre-commit failed: ", err)
				return err
			}
		}

		err = m.do(func(nlmech NetworkMechanism) error {
			return nlmech.CreateNetworkPostCommit()
		})

		if err != nil {
			log.ErrorLog("network/CREATE_NETWORK",
				"Network create post-commit failed: ", err)
		}

		return err
	})
}
1280461
func (st *State) AllMachines() ([]*Machine, error) {
	machinesCollection, closer := st.db().GetCollection(machinesC)
	defer closer()
	return st.allMachines(machinesCollection)
}
1051174
func (do *Provider) DeleteMachine() (err error) {
	err = do.Host.Driver.Remove()
	defer do.Client.Close()
	if err != nil {
		return
	}
	return
}
764643
func (s *Service) AddMachine(componentsmachineproviderrpcmessagescatalogmachineadditionrequest *ComponentsMachineProviderRpcMessagesCatalogMachineAdditionRequest) *AddMachineCall {
	c := &AddMachineCall{s: s, urlParams_: make(gensupport.URLParams)}
	c.componentsmachineproviderrpcmessagescatalogmachineadditionrequest = componentsmachineproviderrpcmessagescatalogmachineadditionrequest
	return c
}
164968
func (a *AAgent) ManageMachines(ctx context.Context, wg *sync.WaitGroup) error {
	wg.Add(1)
	go a.watchSource(ctx, wg)

	return nil
}
1119658
func (u *Unit) AssignedMachine() (names.MachineTag, error) {
	var results params.StringResults
	args := params.Entities{
		Entities: []params.Entity{{Tag: u.tag.String()}},
	}
	emptyTag := names.NewMachineTag("")
	err := u.st.facade.FacadeCall("GetAssignedMachine", args, &results)
	if err != nil {
		return emptyTag, err
	}
	if len(results.Results) != 1 {
		return emptyTag, errors.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return emptyTag, result.Error
	}
	return names.ParseMachineTag(result.Result)
}