// startWithSnapshots starts the node with the given ID using the give
// snapshots
519849
func (net *Network) startWithSnapshots(id enode.ID, snapshots map[string][]byte) error {
	net.lock.Lock()
	defer net.lock.Unlock()

	node := net.getNode(id)
	if node == nil {
		return fmt.Errorf("node %v does not exist", id)
	}
	if node.Up() {
		return fmt.Errorf("node %v already up", id)
	}
	log.Trace("Starting node", "id", id, "adapter", net.nodeAdapter.Name())
	if err := node.Start(snapshots); err != nil {
		log.Warn("Node startup failed", "id", id, "err", err)
		return err
	}
	node.SetUp(true)
	log.Info("Started node", "id", id)
	ev := NewEvent(node)
	net.events.Send(ev)

	// subscribe to peer events
	client, err := node.Client()
	if err != nil {
		return fmt.Errorf("error getting rpc client  for node %v: %s", id, err)
	}
	events := make(chan *p2p.PeerEvent)
	sub, err := client.Subscribe(context.Background(), "admin", events, "peerEvents")
	if err != nil {
		return fmt.Errorf("error getting peer events for node %v: %s", id, err)
	}
	go net.watchPeerEvents(id, events, sub)
	return nil
}
1306368
func (f *Facade) ListSnapshots(ctx datastore.Context, serviceID string) ([]string, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.ListSnapshots"))
	logger := plog.WithField("serviceid", serviceID)
	tenantID, err := f.GetTenantID(ctx, serviceID)
	if err != nil {
		logger.WithError(err).Debug("Could not find tenant for service")
		return nil, err
	}
	logger = logger.WithField("tenantid", tenantID)
	snapshots, err := f.dfs.List(tenantID)
	if err != nil {
		logger.WithError(err).Debug("Could not list snapshots for tenant")
		return nil, err
	}
	return snapshots, nil
}
855831
func (f *Facade) TagSnapshot(snapshotID string, tagName string) error {
	logger := plog.WithFields(logrus.Fields{
		"snapshotid": snapshotID,
		"tagname":    tagName,
	})
	if err := f.dfs.Tag(snapshotID, tagName); err != nil {
		logger.WithError(err).Debug("Could not add tag to snapshot")
		return err
	}
	return nil
}
1081783
func (c *Host) CreateSnapshot(volumeID string) (*volume.Info, error) {
	var res volume.Info
	err := c.c.Put(fmt.Sprintf("/storage/volumes/%s/snapshot", volumeID), nil, &res)
	return &res, err
}
759535
func (c *Cloud) FindSnapshot(tags map[string]string) ([]string, []string, error) {
	request := &ec2.DescribeSnapshotsInput{}
	for k, v := range tags {
		filter := &ec2.Filter{}
		filter.SetName(k)
		filter.SetValues([]*string{&v})

		request.Filters = append(request.Filters, filter)
	}

	result, err := c.ec2.DescribeSnapshots(request)
	if err != nil {
		return nil, nil, err
	}
	var snapshotIDs, statuses []string
	for _, snapshot := range result {
		id := *snapshot.SnapshotId
		status := *snapshot.State
		glog.Infof("found %s, status %s", id, status)
		snapshotIDs = append(snapshotIDs, id)
		statuses = append(statuses, status)
	}
	return snapshotIDs, statuses, nil
}
941096
func (db *DB) newSnapshot() *Snapshot {
	snap := &Snapshot{
		db:   db,
		elem: db.acquireSnapshot(),
	}
	atomic.AddInt32(&db.aliveSnaps, 1)
	runtime.SetFinalizer(snap, (*Snapshot).Release)
	return snap
}
511306
func (n *Node) ReportSnapshot(id uint64, status raft.SnapshotStatus) {
	n.raftNode.ReportSnapshot(id, status)
}
1287706
func (s *Store) Snapshot() (raft.FSMSnapshot, error) {
	s.mu.Lock()
	defer s.mu.Unlock()

	buf, err := json.Marshal(s.data)
	if err != nil {
		return nil, err
	}
	return &raftSnapshot{data: buf}, nil
}
527594
func (c *Client) DeleteSnapshot(id string, name string) error {
	return c.api.DeleteSnapshots(id, name)
}
564446
func (s *DeleteSnapshotInput) SetSnapshotId(v string) *DeleteSnapshotInput {
	s.SnapshotId = &v
	return s
}
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
}
114421
func (image *Image) CreateSnapshot(snapname string) (*Snapshot, error) {
	if image.image == nil {
		return nil, RbdErrorImageNotOpen
	}

	var c_snapname *C.char = C.CString(snapname)
	defer C.free(unsafe.Pointer(c_snapname))

	ret := C.rbd_snap_create(image.image, c_snapname)
	if ret < 0 {
		return nil, RBDError(int(ret))
	}

	return &Snapshot{
		image: image,
		name:  snapname,
	}, nil
}
1336093
func (os *OpenStack) DeleteSnapshot(snapshotID string) error {
	snapshots, err := os.snapshotService()
	if err != nil || snapshots == nil {
		glog.Errorf("Unable to initialize cinder client for region: %s", os.region)
		return err
	}

	err = snapshots.deleteSnapshot(snapshotID)
	if err != nil {
		glog.Errorf("Cannot delete snapshot %s: %v", snapshotID, err)
	}
	return nil
}
509168
func (sn *SimNode) Start(snapshots map[string][]byte) error {
	newService := func(name string) func(ctx *node.ServiceContext) (node.Service, error) {
		return func(nodeCtx *node.ServiceContext) (node.Service, error) {
			ctx := &ServiceContext{
				RPCDialer:   sn.adapter,
				NodeContext: nodeCtx,
				Config:      sn.config,
			}
			if snapshots != nil {
				ctx.Snapshot = snapshots[name]
			}
			serviceFunc := sn.adapter.services[name]
			service, err := serviceFunc(ctx)
			if err != nil {
				return nil, err
			}
			sn.running[name] = service
			return service, nil
		}
	}

	// ensure we only register the services once in the case of the node
	// being stopped and then started again
	var regErr error
	sn.registerOnce.Do(func() {
		for _, name := range sn.config.Services {
			if err := sn.node.Register(newService(name)); err != nil {
				regErr = err
				break
			}
		}
	})
	if regErr != nil {
		return regErr
	}

	if err := sn.node.Start(); err != nil {
		return err
	}

	// create an in-process RPC client
	handler, err := sn.node.RPCHandler()
	if err != nil {
		return err
	}

	sn.lock.Lock()
	sn.client = rpc.DialInProc(handler)
	sn.lock.Unlock()

	return nil
}
484178
func (c *Client) StartNode(nodeID string) error {
	return c.Post(fmt.Sprintf("/nodes/%s/start", nodeID), nil, nil)
}
96557
func WithPullSnapshotter(snapshotterName string) RemoteOpt {
	return func(_ *Client, c *RemoteContext) error {
		c.Snapshotter = snapshotterName
		return nil
	}
}
66469
func (s *Snapshot) SetNodeSnapshots(v []*NodeSnapshot) *Snapshot {
	s.NodeSnapshots = v
	return s
}