本文整理汇总了Golang中github.com/lxc/lxd/shared.ImageInfo.ExpiryDate方法的典型用法代码示例。如果您正苦于以下问题:Golang ImageInfo.ExpiryDate方法的具体用法?Golang ImageInfo.ExpiryDate怎么用?Golang ImageInfo.ExpiryDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd/shared.ImageInfo
的用法示例。
在下文中一共展示了ImageInfo.ExpiryDate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dbImageGet
// dbImageGet gets an ImageBaseInfo object from the database.
// The argument fingerprint will be queried with a LIKE query, means you can
// pass a shortform and will get the full fingerprint.
// There can never be more than one image with a given fingerprint, as it is
// enforced by a UNIQUE constraint in the schema.
func dbImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool) (int, *shared.ImageInfo, error) {
var err error
var create, expire, used, upload *time.Time // These hold the db-returned times
// The object we'll actually return
image := shared.ImageInfo{}
id := -1
arch := -1
// These two humongous things will be filled by the call to DbQueryRowScan
outfmt := []interface{}{&id, &image.Fingerprint, &image.Filename,
&image.Size, &image.Cached, &image.Public, &image.AutoUpdate, &arch,
&create, &expire, &used, &upload}
var query string
var inargs []interface{}
if strictMatching {
inargs = []interface{}{fingerprint}
query = `
SELECT
id, fingerprint, filename, size, cached, public, auto_update, architecture,
creation_date, expiry_date, last_use_date, upload_date
FROM
images
WHERE fingerprint = ?`
} else {
inargs = []interface{}{fingerprint + "%"}
query = `
SELECT
id, fingerprint, filename, size, cached, public, auto_update, architecture,
creation_date, expiry_date, last_use_date, upload_date
FROM
images
WHERE fingerprint LIKE ?`
}
if public {
query = query + " AND public=1"
}
err = dbQueryRowScan(db, query, inargs, outfmt)
if err != nil {
return -1, nil, err // Likely: there are no rows for this fingerprint
}
// Some of the dates can be nil in the DB, let's process them.
if create != nil {
image.CreationDate = *create
} else {
image.CreationDate = time.Time{}
}
if expire != nil {
image.ExpiryDate = *expire
} else {
image.ExpiryDate = time.Time{}
}
if used != nil {
image.LastUsedDate = *used
} else {
image.LastUsedDate = time.Time{}
}
image.Architecture, _ = shared.ArchitectureName(arch)
// The upload date is enforced by NOT NULL in the schema, so it can never be nil.
image.UploadDate = *upload
// Get the properties
q := "SELECT key, value FROM images_properties where image_id=?"
var key, value, name, desc string
inargs = []interface{}{id}
outfmt = []interface{}{key, value}
results, err := dbQueryScan(db, q, inargs, outfmt)
if err != nil {
return -1, nil, err
}
properties := map[string]string{}
for _, r := range results {
key = r[0].(string)
value = r[1].(string)
properties[key] = value
}
image.Properties = properties
// Get the aliases
q = "SELECT name, description FROM images_aliases WHERE image_id=?"
inargs = []interface{}{id}
outfmt = []interface{}{name, desc}
results, err = dbQueryScan(db, q, inargs, outfmt)
//.........这里部分代码省略.........
示例2: ImageDownload
//.........这里部分代码省略.........
return "", err
}
if part.FormName() != "rootfs" {
shared.LogError(
"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.LogError(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return "", err
}
_, err = io.Copy(f, part)
f.Close()
if err != nil {
shared.LogError(
"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.LogError(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return "", err
}
_, err = io.Copy(f, body)
f.Close()
if err != nil {
shared.LogError(
"Failed to save image",
log.Ctx{"image": fp, "err": err})
return "", err
}
}
if protocol == "direct" {
imageMeta, err := getImageMetadata(destName)
if err != nil {
return "", err
}
info.Architecture = imageMeta.Architecture
info.CreationDate = time.Unix(imageMeta.CreationDate, 0)
info.ExpiryDate = time.Unix(imageMeta.ExpiryDate, 0)
info.Properties = imageMeta.Properties
}
// By default, make all downloaded images private
info.Public = false
if alias != fp && secret == "" {
info.AutoUpdate = autoUpdate
}
_, err = imageBuildFromInfo(d, info)
if err != nil {
shared.LogError(
"Failed to create image",
log.Ctx{"image": fp, "err": err})
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
}
示例3: ImageDownload
//.........这里部分代码省略.........
"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 protocol == "direct" {
imageMeta, err := getImageMetadata(destName)
if err != nil {
return "", err
}
info.Architecture = imageMeta.Architecture
info.CreationDate = time.Unix(imageMeta.CreationDate, 0)
info.ExpiryDate = time.Unix(imageMeta.ExpiryDate, 0)
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
}
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.Log.Info(
"Download succeeded",
log.Ctx{"image": fp})
if forContainer {
return fp, dbImageLastAccessInit(d.db, fp)
}
return fp, nil
}
示例4: 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
}