本文整理汇总了Golang中github.com/lxc/lxd/shared.VarPath函数的典型用法代码示例。如果您正苦于以下问题:Golang VarPath函数的具体用法?Golang VarPath怎么用?Golang VarPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VarPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ContainerCreateFromImage
func (s *storageLvm) ContainerCreateFromImage(
container container, imageFingerprint string) error {
imageLVFilename := shared.VarPath(
"images", fmt.Sprintf("%s.lv", imageFingerprint))
if !shared.PathExists(imageLVFilename) {
if err := s.ImageCreate(imageLVFilename); err != nil {
return err
}
}
containerName := containerNameToLVName(container.Name())
lvpath, err := s.createSnapshotLV(containerName, imageFingerprint, false)
if err != nil {
return err
}
destPath := container.Path("")
if err := os.MkdirAll(destPath, 0755); err != nil {
return fmt.Errorf("Error creating container directory: %v", err)
}
dst := shared.VarPath("containers", fmt.Sprintf("%s.lv", container.Name()))
err = os.Symlink(lvpath, dst)
if err != nil {
return err
}
output, err := exec.Command("mount", "-o", "discard", lvpath, destPath).CombinedOutput()
if err != nil {
s.ContainerDelete(container)
return fmt.Errorf("Error mounting snapshot LV: %v\noutput:'%s'", err, string(output))
}
if !container.IsPrivileged() {
if err = s.shiftRootfs(container); err != nil {
output, err2 := exec.Command("umount", destPath).CombinedOutput()
if err2 != nil {
return fmt.Errorf("Error in umount: '%s' while cleaning up after error in shiftRootfs: '%s'\n umount output: '%s'", err2, err, output)
}
s.ContainerDelete(container)
return fmt.Errorf("Error in shiftRootfs: %v", err)
}
}
err = container.TemplateApply("create")
if err != nil {
s.log.Error("Error in create template during ContainerCreateFromImage, continuing to unmount",
log.Ctx{"err": err})
}
output, umounterr := exec.Command("umount", destPath).CombinedOutput()
if umounterr != nil {
return fmt.Errorf("Error unmounting '%s' after shiftRootfs: %v", destPath, umounterr)
}
return err
}
示例2: dbUpdateFromV30
func dbUpdateFromV30(currentVersion int, version int, d *Daemon) error {
if d.MockMode {
return nil
}
entries, err := ioutil.ReadDir(shared.VarPath("containers"))
if err != nil {
return err
}
for _, entry := range entries {
if !shared.IsDir(shared.VarPath("containers", entry.Name(), "rootfs")) {
continue
}
info, err := os.Stat(shared.VarPath("containers", entry.Name(), "rootfs"))
if err != nil {
return err
}
if int(info.Sys().(*syscall.Stat_t).Uid) == 0 {
err := os.Chmod(shared.VarPath("containers", entry.Name()), 0700)
if err != nil {
return err
}
err = os.Chown(shared.VarPath("containers", entry.Name()), 0, 0)
if err != nil {
return err
}
}
}
return nil
}
示例3: containerPost
func containerPost(d *Daemon, r *http.Request) Response {
name := mux.Vars(r)["name"]
c, err := newLxdContainer(name, d)
if err != nil {
return SmartError(err)
}
buf, err := ioutil.ReadAll(r.Body)
if err != nil {
return InternalError(err)
}
body := containerPostBody{}
if err := json.Unmarshal(buf, &body); err != nil {
return BadRequest(err)
}
if body.Migration {
ws, err := migration.NewMigrationSource(c.c)
if err != nil {
return InternalError(err)
}
return AsyncResponseWithWs(ws, nil)
} else {
if c.c.Running() {
return BadRequest(fmt.Errorf("renaming of running container not allowed"))
}
args := DbCreateContainerArgs{
d: d,
name: body.Name,
ctype: cTypeRegular,
config: c.config,
profiles: c.profiles,
ephem: c.ephemeral,
baseImage: c.config["volatile.baseImage"],
architecture: c.architecture,
}
_, err := dbCreateContainer(args)
if err != nil {
return SmartError(err)
}
run := func() error {
oldPath := fmt.Sprintf("%s/", shared.VarPath("lxc", c.name))
newPath := fmt.Sprintf("%s/", shared.VarPath("lxc", body.Name))
if err := os.Rename(oldPath, newPath); err != nil {
return err
}
removeContainer(d, c.name)
return nil
}
return AsyncResponse(shared.OperationWrap(run), nil)
}
}
示例4: btrfsCopyImage
func btrfsCopyImage(hash string, name string, d *Daemon) error {
dpath := shared.VarPath("lxc", name)
imagefile := shared.VarPath("images", hash)
subvol := fmt.Sprintf("%s.btrfs", imagefile)
return exec.Command("btrfs", "subvolume", "snapshot", subvol, dpath).Run()
}
示例5: imageBuildFromInfo
func imageBuildFromInfo(d *Daemon, info shared.ImageInfo) (metadata map[string]string, err error) {
err = d.Storage.ImageCreate(info.Fingerprint)
if err != nil {
os.Remove(shared.VarPath("images", info.Fingerprint))
os.Remove(shared.VarPath("images", info.Fingerprint) + ".rootfs")
return metadata, err
}
err = dbImageInsert(
d.db,
info.Fingerprint,
info.Filename,
info.Size,
info.Public,
info.AutoUpdate,
info.Architecture,
info.CreationDate,
info.ExpiryDate,
info.Properties)
if err != nil {
return metadata, err
}
metadata = make(map[string]string)
metadata["fingerprint"] = info.Fingerprint
metadata["size"] = strconv.FormatInt(info.Size, 10)
return metadata, nil
}
示例6: ContainerSnapshotDelete
func (s *storageZfs) ContainerSnapshotDelete(snapshotContainer container) error {
fields := strings.SplitN(snapshotContainer.Name(), shared.SnapshotDelimiter, 2)
cName := fields[0]
snapName := fmt.Sprintf("snapshot-%s", fields[1])
removable, err := s.zfsSnapshotRemovable(fmt.Sprintf("containers/%s", cName), snapName)
if removable {
err = s.zfsSnapshotDestroy(fmt.Sprintf("containers/%s", cName), snapName)
if err != nil {
return err
}
} else {
err = s.zfsSnapshotRename(fmt.Sprintf("containers/%s", cName), snapName, fmt.Sprintf("copy-%s", uuid.NewV4().String()))
if err != nil {
return err
}
}
err = os.Remove(shared.VarPath(fmt.Sprintf("snapshots/%s/%s.zfs", cName, fields[1])))
if err != nil {
return err
}
parent := shared.VarPath(fmt.Sprintf("snapshots/%s", cName))
if ok, _ := shared.PathIsEmpty(parent); ok {
err = os.Remove(parent)
if err != nil {
return err
}
}
return nil
}
示例7: containerPath
// Helper functions
func containerPath(name string, isSnapshot bool) string {
if isSnapshot {
return shared.VarPath("snapshots", name)
}
return shared.VarPath("containers", name)
}
示例8: ContainerRename
func (s *storageZfs) ContainerRename(container container, newName string) error {
oldName := container.Name()
err := s.zfsRename(fmt.Sprintf("containers/%s", oldName), fmt.Sprintf("containers/%s", newName))
if err != nil {
return err
}
err = s.zfsSet(fmt.Sprintf("containers/%s", newName), "mountpoint", shared.VarPath(fmt.Sprintf("containers/%s", newName)))
if err != nil {
return err
}
err = os.Rename(shared.VarPath(fmt.Sprintf("containers/%s.zfs", oldName)), shared.VarPath(fmt.Sprintf("containers/%s.zfs", newName)))
if err != nil {
return err
}
err = os.Remove(shared.VarPath(fmt.Sprintf("containers/%s", oldName)))
if err != nil {
return err
}
return nil
}
示例9: dbUpdatesApplyAll
func dbUpdatesApplyAll(d *Daemon) error {
currentVersion := dbGetSchema(d.db)
backup := false
for _, update := range dbUpdates {
if update.version <= currentVersion {
continue
}
if !d.MockMode && !backup {
shared.LogInfof("Updating the LXD database schema. Backup made as \"lxd.db.bak\"")
err := shared.FileCopy(shared.VarPath("lxd.db"), shared.VarPath("lxd.db.bak"))
if err != nil {
return err
}
backup = true
}
err := update.apply(currentVersion, d)
if err != nil {
return err
}
currentVersion = update.version
}
return nil
}
示例10: ImageDelete
func (s *storageZfs) ImageDelete(fingerprint string) error {
fs := fmt.Sprintf("images/%s", fingerprint)
removable, err := s.zfsSnapshotRemovable(fs, "readonly")
if err != nil {
return err
}
if removable {
err := s.zfsDestroy(fs)
if err != nil {
return err
}
} else {
err := s.zfsSet(fs, "mountpoint", "none")
if err != nil {
return err
}
err = s.zfsRename(fs, fmt.Sprintf("deleted/%s", fs))
if err != nil {
return err
}
}
if shared.PathExists(shared.VarPath(fs + ".zfs")) {
os.Remove(shared.VarPath(fs + ".zfs"))
}
return nil
}
示例11: PathGet
func (c *lxdContainer) PathGet() string {
if c.IsSnapshot() {
return shared.VarPath("snapshots", c.NameGet())
}
return shared.VarPath("containers", c.NameGet())
}
示例12: exportToDir
/*
* Export the container under @dir. It will look like:
* dir/
* metadata.yaml
* rootfs/
*/
func (d *lxdContainer) exportToDir(snap, dir string) error {
if snap != "" && d.c.Running() {
return fmt.Errorf("Cannot export a running container as image")
}
source := shared.VarPath("lxc", d.name, "metadata.yaml")
dest := fmt.Sprintf("%s/metadata.yaml", dir)
if shared.PathExists(source) {
if err := shared.CopyFile(dest, source); err != nil {
return err
}
}
if snap != "" {
source = snapshotRootfsDir(d, snap)
} else {
source = shared.VarPath("lxc", d.name, "rootfs")
}
// rsync the rootfs
err := exec.Command("rsync", "-a", "--devices", source, dir).Run()
if err != nil {
return err
}
// unshift
if !d.isPrivileged() {
rootfs := fmt.Sprintf("%s/rootfs", dir)
err = d.idmapset.UnshiftRootfs(rootfs)
}
return err
}
示例13: pullOutImagefiles
// Copy imagefile and btrfs file out of the tmpdir
func pullOutImagefiles(d *Daemon, builddir string, fingerprint string) error {
imagefname := filepath.Join(builddir, fingerprint)
finalName := shared.VarPath("images", fingerprint)
err := os.Rename(imagefname, finalName)
if err != nil {
return err
}
lvsymlink := fmt.Sprintf("%s.lv", imagefname)
if _, err := os.Stat(lvsymlink); err == nil {
dst := shared.VarPath("images", fmt.Sprintf("%s.lv", fingerprint))
return os.Rename(lvsymlink, dst)
}
switch d.BackingFs {
case "btrfs":
subvol := fmt.Sprintf("%s.btrfs", imagefname)
dst := shared.VarPath("images", fmt.Sprintf("%s.btrfs", fingerprint))
if err := os.Rename(subvol, dst); err != nil {
return err
}
}
return nil
}
示例14: ImageCreate
func (s *storageLvm) ImageCreate(fingerprint string) error {
finalName := shared.VarPath("images", fingerprint)
lvpath, err := s.createThinLV(fingerprint)
if err != nil {
s.log.Error("LVMCreateThinLV", log.Ctx{"err": err})
return fmt.Errorf("Error Creating LVM LV for new image: %v", err)
}
dst := shared.VarPath("images", fmt.Sprintf("%s.lv", fingerprint))
err = os.Symlink(lvpath, dst)
if err != nil {
return err
}
tempLVMountPoint, err := ioutil.TempDir(shared.VarPath("images"), "tmp_lv_mnt")
if err != nil {
return err
}
defer func() {
if err := os.RemoveAll(tempLVMountPoint); err != nil {
s.log.Error("Deleting temporary LVM mount point", log.Ctx{"err": err})
}
}()
var fstype string
fstype, err = s.d.ConfigValueGet("storage.lvm_fstype")
if err != nil {
return fmt.Errorf("Error checking server config, err=%v", err)
}
if fstype == "" {
fstype = "ext4"
}
err = s.tryMount(lvpath, tempLVMountPoint, fstype, 0, "discard")
if err != nil {
shared.Logf("Error mounting image LV for untarring: %v", err)
return fmt.Errorf("Error mounting image LV: %v", err)
}
untarErr := untarImage(finalName, tempLVMountPoint)
err = s.tryUnmount(tempLVMountPoint, 0)
if err != nil {
s.log.Warn("could not unmount LV. Will not remove",
log.Ctx{"lvpath": lvpath, "mountpoint": tempLVMountPoint, "err": err})
if untarErr == nil {
return err
}
return fmt.Errorf(
"Error unmounting '%s' during cleanup of error %v",
tempLVMountPoint, untarErr)
}
return untarErr
}
示例15: readMyCert
func readMyCert() (string, string, error) {
certf := shared.VarPath("server.crt")
keyf := shared.VarPath("server.key")
shared.LogDebug("Looking for existing certificates", log.Ctx{"cert": certf, "key": keyf})
err := shared.FindOrGenCert(certf, keyf, false)
return certf, keyf, err
}