本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.ShortHash函数的典型用法代码示例。如果您正苦于以下问题:Golang ShortHash函数的具体用法?Golang ShortHash怎么用?Golang ShortHash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ShortHash函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getAppImageID
// getAppImageID returns the image id to enter
// If one was supplied in the flags then it's simply returned
// If the PM contains a single image, that image's id is returned
// If the PM has multiple images, the ids and names are printed and an error is returned
func getAppImageID(p *pod) (*types.Hash, error) {
if !flagAppImageID.Empty() {
return &flagAppImageID, nil
}
// figure out the image id, or show a list if multiple are present
b, err := ioutil.ReadFile(common.PodManifestPath(p.path()))
if err != nil {
return nil, fmt.Errorf("error reading pod manifest: %v", err)
}
m := schema.PodManifest{}
if err = m.UnmarshalJSON(b); err != nil {
return nil, fmt.Errorf("unable to load manifest: %v", err)
}
switch len(m.Apps) {
case 0:
return nil, fmt.Errorf("pod contains zero apps")
case 1:
return &m.Apps[0].Image.ID, nil
default:
}
stderr("Pod contains multiple apps:")
for _, ra := range m.Apps {
stderr("\t%s: %s", types.ShortHash(ra.Image.ID.String()), ra.Name.String())
}
return nil, fmt.Errorf("specify app using \"rkt enter --imageid ...\"")
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:35,代码来源:enter.go
示例2: 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(getDataDir())
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 := &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(hash)
return nil
})
if err != nil {
stderr("%v", err)
return 1
}
return
}
开发者ID:mischief,项目名称:rkt,代码行数:59,代码来源:fetch.go
示例3: 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
示例4: 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
示例5: TestResumedFetch
func TestResumedFetch(t *testing.T) {
image := "rkt-inspect-implicit-fetch.aci"
imagePath := patchTestACI(image, "--exec=/inspect")
hash := types.ShortHash("sha512-" + getHashOrPanic(imagePath))
defer os.Remove(imagePath)
kill := make(chan struct{})
reportkill := make(chan struct{})
shouldInterrupt := &synchronizedBool{}
shouldInterrupt.Write(true)
server := httptest.NewServer(testServerHandler(t, shouldInterrupt, imagePath, kill, reportkill))
defer server.Close()
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
cmd := fmt.Sprintf("%s --no-store --insecure-skip-verify fetch %s", ctx.Cmd(), server.URL)
child := spawnOrFail(t, cmd)
<-kill
err := child.Close()
if err != nil {
panic(err)
}
reportkill <- struct{}{}
// rkt has fetched the first half of the image
// If it fetches the first half again these channels will be written to.
// Closing them to make the test panic if they're written to.
close(kill)
close(reportkill)
child = spawnOrFail(t, cmd)
if _, _, err := expectRegexWithOutput(child, ".*"+hash); err != nil {
t.Fatalf("hash didn't match: %v", err)
}
err = child.Wait()
if err != nil {
t.Errorf("rkt didn't exit cleanly: %v", err)
}
}
开发者ID:aaronlevy,项目名称:rkt,代码行数:44,代码来源:rkt_fetch_test.go
示例6: TestResumedFetchInvalidCache
func TestResumedFetchInvalidCache(t *testing.T) {
image := "rkt-inspect-implicit-fetch.aci"
imagePath := patchTestACI(image, "--exec=/inspect")
defer os.Remove(imagePath)
hash := types.ShortHash("sha512-" + getHashOrPanic(imagePath))
kill := make(chan struct{})
reportkill := make(chan struct{})
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
shouldInterrupt := &synchronizedBool{}
shouldInterrupt.Write(true)
// Fetch the first half of the image, and kill rkt once it reaches halfway.
server := httptest.NewServer(testServerHandler(t, shouldInterrupt, imagePath, kill, reportkill))
defer server.Close()
cmd := fmt.Sprintf("%s --no-store --insecure-skip-verify fetch %s", ctx.Cmd(), server.URL)
child := spawnOrFail(t, cmd)
<-kill
err := child.Close()
if err != nil {
panic(err)
}
reportkill <- struct{}{}
// Fetch the image again. The server doesn't support Etags or the
// Last-Modified header, so the cached version should be invalidated. If
// rkt tries to use the cache, the hash won't check out.
shouldInterrupt.Write(false)
child = spawnOrFail(t, cmd)
if _, s, err := expectRegexWithOutput(child, ".*"+hash); err != nil {
t.Fatalf("hash didn't match: %v\nin: %s", err, s)
}
err = child.Wait()
if err != nil {
t.Errorf("rkt didn't exit cleanly: %v", err)
}
}
开发者ID:aaronlevy,项目名称:rkt,代码行数:41,代码来源:rkt_fetch_test.go
示例7: Enter
// Enter enters the pod/app by exec()ing the stage1's /enter similar to /init
// /enter can expect to have its CWD set to the app root.
// imageID and command are supplied to /enter on argv followed by any arguments.
// stage1Path is the path of the stage1 rootfs
func Enter(cdir string, podPID int, imageID *types.Hash, stage1Path string, cmdline []string) error {
if err := os.Chdir(cdir); err != nil {
return fmt.Errorf("error changing to dir: %v", err)
}
id := types.ShortHash(imageID.String())
ep, err := getStage1Entrypoint(cdir, enterEntrypoint)
if err != nil {
return fmt.Errorf("error determining entrypoint: %v", err)
}
argv := []string{filepath.Join(stage1Path, ep)}
argv = append(argv, strconv.Itoa(podPID))
argv = append(argv, id)
argv = append(argv, cmdline...)
if err := syscall.Exec(argv[0], argv, os.Environ()); err != nil {
return fmt.Errorf("error execing enter: %v", err)
}
// never reached
return nil
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:27,代码来源:enter.go
示例8: RelAppImagePath
// RelAppImagePath returns the path of an application image relative to the
// stage1 chroot
func RelAppImagePath(imageID types.Hash) string {
return filepath.Join(stage2Dir, types.ShortHash(imageID.String()))
}
开发者ID:fdserr,项目名称:rkt,代码行数:5,代码来源:common.go
示例9: AppImagePath
// AppImagePath returns the path where an app image (i.e. unpacked ACI) is rooted (i.e.
// where its contents are extracted during stage0), based on the app image ID.
func AppImagePath(root string, imageID types.Hash) string {
return filepath.Join(AppImagesPath(root), types.ShortHash(imageID.String()))
}
开发者ID:fdserr,项目名称:rkt,代码行数:5,代码来源:common.go
示例10: CreateCgroups
// CreateCgroups mounts the cgroup controllers hierarchy for the container but
// leaves the subcgroup for each app read-write so the systemd inside stage1
// can apply isolators to them
func CreateCgroups(root string, subcgroup string, appHashes []types.Hash) error {
cgroupsFile, err := os.Open("/proc/cgroups")
if err != nil {
return err
}
defer cgroupsFile.Close()
cgroups, err := parseCgroups(cgroupsFile)
if err != nil {
return fmt.Errorf("error parsing /proc/cgroups: %v", err)
}
controllers := getControllers(cgroups)
var flags uintptr
// 1. Mount /sys read-only
sys := filepath.Join(root, "/sys")
if err := os.MkdirAll(sys, 0700); err != nil {
return err
}
flags = syscall.MS_RDONLY |
syscall.MS_NOSUID |
syscall.MS_NOEXEC |
syscall.MS_NODEV
if err := syscall.Mount("sysfs", sys, "sysfs", flags, ""); err != nil {
return fmt.Errorf("error mounting %q: %v", sys, err)
}
// 2. Mount /sys/fs/cgroup
cgroupTmpfs := filepath.Join(root, "/sys/fs/cgroup")
if err := os.MkdirAll(cgroupTmpfs, 0700); err != nil {
return err
}
flags = syscall.MS_NOSUID |
syscall.MS_NOEXEC |
syscall.MS_NODEV |
syscall.MS_STRICTATIME
if err := syscall.Mount("tmpfs", cgroupTmpfs, "tmpfs", flags, "mode=755"); err != nil {
return fmt.Errorf("error mounting %q: %v", cgroupTmpfs, err)
}
// 3. Mount controllers
for _, c := range controllers {
// 3a. Mount controller
cPath := filepath.Join(root, "/sys/fs/cgroup", c)
if err := os.MkdirAll(cPath, 0700); err != nil {
return err
}
flags = syscall.MS_NOSUID |
syscall.MS_NOEXEC |
syscall.MS_NODEV
if err := syscall.Mount("cgroup", cPath, "cgroup", flags, c); err != nil {
return fmt.Errorf("error mounting %q: %v", cPath, err)
}
// 3b. Check if we're running from a unit to know which subcgroup
// directories to mount read-write
subcgroupPath := filepath.Join(cPath, subcgroup)
// 3c. Create cgroup directories and mount the files we need over
// themselves so they stay read-write
for _, a := range appHashes {
serviceName := types.ShortHash(a.String()) + ".service"
appCgroup := filepath.Join(subcgroupPath, serviceName)
if err := os.MkdirAll(appCgroup, 0755); err != nil {
return err
}
for _, f := range getControllerRWFiles(c) {
cgroupFilePath := filepath.Join(appCgroup, f)
// the file may not be there if kernel doesn't support the
// feature, skip it in that case
if _, err := os.Stat(cgroupFilePath); os.IsNotExist(err) {
continue
}
if err := syscall.Mount(cgroupFilePath, cgroupFilePath, "", syscall.MS_BIND, ""); err != nil {
return fmt.Errorf("error bind mounting %q: %v", cgroupFilePath, err)
}
}
}
// 3d. Re-mount controller read-only to prevent the container modifying host controllers
flags = syscall.MS_BIND |
syscall.MS_REMOUNT |
syscall.MS_NOSUID |
syscall.MS_NOEXEC |
syscall.MS_NODEV |
syscall.MS_RDONLY
if err := syscall.Mount(cPath, cPath, "", flags, ""); err != nil {
return fmt.Errorf("error remounting RO %q: %v", cPath, err)
}
}
// 4. Create symlinks for combined controllers
//.........这里部分代码省略.........
开发者ID:danieltaborda,项目名称:rkt,代码行数:101,代码来源:cgroup.go
示例11: RelEnvFilePath
// RelEnvFilePath returns the path to the environment file for the given imageID
// relative to the pod's root
func RelEnvFilePath(imageID types.Hash) string {
return filepath.Join(envDir, types.ShortHash(imageID.String()))
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:5,代码来源:path.go
示例12: ServiceUnitName
// ServiceUnitName returns a systemd service unit name for the given imageID
func ServiceUnitName(imageID types.Hash) string {
return types.ShortHash(imageID.String()) + ".service"
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:4,代码来源:path.go
注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.ShortHash函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论