本文整理汇总了Golang中github.com/lxc/lxd/shared.ImageInfo.Public方法的典型用法代码示例。如果您正苦于以下问题:Golang ImageInfo.Public方法的具体用法?Golang ImageInfo.Public怎么用?Golang ImageInfo.Public使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd/shared.ImageInfo
的用法示例。
在下文中一共展示了ImageInfo.Public方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ImageDownload
//.........这里部分代码省略.........
}
if err := json.Unmarshal(resp.Metadata, &info); err != nil {
return "", err
}
/* now grab the actual file from /1.0/images/%s/export */
if secret != "" {
exporturl = fmt.Sprintf(
"%s/%s/images/%s/export?secret=%s",
server, shared.APIVersion, fp, secret)
} else {
exporturl = fmt.Sprintf(
"%s/%s/images/%s/export",
server, shared.APIVersion, fp)
}
} else if protocol == "simplestreams" {
err := ss.Download(fp, "meta", destName, nil)
if err != nil {
return "", err
}
err = ss.Download(fp, "root", destName+".rootfs", progress)
if err != nil {
return "", err
}
info, err := ss.GetImageInfo(fp)
if err != nil {
return "", err
}
info.Public = false
info.AutoUpdate = autoUpdate
_, err = imageBuildFromInfo(d, *info)
if err != nil {
return "", err
}
if alias != fp {
id, _, err := dbImageGet(d.db, fp, false, true)
if err != nil {
return "", err
}
err = dbImageSourceInsert(d.db, id, server, protocol, "", alias)
if err != nil {
return "", err
}
}
shared.LogInfo("Image downloaded", ctxMap)
if forContainer {
return fp, dbImageLastAccessInit(d.db, fp)
}
return fp, nil
}
raw, err := d.httpGetFile(exporturl, certificate)
if err != nil {
shared.LogError(
"Failed to download image",
示例2: ImageDownload
//.........这里部分代码省略.........
}
if err := json.Unmarshal(resp.Metadata, &info); err != nil {
return "", err
}
/* now grab the actual file from /1.0/images/%s/export */
if secret != "" {
exporturl = fmt.Sprintf(
"%s/%s/images/%s/export?secret=%s",
server, shared.APIVersion, fp, secret)
} else {
exporturl = fmt.Sprintf(
"%s/%s/images/%s/export",
server, shared.APIVersion, fp)
}
} else if protocol == "simplestreams" {
err := ss.Download(fp, "meta", destName, nil)
if err != nil {
return "", err
}
err = ss.Download(fp, "root", destName+".rootfs", progress)
if err != nil {
return "", err
}
info, err := ss.GetImageInfo(fp)
if err != nil {
return "", err
}
info.Public = false
info.AutoUpdate = autoUpdate
_, err = imageBuildFromInfo(d, *info)
if err != nil {
return "", err
}
if alias != fp {
id, _, err := dbImageGet(d.db, fp, false, true)
if err != nil {
return "", err
}
err = dbImageSourceInsert(d.db, id, server, protocol, "", alias)
if err != nil {
return "", err
}
}
if forContainer {
return fp, dbImageLastAccessInit(d.db, fp)
}
return fp, nil
}
raw, err := d.httpGetFile(exporturl, certificate)
if err != nil {
shared.Log.Error(
"Failed to download image",
log.Ctx{"image": fp, "err": err})
return "", err
示例3: ImageDownload
//.........这里部分代码省略.........
if err != nil {
shared.Log.Error(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return err
}
// Get the rootfs tarball
part, err = mr.NextPart()
if err != nil {
shared.Log.Error(
"Invalid multipart image",
log.Ctx{"image": fp, "err": err})
return err
}
if part.FormName() != "rootfs" {
shared.Log.Error(
"Invalid multipart image",
log.Ctx{"image": fp})
return fmt.Errorf("Invalid multipart image")
}
destName = filepath.Join(destDir, info.Fingerprint+".rootfs")
f, err = os.Create(destName)
if err != nil {
shared.Log.Error(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return err
}
_, err = io.Copy(f, part)
f.Close()
if err != nil {
shared.Log.Error(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return err
}
} else {
destName = filepath.Join(destDir, info.Fingerprint)
f, err := os.Create(destName)
if err != nil {
shared.Log.Error(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return err
}
_, err = io.Copy(f, body)
f.Close()
if err != nil {
shared.Log.Error(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return err
}
}
if directDownload {
imageMeta, err := getImageMetadata(destName)
if err != nil {
return err
}
info.Architecture, _ = shared.ArchitectureId(imageMeta.Architecture)
info.CreationDate = imageMeta.CreationDate
info.ExpiryDate = imageMeta.ExpiryDate
info.Properties = imageMeta.Properties
}
// By default, make all downloaded images private
info.Public = false
_, err = imageBuildFromInfo(d, info)
if err != nil {
shared.Log.Error(
"Failed to create image",
log.Ctx{"image": fp, "err": err})
return err
}
shared.Log.Info(
"Download succeeded",
log.Ctx{"image": fp})
if forContainer {
return dbImageLastAccessInit(d.db, fp)
}
return nil
}