// Export the volume with a given name on the cluster
965490
func (c *Client) Export(ctx context.Context, name string) (int, error) {

	ok, id, err := c.IsExported(ctx, name)
	if err != nil {
		return 0, err
	}
	if ok {
		return id, nil
	}

	paths := []string{c.API.VolumePath(name)}

	return api.ExportCreate(
		ctx, c.API,
		&api.Export{Paths: &paths})
}
307677
func (r *Root) Create(name string, opts map[string]string) (volume.Volume, error) {
	if err := r.validateName(name); err != nil {
		return nil, err
	}

	r.m.Lock()
	defer r.m.Unlock()

	v, exists := r.volumes[name]
	if exists {
		return v, nil
	}

	path := r.DataPath(name)
	if err := idtools.MkdirAllAndChown(path, 0755, r.rootIdentity); err != nil {
		return nil, errors.Wrapf(errdefs.System(err), "error while creating volume path '%s'", path)
	}

	var err error
	defer func() {
		if err != nil {
			os.RemoveAll(filepath.Dir(path))
		}
	}()

	v = &localVolume{
		driverName: r.Name(),
		name:       name,
		path:       path,
	}

	if len(opts) != 0 {
		if err = setOpts(v, opts); err != nil {
			return nil, err
		}
		var b []byte
		b, err = json.Marshal(v.opts)
		if err != nil {
			return nil, err
		}
		if err = ioutil.WriteFile(filepath.Join(filepath.Dir(path), "opts.json"), b, 600); err != nil {
			return nil, errdefs.System(errors.Wrap(err, "error while persisting volume options"))
		}
	}

	r.volumes[name] = v
	return v, nil
}
244155
func (c *Cluster) Export() ([]byte, error) {
	var config bytes.Buffer

	namespaces, err := c.getAllowedAndExistingNamespaces()
	if err != nil {
		return nil, errors.Wrap(err, "getting namespaces")
	}

	encoder := yaml.NewEncoder(&config)
	defer encoder.Close()

	for _, ns := range namespaces {
		// kind & apiVersion must be set, since TypeMeta is not populated
		ns.Kind = "Namespace"
		ns.APIVersion = "v1"
		err := encoder.Encode(yamlThroughJSON{ns})
		if err != nil {
			return nil, errors.Wrap(err, "marshalling namespace to YAML")
		}

		for _, resourceKind := range resourceKinds {
			workloads, err := resourceKind.getWorkloads(c, ns.Name)
			if err != nil {
				switch {
				case apierrors.IsNotFound(err):
					// Kind not supported by API server, skip
					continue
				case apierrors.IsForbidden(err):
					// K8s can return forbidden instead of not found for non super admins
					c.logger.Log("warning", "not allowed to list resources", "err", err)
					continue
				default:
					return nil, err
				}
			}

			for _, pc := range workloads {
				if !isAddon(pc) {
					if err := encoder.Encode(yamlThroughJSON{pc.k8sObject}); err != nil {
						return nil, err
					}
				}
			}
		}
	}
	return config.Bytes(), nil
}
838262
func (a *API) ExportableName(name string) string {
	if name == "" {
		return name
	}

	return strings.ToUpper(name[0:1]) + name[1:]
}
312460
func (mi *maas1Instance) volumes(
	mTag names.MachineTag, requestedVolumes []names.VolumeTag,
) (
	[]storage.Volume, []storage.VolumeAttachment, error,
) {
	var volumes []storage.Volume
	var attachments []storage.VolumeAttachment

	deviceInfo, ok := mi.maasObject.GetMap()["physicalblockdevice_set"]
	// Older MAAS servers don't support storage.
	if !ok || deviceInfo.IsNil() {
		return volumes, attachments, nil
	}

	labelsMap, ok := mi.maasObject.GetMap()["constraint_map"]
	if !ok || labelsMap.IsNil() {
		return nil, nil, errors.NotFoundf("constraint map field")
	}

	devices, err := deviceInfo.GetArray()
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	// deviceLabel is the volume label passed
	// into the acquire node call as part
	// of the storage constraints parameter.
	deviceLabels, err := labelsMap.GetMap()
	if err != nil {
		return nil, nil, errors.Annotate(err, "invalid constraint map value")
	}

	// Set up a collection of volumes tags which
	// we specifically asked for when the node was acquired.
	validVolumes := set.NewStrings()
	for _, v := range requestedVolumes {
		validVolumes.Add(v.Id())
	}

	for _, d := range devices {
		deviceAttrs, err := d.GetMap()
		if err != nil {
			return nil, nil, errors.Trace(err)
		}
		// id in devices list is numeric
		id, err := deviceAttrs["id"].GetFloat64()
		if err != nil {
			return nil, nil, errors.Annotate(err, "invalid device id")
		}
		// id in constraint_map field is a string
		idKey := strconv.Itoa(int(id))

		// Device Label.
		deviceLabelValue, ok := deviceLabels[idKey]
		if !ok {
			logger.Debugf("acquire maas node: missing volume label for id %q", idKey)
			continue
		}
		deviceLabel, err := deviceLabelValue.GetString()
		if err != nil {
			return nil, nil, errors.Annotate(err, "invalid device label")
		}
		// We don't explicitly allow the root volume to be specified yet.
		if deviceLabel == rootDiskLabel {
			continue
		}
		// We only care about the volumes we specifically asked for.
		if !validVolumes.Contains(deviceLabel) {
			continue
		}

		// HardwareId and DeviceName.
		// First try for id_path.
		idPathPrefix := "/dev/disk/by-id/"
		hardwareId, err := deviceAttrs["id_path"].GetString()
		var deviceName string
		if err == nil {
			if !strings.HasPrefix(hardwareId, idPathPrefix) {
				return nil, nil, errors.Errorf("invalid device id %q", hardwareId)
			}
			hardwareId = hardwareId[len(idPathPrefix):]
		} else {
			// On VMAAS, id_path not available so try for path instead.
			deviceName, err = deviceAttrs["name"].GetString()
			if err != nil {
				return nil, nil, errors.Annotate(err, "invalid device name")
			}
		}

		// Size.
		sizeinBytes, err := deviceAttrs["size"].GetFloat64()
		if err != nil {
			return nil, nil, errors.Annotate(err, "invalid device size")
		}

		volumeTag := names.NewVolumeTag(deviceLabel)
		vol := storage.Volume{
			volumeTag,
			storage.VolumeInfo{
				VolumeId:   volumeTag.String(),
				HardwareId: hardwareId,
				Size:       uint64(sizeinBytes / humanize.MiByte),
				Persistent: false,
			},
		}
		volumes = append(volumes, vol)

		attachment := storage.VolumeAttachment{
			volumeTag,
			mTag,
			storage.VolumeAttachmentInfo{
				DeviceName: deviceName,
				ReadOnly:   false,
			},
		}
		attachments = append(attachments, attachment)
	}
	return volumes, attachments, nil
}
862624
func (c *Client) UnexportVolume(
	ctx context.Context, name string) error {

	return c.Unexport(ctx, name)
}
205643
func (id Identity) Export() (ret keybase1.PGPIdentity) {
	ret.Username = id.Username
	ret.Email = id.Email
	ret.Comment = id.Comment
	return
}
302781
func (f *filesystem) Volume() (names.VolumeTag, error) {
	if f.doc.VolumeId == "" {
		return names.VolumeTag{}, ErrNoBackingVolume
	}
	return names.NewVolumeTag(f.doc.VolumeId), nil
}
530348
func mountVolume(pod *corev1.Pod, container *corev1.Container, objName, mountPath, volumeSuffix string, fsType policy.FSType) {
	volumeName := apihelpers.GetName(objName, volumeSuffix, kvalidation.DNS1123LabelMaxLength)

	// coerce from RFC1123 subdomain to RFC1123 label.
	volumeName = strings.Replace(volumeName, ".", "-", -1)

	volumeExists := false
	for _, v := range pod.Spec.Volumes {
		if v.Name == volumeName {
			volumeExists = true
			break
		}
	}
	mode := int32(0600)
	if !volumeExists {
		volume := makeVolume(volumeName, objName, mode, fsType)
		pod.Spec.Volumes = append(pod.Spec.Volumes, volume)
	}

	volumeMount := corev1.VolumeMount{
		Name:      volumeName,
		MountPath: mountPath,
		ReadOnly:  true,
	}
	container.VolumeMounts = append(container.VolumeMounts, volumeMount)
}
337516
func (res *Resource) Export(container Container, context *qor.Context, callbacks ...func(Progress) error) error {
	var (
		total   uint
		results = res.NewSlice()
		err     = context.GetDB().Find(results).Count(&total).Error
	)

	if err == nil {
		reflectValue := reflect.Indirect(reflect.ValueOf(results))

		writer, err := container.NewWriter(res, context)

		if err == nil {
			writer.WriteHeader()

			for i := 0; i < reflectValue.Len(); i++ {
				var result = reflectValue.Index(i).Interface()
				var metaValues *resource.MetaValues
				if metaValues, err = writer.WriteRow(result); err != nil {
					return err
				}

				var progress = Progress{
					Current: uint(i + 1),
					Total:   total,
					Value:   result,
				}

				for _, metaValue := range metaValues.Values {
					progress.Cells = append(progress.Cells, Cell{
						Header: metaValue.Name,
						Value:  metaValue.Value,
					})
				}

				for _, callback := range callbacks {
					if err := callback(progress); err != nil {
						return err
					}
				}
			}
			err = writer.Flush()
		}

		return err
	}

	return err
}
582767
func (ckf ComputedKeyFamily) Export() []keybase1.PublicKey {
	var exportedKeys []keybase1.PublicKey
	for _, key := range ckf.GetAllActiveSibkeys() {
		exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
	}
	for _, key := range ckf.GetAllActiveSubkeys() {
		exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
	}
	sort.Sort(PublicKeyList(exportedKeys))
	return exportedKeys
}
1334186
func (s TrackSummary) Export(username string) (ret keybase1.TrackSummary) {
	ret.Time = keybase1.ToTime(s.time)
	ret.IsRemote = s.isRemote
	ret.Username = username
	return
}
779046
func (c *Host) GetVolume(volumeID string) (*volume.Info, error) {
	var volume volume.Info
	return &volume, c.c.Get(fmt.Sprintf("/storage/volumes/%s", volumeID), &volume)
}
389814
func (c *Client) GetExportByName(
	ctx context.Context, name string) (Export, error) {

	exports, err := api.ExportsList(ctx, c.API)
	if err != nil {
		return nil, err
	}
	path := c.API.VolumePath(name)
	for _, ex := range exports {
		for _, p := range *ex.Paths {
			if p == path {
				return ex, nil
			}
		}
	}
	return nil, nil
}
1048300
func (d *RsyncDriver) Create(volumeName string) (volume.Volume, error) {
	d.Lock()
	defer d.Unlock()
	if d.Exists(volumeName) {
		return nil, volume.ErrVolumeExists
	}
	if err := os.MkdirAll(filepath.Join(d.MetadataDir(), volumeName), 0755); err != nil && !os.IsExist(err) {
		return nil, err
	}
	volumePath := filepath.Join(d.root, volumeName)
	if err := os.MkdirAll(volumePath, 0755); err != nil {
		return nil, err
	}
	return d.Get(volumeName)
}
725452
func (t *UniversalTranslator) Export(format ImportExportFormat, dirname string) error {

	_, err := os.Stat(dirname)
	fmt.Println(dirname, err, os.IsNotExist(err))
	if err != nil {

		if !os.IsNotExist(err) {
			return err
		}

		if err = os.MkdirAll(dirname, 0744); err != nil {
			return err
		}
	}

	// build up translations
	var trans []translation
	var b []byte
	var ext string

	for _, locale := range t.translators {

		for k, v := range locale.(*translator).translations {
			trans = append(trans, translation{
				Locale:      locale.Locale(),
				Key:         k,
				Translation: v.text,
			})
		}

		for k, pluralTrans := range locale.(*translator).cardinalTanslations {

			for i, plural := range pluralTrans {

				// leave enough for all plural rules
				// but not all are set for all languages.
				if plural == nil {
					continue
				}

				trans = append(trans, translation{
					Locale:      locale.Locale(),
					Key:         k.(string),
					Translation: plural.text,
					PluralType:  cardinalType,
					PluralRule:  locales.PluralRule(i).String(),
				})
			}
		}

		for k, pluralTrans := range locale.(*translator).ordinalTanslations {

			for i, plural := range pluralTrans {

				// leave enough for all plural rules
				// but not all are set for all languages.
				if plural == nil {
					continue
				}

				trans = append(trans, translation{
					Locale:      locale.Locale(),
					Key:         k.(string),
					Translation: plural.text,
					PluralType:  ordinalType,
					PluralRule:  locales.PluralRule(i).String(),
				})
			}
		}

		for k, pluralTrans := range locale.(*translator).rangeTanslations {

			for i, plural := range pluralTrans {

				// leave enough for all plural rules
				// but not all are set for all languages.
				if plural == nil {
					continue
				}

				trans = append(trans, translation{
					Locale:      locale.Locale(),
					Key:         k.(string),
					Translation: plural.text,
					PluralType:  rangeType,
					PluralRule:  locales.PluralRule(i).String(),
				})
			}
		}

		switch format {
		case FormatJSON:
			b, err = json.MarshalIndent(trans, "", "    ")
			ext = ".json"
		}

		if err != nil {
			return err
		}

		err = ioutil.WriteFile(filepath.Join(dirname, fmt.Sprintf("%s%s", locale.Locale(), ext)), b, 0644)
		if err != nil {
			return err
		}

		trans = trans[0:0]
	}

	return nil
}
225148
func VolumeCtorNameIndex(name string, index int) Volume {
	return &xms.Volume{Name: name, Index: index}
}