// StartMachineFromSnapshot starts the machine from the specified snapshot.
// Machine must be in 'stopped' state.
// See API docs: http://apidocs.joyent.com/cloudapi/#StartMachineFromSnapshot
191375
func (c *Client) StartMachineFromSnapshot(machineID, snapshotName string) error {
	req := request{
		method:         client.POST,
		url:            makeURL(apiMachines, machineID, apiSnapshots, snapshotName),
		expectedStatus: http.StatusAccepted,
	}
	if _, err := c.sendRequest(req); err != nil {
		return errors.Newf(err, "failed to start machine with id %s from snapshot %s", machineID, snapshotName)
	}
	return nil
}
839736
func (_m *API) TagSnapshot(_a0 string, _a1 string) error {
	ret := _m.Called(_a0, _a1)

	var r0 error
	if rf, ok := ret.Get(0).(func(string, string) error); ok {
		r0 = rf(_a0, _a1)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
438291
func (st *State) start(controllerTag names.ControllerTag, hub *pubsub.SimpleHub) (err error) {
	defer func() {
		if err == nil {
			return
		}
		if err2 := st.Close(); err2 != nil {
			logger.Errorf("closing State for %s: %v", st.modelTag, err2)
		}
	}()

	st.controllerTag = controllerTag

	// Run the "connectionStatus" Mongo command to obtain the authenticated
	// user name, if any. This is used below for the lease store ID.
	// See: https://docs.mongodb.com/manual/reference/command/connectionStatus/
	//
	// TODO(axw) when we move the workers to a higher level state.Manager
	// type, we should pass in a tag that identifies the agent running the
	// worker. That can then be used to identify the lease manager.
	var connectionStatus struct {
		AuthInfo struct {
			AuthenticatedUsers []struct {
				User string `bson:"user"`
			} `bson:"authenticatedUsers"`
		} `bson:"authInfo"`
	}
	if err := st.session.DB(jujuDB).Run(bson.D{{"connectionStatus", 1}}, &connectionStatus); err != nil {
		return errors.Annotate(err, "obtaining connection status")
	}

	if len(connectionStatus.AuthInfo.AuthenticatedUsers) == 1 {
		st.leaseStoreId = connectionStatus.AuthInfo.AuthenticatedUsers[0].User
	} else {
		// If we're running state anonymously, we can still use the lease
		// manager; but we need to make sure we use a unique store ID, and
		// will thus not be very performant.
		logger.Infof("running state anonymously; using unique store id")
		uuid, err := utils.NewUUID()
		if err != nil {
			return errors.Trace(err)
		}
		st.leaseStoreId = fmt.Sprintf("anon-%s", uuid.String())
	}
	// now we've set up leaseStoreId, we can use workersFactory

	logger.Infof("starting standard state workers")
	workers, err := newWorkers(st, hub)
	if err != nil {
		return errors.Trace(err)
	}
	st.workers = workers

	logger.Infof("creating cloud image metadata storage")
	st.CloudImageMetadataStorage = cloudimagemetadata.NewStorage(
		cloudimagemetadataC,
		&environMongo{st},
	)

	logger.Infof("started state for %s successfully", st.modelTag)
	return nil
}
824417
func (tr *Repo) InitSnapshot() error {
	if tr.Root == nil {
		return ErrNotLoaded{Role: data.CanonicalRootRole}
	}
	root, err := tr.Root.ToSigned()
	if err != nil {
		return err
	}

	if _, ok := tr.Targets[data.CanonicalTargetsRole]; !ok {
		return ErrNotLoaded{Role: data.CanonicalTargetsRole}
	}
	targets, err := tr.Targets[data.CanonicalTargetsRole].ToSigned()
	if err != nil {
		return err
	}
	snapshot, err := data.NewSnapshot(root, targets)
	if err != nil {
		return err
	}
	tr.Snapshot = snapshot
	return nil
}
822375
func (s *CreateClusterSnapshotOutput) SetSnapshot(v *Snapshot) *CreateClusterSnapshotOutput {
	s.Snapshot = v
	return s
}
1322323
func (client *Client) CreateSnapshot(args *CreateSnapshotArgs) (snapshotId string, err error) {

	response := CreateSnapshotResponse{}

	err = client.Invoke("CreateSnapshot", args, &response)
	if err == nil {
		snapshotId = response.SnapshotId
	}
	return snapshotId, err
}
232410
func (d *domainClient) LoadSnapshot(ctx context.Context, args *LoadSnapshotArgs) (reply *LoadSnapshotReply, err error) {
	reply = new(LoadSnapshotReply)
	if args != nil {
		err = rpcc.Invoke(ctx, "LayerTree.loadSnapshot", args, reply, d.conn)
	} else {
		err = rpcc.Invoke(ctx, "LayerTree.loadSnapshot", nil, reply, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: "LayerTree", Op: "LoadSnapshot", Err: err}
	}
	return
}
1283957
func (s *SnapshotService) CreateSnapshot(p *CreateSnapshotParams) (*CreateSnapshotResponse, error) {
	resp, err := s.cs.newRequest("createSnapshot", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreateSnapshotResponse
	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
}
612522
func (f *fragment) Snapshot() error {
	f.mu.Lock()
	defer f.mu.Unlock()
	return f.snapshot()
}
1061995
func (c *CloudAPI) DeleteMachine(machineID string) error {
	if err := c.ProcessFunctionHook(c, machineID); err != nil {
		return err
	}

	for i, machine := range c.machines {
		if machine.Id == machineID {
			if machine.State == "stopped" {
				c.machines = append(c.machines[:i], c.machines[i+1:]...)
				return nil
			}

			return fmt.Errorf("Cannot Delete machine %s, machine is not stopped.", machineID)
		}
	}

	return fmt.Errorf("Machine %s not found", machineID)
}
671922
func (env *sessionEnviron) finishMachineConfig(args environs.StartInstanceParams, img *OvaFileMetadata) error {
	envTools, err := args.Tools.Match(tools.Filter{Arch: img.Arch})
	if err != nil {
		return err
	}
	if err := args.InstanceConfig.SetTools(envTools); err != nil {
		return errors.Trace(err)
	}
	return FinishInstanceConfig(args.InstanceConfig, env.Config())
}
1206772
func (vm *VM) Start() error {
	_, err := runner.RunCombinedError("startvm", vm.Name)
	if err != nil {
		// If the user has paused the VM it reads as halted but the Start
		// command will fail. Try to resume it as a backup.
		_, rerr := runner.RunCombinedError("controlvm", vm.Name, "resume")
		if rerr != nil {
			// If neither succeeds, return both errors.
			return lvm.WrapErrors(lvm.ErrStartingVM, err, rerr)
		}
	}
	return nil
}
933449
func (s *Server) clustersFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]proto.Message, error) {
	if cfgSnap == nil {
		return nil, errors.New("nil config given")
	}
	// Include the "app" cluster for the public listener
	clusters := make([]proto.Message, len(cfgSnap.Proxy.Upstreams)+1)

	var err error
	clusters[0], err = s.makeAppCluster(cfgSnap)
	if err != nil {
		return nil, err
	}

	for idx, upstream := range cfgSnap.Proxy.Upstreams {
		clusters[idx+1], err = s.makeUpstreamCluster(upstream, cfgSnap)
		if err != nil {
			return nil, err
		}
	}

	return clusters, nil
}
1352142
func (c *CloudAPI) CountMachines() (int, error) {
	if err := c.ProcessFunctionHook(c); err != nil {
		return 0, err
	}

	return len(c.machines), nil
}
743913
func (c *Client) GetSnapshot(id string, name string) (Snapshot, error) {
	initiator, err := c.api.GetSnapshot(id, name)
	if err != nil {
		return nil, err
	}
	return initiator.Content, nil
}
767656
func (m *CountMeter) Snapshot() metrics.Meter {
	m.mtx.RLock()
	defer m.mtx.RUnlock()
	return &MeterSnapshot{
		m.overall,
		m.rate1(),
		m.rate5(),
		m.rate15(),
		m.rateMean(),
	}
}
410748
func endpointsFromSnapshot(cfgSnap *proxycfg.ConfigSnapshot, token string) ([]proto.Message, error) {
	if cfgSnap == nil {
		return nil, errors.New("nil config given")
	}
	resources := make([]proto.Message, 0, len(cfgSnap.UpstreamEndpoints))
	for id, endpoints := range cfgSnap.UpstreamEndpoints {
		la := makeLoadAssignment(id, endpoints)
		resources = append(resources, la)
	}
	return resources, nil
}