本文整理汇总了Golang中github.com/coreos/rkt/store.NewStore函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStore函数的具体用法?Golang NewStore怎么用?Golang NewStore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStore函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetStoreKeyFromApp
func TestGetStoreKeyFromApp(t *testing.T) {
dir, err := ioutil.TempDir("", "fetch-image")
if err != nil {
t.Fatalf("error creating tempdir: %v", err)
}
defer os.RemoveAll(dir)
s, err := store.NewStore(dir)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
defer s.Dump(false)
// Test an aci without os and arch labels
a, err := aci.NewBasicACI(dir, "example.com/app")
defer a.Close()
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
_, err = s.WriteACI(a, false)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
_, err = getStoreKeyFromApp(s, "example.com/app")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:matomesc,项目名称:rkt,代码行数:32,代码来源:fetch_test.go
示例2: getStore
func getStore() *store.Store {
s, err := store.NewStore(storeDir)
if err != nil {
log.Fatalf("Unable to open a new ACI store: %s", err)
}
return s
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:7,代码来源:main.go
示例3: importOciBundle
func importOciBundle(cmd *cobra.Command, args []string) (exit int) {
//command is "rkt image import-oci oci-bundle-path"
if len(args) < 1 {
fmt.Printf("command should be: rkt image import-oci ocibundle")
return 1
}
aciImage, err := Oci2aciImage(args[0])
if err != nil {
fmt.Printf("convert oci bundle to aci image error: %v", err)
return 1
}
//save aci to rkt store
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
fmt.Printf("cannot open store: %v", err)
return 1
}
aciFile, err := os.Open(aciImage)
if err != nil {
fmt.Printf("error opening ACI file %s: %v", aciImage, err)
return 1
}
key, err := s.WriteACI(aciFile, true)
if err != nil {
fmt.Printf("error write ACI file: %v", err)
return 1
}
fmt.Println(key)
return 0
}
开发者ID:sdgdsffdsfff,项目名称:rkt,代码行数:32,代码来源:oci2aci.go
示例4: runImageImport
func runImageImport(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
//convert oci bundle to aci image
aciImage, err := oci2aci.Oci2aciImage(args[0])
if err != nil {
fmt.Printf("oci2aci failed: %v", err)
return 1
}
//save aci to rkt store
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
fmt.Printf("cannot open store: %v", err)
return 1
}
aciFile, err := os.Open(aciImage)
if err != nil {
fmt.Printf("opening ACI file %s failed: %v", aciImage, err)
return 1
}
key, err := s.WriteACI(aciFile, true)
if err != nil {
fmt.Printf("write ACI file failed: %v", err)
return 1
}
fmt.Println(key)
return 0
}
开发者ID:liugenping,项目名称:rkt,代码行数:32,代码来源:image_importoci.go
示例5: runFetch
func runFetch(cmd *cobra.Command, args []string) (exit int) {
if err := parseApps(&rktApps, args, cmd.Flags(), false); err != nil {
stderr.PrintE("unable to parse arguments", err)
return 1
}
if rktApps.Count() < 1 {
stderr.Print("must provide at least one image")
return 1
}
if flagStoreOnly && flagNoStore {
stderr.Print("both --store-only and --no-store specified")
return 1
}
s, err := store.NewStore(getDataDir())
if err != nil {
stderr.PrintE("cannot open store", err)
return 1
}
ks := getKeystore()
config, err := getConfig()
if err != nil {
stderr.PrintE("cannot get configuration", err)
return 1
}
ft := &image.Fetcher{
S: s,
Ks: ks,
Headers: config.AuthPerHost,
DockerAuth: config.DockerCredentialsPerRegistry,
InsecureFlags: globalFlags.InsecureFlags,
Debug: globalFlags.Debug,
TrustKeysFromHTTPS: globalFlags.TrustKeysFromHTTPS,
StoreOnly: flagStoreOnly,
NoStore: flagNoStore,
WithDeps: true,
}
err = rktApps.Walk(func(app *apps.App) error {
hash, err := ft.FetchImage(app.Image, app.Asc, app.ImType)
if err != nil {
return err
}
if !flagFullHash {
hash = types.ShortHash(hash)
}
stdout.Print(hash)
return nil
})
if err != nil {
stderr.Error(err)
return 1
}
return
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:59,代码来源:fetch.go
示例6: deletePod
// deletePod cleans up files and resource associated with the pod
// pod must be under exclusive lock and be in either ExitedGarbage
// or Garbage state
func deletePod(p *pod) {
if !p.isExitedGarbage && !p.isGarbage {
panic(fmt.Sprintf("logic error: deletePod called with non-garbage pod %q (status %q)", p.uuid, p.getState()))
}
if p.isExitedGarbage {
s, err := store.NewStore(getDataDir())
if err != nil {
stderr("Cannot open store: %v", err)
return
}
defer s.Close()
stage1TreeStoreID, err := p.getStage1TreeStoreID()
if err != nil {
stderr("Error getting stage1 treeStoreID: %v", err)
return
}
stage1RootFS := s.GetTreeStoreRootFS(stage1TreeStoreID)
// execute stage1's GC
if err := stage0.GC(p.path(), p.uuid, stage1RootFS, globalFlags.Debug); err != nil {
stderr("Stage1 GC of pod %q failed: %v", p.uuid, err)
return
}
if p.usesOverlay() {
apps, err := p.getApps()
if err != nil {
stderr("Error retrieving app hashes from pod manifest: %v", err)
return
}
for _, a := range apps {
dest := filepath.Join(common.AppPath(p.path(), a.Name), "rootfs")
if err := syscall.Unmount(dest, 0); err != nil {
// machine could have been rebooted and mounts lost.
// ignore "does not exist" and "not a mount point" errors
if err != syscall.ENOENT && err != syscall.EINVAL {
stderr("Error unmounting app at %v: %v", dest, err)
}
}
}
s1 := filepath.Join(common.Stage1ImagePath(p.path()), "rootfs")
if err := syscall.Unmount(s1, 0); err != nil {
// machine could have been rebooted and mounts lost.
// ignore "does not exist" and "not a mount point" errors
if err != syscall.ENOENT && err != syscall.EINVAL {
stderr("Error unmounting stage1 at %v: %v", s1, err)
return
}
}
}
}
if err := os.RemoveAll(p.path()); err != nil {
stderr("Unable to remove pod %q: %v", p.uuid, err)
}
}
开发者ID:krnowak,项目名称:rkt,代码行数:61,代码来源:gc.go
示例7: runRmImage
func runRmImage(cmd *cobra.Command, args []string) (exit int) {
if len(args) < 1 {
stderr("rkt: Must provide at least one image key")
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("rkt: cannot open store: %v", err)
return 1
}
//TODO(sgotti) Which return code to use when the removal fails only for some images?
done := 0
errors := 0
staleErrors := 0
for _, pkey := range args {
errors++
h, err := types.NewHash(pkey)
if err != nil {
stderr("rkt: wrong imageID %q: %v", pkey, err)
continue
}
key, err := s.ResolveKey(h.String())
if err != nil {
stderr("rkt: imageID %q not valid: %v", pkey, err)
continue
}
if key == "" {
stderr("rkt: imageID %q doesn't exists", pkey)
continue
}
if err = s.RemoveACI(key); err != nil {
if serr, ok := err.(*store.StoreRemovalError); ok {
staleErrors++
stderr("rkt: some files cannot be removed for imageID %q: %v", pkey, serr)
} else {
stderr("rkt: error removing aci for imageID %q: %v", pkey, err)
continue
}
}
stdout("rkt: successfully removed aci for imageID: %q", pkey)
errors--
done++
}
if done > 0 {
stderr("rkt: %d image(s) successfully removed", done)
}
if errors > 0 {
stderr("rkt: %d image(s) cannot be removed", errors)
}
if staleErrors > 0 {
stderr("rkt: %d image(s) removed but left some stale files", staleErrors)
}
return 0
}
开发者ID:NeilW,项目名称:rkt,代码行数:58,代码来源:image_rm.go
示例8: runImageCatManifest
func runImageCatManifest(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 1 {
cmd.Usage()
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("image cat-manifest: cannot open store: %v", err)
return 1
}
var key string
if _, err := types.NewHash(args[0]); err == nil {
key, err = s.ResolveKey(args[0])
if err != nil {
stderr("image cat-manifest: cannot resolve key: %v", err)
return 1
}
} else {
app, err := discovery.NewAppFromString(args[0])
if err != nil {
stderr("image cat-manifest: cannot parse the image name: %v", err)
return 1
}
labels, err := types.LabelsFromMap(app.Labels)
if err != nil {
stderr("image cat-manifest: invalid labels in the name: %v", err)
return 1
}
key, err = s.GetACI(app.Name, labels)
if err != nil {
stderr("image cat-manifest: cannot find image: %v", err)
return 1
}
}
manifest, err := s.GetImageManifest(key)
if err != nil {
stderr("image cat-manifest: cannot get image manifest: %v", err)
return 1
}
var b []byte
if flagPrettyPrint {
b, err = json.MarshalIndent(manifest, "", "\t")
} else {
b, err = json.Marshal(manifest)
}
if err != nil {
stderr("image cat-manifest: cannot read the image manifest: %v", err)
return 1
}
stdout(string(b))
return 0
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:57,代码来源:image_cat_manifest.go
示例9: runFetch
func runFetch(cmd *cobra.Command, args []string) (exit int) {
if err := parseApps(&rktApps, args, cmd.Flags(), false); err != nil {
stderr("fetch: unable to parse arguments: %v", err)
return 1
}
if rktApps.Count() < 1 {
stderr("fetch: must provide at least one image")
return 1
}
if flagStoreOnly && flagNoStore {
stderr("both --store-only and --no-store specified")
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("fetch: cannot open store: %v", err)
return 1
}
ks := getKeystore()
config, err := getConfig()
if err != nil {
stderr("fetch: cannot get configuration: %v", err)
return 1
}
ft := &fetcher{
imageActionData: imageActionData{
s: s,
ks: ks,
headers: config.AuthPerHost,
dockerAuth: config.DockerCredentialsPerRegistry,
insecureSkipVerify: globalFlags.InsecureSkipVerify,
debug: globalFlags.Debug,
},
storeOnly: flagStoreOnly,
noStore: flagNoStore,
withDeps: true,
}
err = rktApps.Walk(func(app *apps.App) error {
hash, err := ft.fetchImage(app.Image, app.Asc)
if err != nil {
return err
}
shortHash := types.ShortHash(hash)
stdout(shortHash)
return nil
})
if err != nil {
stderr("%v", err)
return 1
}
return
}
开发者ID:NeilW,项目名称:rkt,代码行数:57,代码来源:fetch.go
示例10: runEnter
func runEnter(cmd *cobra.Command, args []string) (exit int) {
if len(args) < 1 {
cmd.Usage()
return 1
}
p, err := getPodFromUUIDString(args[0])
if err != nil {
stderr.PrintE("problem retrieving pod", err)
return 1
}
defer p.Close()
if !p.isRunning() {
stderr.Printf("pod %q isn't currently running", p.uuid)
return 1
}
podPID, err := p.getContainerPID1()
if err != nil {
stderr.PrintE(fmt.Sprintf("unable to determine the pid for pod %q", p.uuid), err)
return 1
}
appName, err := getAppName(p)
if err != nil {
stderr.PrintE("unable to determine app name", err)
return 1
}
argv, err := getEnterArgv(p, args)
if err != nil {
stderr.PrintE("enter failed", err)
return 1
}
s, err := store.NewStore(getDataDir())
if err != nil {
stderr.PrintE("cannot open store", err)
return 1
}
stage1TreeStoreID, err := p.getStage1TreeStoreID()
if err != nil {
stderr.PrintE("error getting stage1 treeStoreID", err)
return 1
}
stage1RootFS := s.GetTreeStoreRootFS(stage1TreeStoreID)
if err = stage0.Enter(p.path(), podPID, *appName, stage1RootFS, argv); err != nil {
stderr.PrintE("enter failed", err)
return 1
}
// not reached when stage0.Enter execs /enter
return 0
}
开发者ID:hwinkel,项目名称:rkt,代码行数:57,代码来源:enter.go
示例11: runImageExport
func runImageExport(cmd *cobra.Command, args []string) (exit int) {
if len(args) != 2 {
cmd.Usage()
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("image export: cannot open store: %v", err)
return 1
}
key, err := getKeyFromAppOrHash(s, args[0])
if err != nil {
stderr("image export: %v", err)
return 1
}
aci, err := s.ReadStream(key)
if err != nil {
stderr("image export: error reading image: %v", err)
return 1
}
defer aci.Close()
mode := os.O_CREATE | os.O_WRONLY
if flagOverwriteACI {
mode |= os.O_TRUNC
} else {
mode |= os.O_EXCL
}
f, err := os.OpenFile(args[1], mode, 0644)
if err != nil {
if os.IsExist(err) {
stderr("image export: output ACI file exists (try --overwrite)")
} else {
stderr("image export: unable to open output ACI file %s: %v", args[1], err)
}
return 1
}
defer func() {
err := f.Close()
if err != nil {
stderr("image export: error closing output ACI file: %v", err)
exit = 1
}
}()
_, err = io.Copy(f, aci)
if err != nil {
stderr("image export: error writing to output ACI file: %v", err)
return 1
}
return 0
}
开发者ID:jsarenik,项目名称:rkt,代码行数:56,代码来源:image_export.go
示例12: newV1AlphaAPIServer
func newV1AlphaAPIServer() (*v1AlphaAPIServer, error) {
s, err := store.NewStore(getDataDir())
if err != nil {
return nil, err
}
return &v1AlphaAPIServer{
store: s,
}, nil
}
开发者ID:krnowak,项目名称:rkt,代码行数:10,代码来源:api_service.go
示例13: newV1AlphaAPIServer
func newV1AlphaAPIServer() (*v1AlphaAPIServer, error) {
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
return nil, err
}
return &v1AlphaAPIServer{
store: s,
}, nil
}
开发者ID:pbprasad99,项目名称:rkt,代码行数:10,代码来源:api_service.go
示例14: runImages
func runImages(cmd *cobra.Command, args []string) (exit int) {
if !flagNoLegend {
headerFields := []string{}
for _, f := range flagImagesFields {
headerFields = append(headerFields, ImagesFieldHeaderMap[f])
}
fmt.Fprintf(tabOut, "%s\n", strings.Join(headerFields, "\t"))
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("images: cannot open store: %v\n", err)
return 1
}
sortAciinfoFields := []string{}
for _, f := range flagImagesSortFields {
sortAciinfoFields = append(sortAciinfoFields, ImagesFieldAciInfoMap[f])
}
aciInfos, err := s.GetAllACIInfos(sortAciinfoFields, bool(flagImagesSortAsc))
if err != nil {
stderr("images: unable to get aci infos: %v", err)
return
}
for _, aciInfo := range aciInfos {
im, err := s.GetImageManifest(aciInfo.BlobKey)
if err != nil {
// ignore aciInfo with missing image manifest as it can be deleted in the meantime
continue
}
version, ok := im.Labels.Get("version")
for _, f := range flagImagesFields {
switch f {
case keyField:
fmt.Fprintf(tabOut, "%s", aciInfo.BlobKey)
case nameField:
fmt.Fprintf(tabOut, "%s", aciInfo.Name)
if ok {
fmt.Fprintf(tabOut, ":%s", version)
}
case importTimeField:
fmt.Fprintf(tabOut, "%s", aciInfo.ImportTime.Format(defaultTimeLayout))
case latestField:
fmt.Fprintf(tabOut, "%t", aciInfo.Latest)
}
fmt.Fprintf(tabOut, "\t")
}
fmt.Fprintf(tabOut, "\n")
}
tabOut.Flush()
return 0
}
开发者ID:samarvin,项目名称:rkt,代码行数:55,代码来源:image_list.go
示例15: runGcImage
func runGcImage(cmd *cobra.Command, args []string) (exit int) {
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("rkt: cannot open store: %v", err)
return 1
}
if err := gcTreeStore(s); err != nil {
stderr("rkt: failed to remove unreferenced treestores: %v", err)
return 1
}
return 0
}
开发者ID:NeilW,项目名称:rkt,代码行数:13,代码来源:image_gc.go
示例16: runFetch
func runFetch(args []string) (exit int) {
if err := parseApps(&rktApps, args, &fetchFlags, false); err != nil {
stderr("fetch: unable to parse arguments: %v", err)
return 1
}
if rktApps.Count() < 1 {
stderr("fetch: must provide at least one image")
return 1
}
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("fetch: cannot open store: %v", err)
return 1
}
ks := getKeystore()
config, err := getConfig()
if err != nil {
stderr("fetch: cannot get configuration: %v", err)
return 1
}
ft := &fetcher{
imageActionData: imageActionData{
s: s,
ks: ks,
headers: config.AuthPerHost,
dockerAuth: config.DockerCredentialsPerRegistry,
insecureSkipVerify: globalFlags.InsecureSkipVerify,
debug: globalFlags.Debug,
},
withDeps: true,
}
err = rktApps.Walk(func(app *apps.App) error {
hash, err := ft.fetchImage(app.Image, app.Asc, true)
if err != nil {
return err
}
shortHash := types.ShortHash(hash)
fmt.Println(shortHash)
return nil
})
if err != nil {
stderr("%v", err)
return 1
}
return
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:49,代码来源:fetch.go
示例17: emptyExitedGarbage
// emptyExitedGarbage discards sufficiently aged pods from exitedGarbageDir()
func emptyExitedGarbage(gracePeriod time.Duration) error {
if err := walkPods(includeExitedGarbageDir, func(p *pod) {
gp := p.path()
st := &syscall.Stat_t{}
if err := syscall.Lstat(gp, st); err != nil {
if err != syscall.ENOENT {
stderr("Unable to stat %q, ignoring: %v", gp, err)
}
return
}
if expiration := time.Unix(st.Ctim.Unix()).Add(gracePeriod); time.Now().After(expiration) {
if err := p.ExclusiveLock(); err != nil {
return
}
stdout("Garbage collecting pod %q", p.uuid)
s, err := store.NewStore(globalFlags.Dir)
if err != nil {
stderr("Cannot open store: %v", err)
return
}
stage1ID, err := p.getStage1Hash()
if err != nil {
stderr("Error getting stage1 hash")
return
}
stage1RootFS := s.GetTreeStoreRootFS(stage1ID.String())
// execute stage1's GC
if err := stage0.GC(p.path(), p.uuid, stage1RootFS, globalFlags.Debug); err != nil {
stderr("Stage1 GC of pod %q failed: %v", p.uuid, err)
return
}
if err := os.RemoveAll(gp); err != nil {
stderr("Unable to remove pod %q: %v", p.uuid, err)
}
}
}); err != nil {
return err
}
return nil
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:46,代码来源:gc.go
示例18: runGcImage
func runGcImage(cmd *cobra.Command, args []string) (exit int) {
s, err := store.NewStore(getDataDir())
if err != nil {
stderr("rkt: cannot open store: %v", err)
return 1
}
if err := gcTreeStore(s); err != nil {
stderr("rkt: failed to remove unreferenced treestores: %v", err)
return 1
}
if err := gcStore(s, flagImageGracePeriod); err != nil {
stderr("rkt: %v", err)
return 1
}
return 0
}
开发者ID:matomesc,项目名称:rkt,代码行数:19,代码来源:image_gc.go
示例19: runRmImage
func runRmImage(cmd *cobra.Command, args []string) (exit int) {
if len(args) < 1 {
stderr.Print("must provide at least one image ID")
return 1
}
s, err := store.NewStore(getDataDir())
if err != nil {
stderr.PrintE("cannot open store", err)
return 1
}
if err := rmImages(s, args); err != nil {
stderr.Error(err)
return 1
}
return 0
}
开发者ID:hwinkel,项目名称:rkt,代码行数:19,代码来源:image_rm.go
示例20: runGCImage
func runGCImage(cmd *cobra.Command, args []string) (exit int) {
s, err := store.NewStore(getDataDir())
if err != nil {
stderr.PrintE("cannot open store", err)
return 1
}
if err := gcTreeStore(s); err != nil {
stderr.PrintE("failed to remove unreferenced treestores", err)
return 1
}
if err := gcStore(s, flagImageGracePeriod); err != nil {
stderr.Error(err)
return 1
}
return 0
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:19,代码来源:image_gc.go
注:本文中的github.com/coreos/rkt/store.NewStore函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论