// Returns a list of snapshots as specified by the service ID.  If no service
// ID is set, then returns a list of all snapshots.
16133
func (c *ServicedCli) snapshots(id string) []dao.SnapshotInfo {
	var (
		snapshots []dao.SnapshotInfo
		err       error
	)

	if id != "" {
		snapshots, err = c.driver.GetSnapshotsByServiceID(id)
	} else {
		snapshots, err = c.driver.GetSnapshots()
	}

	if err != nil || snapshots == nil || len(snapshots) == 0 {
		return []dao.SnapshotInfo{}
	}

	return snapshots
}
598666
func (s *SnapshotService) ListSnapshotPolicies(p *ListSnapshotPoliciesParams) (*ListSnapshotPoliciesResponse, error) {
	resp, err := s.cs.newRequest("listSnapshotPolicies", p.toURLValues())
	if err != nil {
		return nil, err
	}

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

	return &r, nil
}
757582
func (f *Facade) getServices(ctx datastore.Context) ([]service.Service, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.getServices"))
	plog.Debug("Started Facade.getServices")
	defer plog.Debug("Finished Facade.getServices")

	store := f.serviceStore
	results, err := store.GetServices(ctx)
	if err != nil {
		plog.WithError(err).Error("Unable to get a list of all services")
		return results, err
	}
	return results, nil
}
704706
func (s *SnapshotService) NewListSnapshotsParams() *ListSnapshotsParams {
	p := &ListSnapshotsParams{}
	p.p = make(map[string]interface{})
	return p
}
617620
func (n *ExecNode) Snapshots() (map[string][]byte, error) {
	if n.client == nil {
		return nil, errors.New("RPC not started")
	}
	var snapshots map[string][]byte
	return snapshots, n.client.Call(&snapshots, "simulation_snapshot")
}
60892
func (s *SnapshotService) NewListVMSnapshotParams() *ListVMSnapshotParams {
	p := &ListVMSnapshotParams{}
	p.p = make(map[string]interface{})
	return p
}
1368079
func (r Region) Services() map[string]Service {
	ss := map[string]Service{}
	for id, s := range r.p.Services {
		if _, ok := s.Endpoints[r.id]; ok {
			ss[id] = Service{
				id: id,
				p:  r.p,
			}
		}
	}

	return ss
}
905947
func (v *BtrfsVolume) Snapshots() ([]string, error) {
	v.Lock()
	defer v.Unlock()

	glog.V(2).Infof("listing snapshots of volume:%v and v.name:%s ", v.path, v.name)
	output, err := volume.RunBtrFSCmd(v.sudoer, "subvolume", "list", "-s", v.path)
	if err != nil {
		glog.Errorf("Could not list subvolumes of %s: %s", v.path, err)
		return nil, err
	}

	var files []os.FileInfo
	for _, line := range strings.Split(string(output), "\n") {
		glog.V(0).Infof("line: %s", line)
		if parts := strings.Split(line, "path"); len(parts) == 2 {
			rawLabel := strings.TrimSpace(parts[1])
			rawLabel = strings.TrimPrefix(rawLabel, "volumes/")
			if v.isSnapshot(rawLabel) {
				label := v.prettySnapshotLabel(rawLabel)
				file, err := os.Stat(filepath.Join(v.Driver().Root(), rawLabel))
				if err != nil {
					glog.Errorf("Could not stat snapshot %s: %s", label, err)
					return nil, err
				}
				files = append(files, file)
				glog.V(2).Infof("found snapshot:%s", label)
			}
		}
	}
	labels := volume.FileInfoSlice(files).Labels()
	return labels, nil
}
316303
func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter {
	if c.snapshotters != nil {
		return c.snapshotters[snapshotterName]
	}
	c.connMu.Lock()
	defer c.connMu.Unlock()
	return snproxy.NewSnapshotter(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName)
}
1074532
func (ss Snapshot) ListRequest() (ListCommand, error) {
	// Restricted cannot be applied here because it really has three states
	req := &ListSnapshots{
		ID:           ss.ID,
		Name:         ss.Name,
		VolumeID:     ss.VolumeID,
		SnapshotType: ss.SnapshotType,
		ZoneID:       ss.ZoneID,
		// TODO: tags
	}

	return req, nil
}
1361315
func (s *storeImpl) GetServices(ctx datastore.Context) ([]Service, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("ServiceStore.GetServices"))
	return s.query(ctx, "_exists_:ID")
}
908027
func (_class VIFClass) GetAllRecords(sessionID SessionRef) (_retval map[VIFRef]VIFRecord, _err error) {
	_method := "VIF.get_all_records"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVIFRefToVIFRecordMapToGo(_method + " -> ", _result.Value)
	return
}
994658
func (m *DB) Snapshotters() map[string]snapshots.Snapshotter {
	ss := make(map[string]snapshots.Snapshotter, len(m.ss))
	for n, sn := range m.ss {
		ss[n] = sn
	}
	return ss
}
82672
func (f *Facade) GetSnapshotByServiceIDAndTag(ctx datastore.Context, serviceID, tagName string) (*dfs.SnapshotInfo, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.GetSnapshotByServiceIDAndTag"))
	logger := plog.WithFields(logrus.Fields{
		"serviceid": serviceID,
		"tagname":   tagName,
	})

	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)
	info, err := f.dfs.TagInfo(tenantID, tagName)
	if err != nil {
		logger.WithError(err).Debug("Could not get info for snapshot tag")
		return nil, err
	}
	return info, nil
}
139153
func (c *ServicedCli) cmdServiceSnapshot(ctx *cli.Context) {
	nArgs := len(ctx.Args())
	if nArgs < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "snapshot")
		c.exit(1)
		return
	}

	description := ""
	if nArgs <= 3 {
		description = ctx.String("description")
	}

	svc, _, err := c.searchForService(ctx.Args().First(), ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	//get the tags (if any)
	tag := ctx.String("tag")

	cfg := api.SnapshotConfig{
		ServiceID: svc.ID,
		Message:   description,
		Tag:       tag,
	}
	if snapshot, err := c.driver.AddSnapshot(cfg); err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
	} else if snapshot == "" {
		fmt.Fprintln(os.Stderr, "received nil snapshot")
		c.exit(1)
	} else {
		fmt.Println(snapshot)
	}
	return
}
480264
func (sn *SimNode) Snapshots() (map[string][]byte, error) {
	sn.lock.RLock()
	services := make(map[string]node.Service, len(sn.running))
	for name, service := range sn.running {
		services[name] = service
	}
	sn.lock.RUnlock()
	if len(services) == 0 {
		return nil, errors.New("no running services")
	}
	snapshots := make(map[string][]byte)
	for name, service := range services {
		if s, ok := service.(interface {
			Snapshot() ([]byte, error)
		}); ok {
			snap, err := s.Snapshot()
			if err != nil {
				return nil, err
			}
			snapshots[name] = snap
		}
	}
	return snapshots, nil
}
691103
func (_class BlobClass) GetAllRecords(sessionID SessionRef) (_retval map[BlobRef]BlobRecord, _err error) {
	_method := "blob.get_all_records"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg)
	if _err != nil {
		return
	}
	_retval, _err = convertBlobRefToBlobRecordMapToGo(_method + " -> ", _result.Value)
	return
}