当前位置: 首页>>代码示例>>Golang>>正文


Golang types.NewHash函数代码示例

本文整理汇总了Golang中github.com/appc/spec/schema/types.NewHash函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHash函数的具体用法?Golang NewHash怎么用?Golang NewHash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewHash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: FindImage

// FindImage tries to get a hash of a passed image, ideally from
// store. Otherwise this might involve fetching it from remote with
// the Fetcher.
func (f *Finder) FindImage(img string, asc string) (*types.Hash, error) {
	ensureLogger(f.Debug)

	// Check if it's an hash
	if _, err := types.NewHash(img); err == nil {
		h, err := f.getHashFromStore(img)
		if err != nil {
			return nil, err
		}
		return h, nil
	}

	d, err := DistFromImageString(img)
	if err != nil {
		return nil, err
	}

	// urls, names, paths have to be fetched, potentially remotely
	ft := (*Fetcher)(f)
	h, err := ft.FetchImage(d, img, asc)
	if err != nil {
		return nil, err
	}
	return h, nil
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:28,代码来源:finder.go

示例2: getHashFromStore

func (f *Finder) getHashFromStore(img string) (*types.Hash, error) {
	h, err := types.NewHash(img)
	if err != nil {
		return nil, errwrap.Wrap(fmt.Errorf("%q is not a valid hash", img), err)
	}
	fullKey, err := f.S.ResolveKey(img)
	if err != nil {
		return nil, errwrap.Wrap(fmt.Errorf("could not resolve image %q", img), err)
	}
	h, err = types.NewHash(fullKey)
	if err != nil {
		// should never happen
		log.PanicE("got an invalid hash from the store, looks like it is corrupted", err)
	}
	return h, nil
}
开发者ID:hwinkel,项目名称:rkt,代码行数:16,代码来源:finder.go

示例3: getImage

func getImage(name string, localOnly bool) (*jetpack.Image, error) {
	if h, err := types.NewHash(name); err == nil {
		if len(name) < hashSize {
			// Short hash. Iterate over images, return first prefix match.
			// FIXME: what about multiple matches?
			name = strings.ToLower(name)
			if imgs, err := Host.Images(); err != nil {
				return nil, errors.Trace(err)
			} else {
				for _, img := range imgs {
					if strings.HasPrefix(img.Hash.String(), name) {
						return img, nil
					}
				}
				return nil, jetpack.ErrNotFound
			}
		}
		return Host.GetImage(*h, "", nil)
	}
	if name, labels, err := parseImageName(name); err != nil {
		return nil, errors.Trace(err)
	} else if localOnly {
		return Host.GetLocalImage(types.Hash{}, name, labels)
	} else {
		return Host.GetImage(types.Hash{}, name, labels)
	}
}
开发者ID:sdoumbouya,项目名称:jetpack,代码行数:27,代码来源:command.go

示例4: parseApp

func parseApp(args []string) ([]string, *schema.RuntimeApp, error) {
	if len(args) == 0 {
		return nil, nil, nil
	}

	rtapp := schema.RuntimeApp{}

	// Parse first argument (image name)
	if h, err := types.NewHash(args[0]); err == nil {
		rtapp.Image.ID = *h
		rtapp.Name.Set(h.String()) // won't err
	} else if dapp, err := discovery.NewAppFromString(args[0]); err == nil {
		rtapp.Image.Name = &dapp.Name
		rtapp.Name.Set(path.Base(dapp.Name.String())) // won't err here
		if ll, err := types.LabelsFromMap(dapp.Labels); err != nil {
			return args, nil, err
		} else {
			rtapp.Image.Labels = ll
		}
	} else {
		return args, nil, err
	}

	fl := flag.NewFlagSet(args[0], flag.ExitOnError)
	fl.Var(&rtapp.Name, "name", "App name")
	fl.Var((*AnnotationsFlag)(&rtapp.Annotations), "a", "Add annotation (NAME=VALUE)")
	fl.Var((*MountsFlag)(&rtapp.Mounts), "m", "Mount volume (VOLUME[:MOUNTPOINT])")
	// TODO: app override
	fl.Parse(args[1:])
	return fl.Args(), &rtapp, nil
}
开发者ID:sdoumbouya,项目名称:jetpack,代码行数:31,代码来源:flags.go

示例5: ExtractLayerInfo

// ExtractLayerInfo extracts the image name and ID from a path to an ACI
func ExtractLayerInfo(store *store.Store, in string) (types.Dependency, error) {
	im, err := GetManifestFromImage(in)
	if err != nil {
		return types.Dependency{}, fmt.Errorf("error getting manifest from image (%v): %v", in, err)
	}

	inFile, err := os.Open(in)
	if err != nil {
		return types.Dependency{}, fmt.Errorf("error opening ACI: %v", err)
	}
	defer inFile.Close()

	inImageID, err := store.WriteACI(inFile, false)
	if err != nil {
		return types.Dependency{}, fmt.Errorf("error writing ACI into the tree store: %v", err)
	}

	hash, err := types.NewHash(inImageID)
	if err != nil {
		return types.Dependency{}, fmt.Errorf("error creating hash from an image ID (%s): %v", hash, err)
	}

	return types.Dependency{
		ImageName: im.Name,
		ImageID:   hash,
	}, nil
}
开发者ID:klizhentas,项目名称:acbuild,代码行数:28,代码来源:util.go

示例6: makePod

//rktDirectory string, ociConfig string, ociRuntimeConfig string, ociDirectory string
func (this *oci2rkt) makePod() (err error) {

	//1.covert to pod
	this.podManifest.ACVersion = types.SemVer{
		Major:      0,
		Minor:      8,
		Patch:      0,
		PreRelease: "",
		Metadata:   "",
	}

	this.podManifest.ACKind = "PodManifest"

	/*
		this.podManifest.Apps = schema.AppList{
			{
				Name: "oci",
				Image: schema.RuntimeImage{
					ID: types.Hash{
						Val: "",
					},
				},
			},
		}
	*/

	runTimeImage := schema.RuntimeImage{}
	hash, err := types.NewHash("sha512-ca0bee4ecb888d10cf0816ebe7e16499230ab349bd3126976ab60b9b1db2e120")
	if err != nil {
		return err
	}
	runTimeImage.ID = *hash
	runTimeApp := schema.RuntimeApp{
		Name: "oci",
	}
	runTimeApp.Image = runTimeImage

	this.podManifest.Apps = append(this.podManifest.Apps, runTimeApp)

	this.podManifest.Volumes = nil
	this.podManifest.Isolators = nil
	this.podManifest.Annotations = nil
	this.podManifest.Ports = nil

	//2.marshal
	podBuf, err := json.Marshal(this.podManifest)
	if err != nil {
		return err
	}

	//3.wirte pod file
	pod := this.RktBundlePath + "/pod"

	err = ioutil.WriteFile(pod, podBuf, 0755)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:sdgdsffdsfff,项目名称:rkt,代码行数:61,代码来源:oci2rkt.go

示例7: mustRktHash

func mustRktHash(hash string) *appctypes.Hash {
	h, err := appctypes.NewHash(hash)
	if err != nil {
		panic(err)
	}
	return h
}
开发者ID:vurt,项目名称:kubernetes,代码行数:7,代码来源:rkt_test.go

示例8: FetchImage

// FetchImage will take an image as either a path, a URL or a name
// string and import it into the store if found. If ascPath is not "",
// it must exist as a local file and will be used as the signature
// file for verification, unless verification is disabled. If
// f.WithDeps is true also image dependencies are fetched.
func (f *Fetcher) FetchImage(d dist.Distribution, image, ascPath string) (*types.Hash, error) {
	ensureLogger(f.Debug)
	db := &distBundle{
		dist:  d,
		image: image,
	}
	a := f.getAsc(ascPath)
	hash, err := f.fetchSingleImage(db, a)
	if err != nil {
		return nil, err
	}
	if f.WithDeps {
		err = f.fetchImageDeps(hash)
		if err != nil {
			return nil, err
		}
	}

	// we need to be able to do a chroot and access to the tree store
	// directories, we need to
	// 1) check if the system supports OverlayFS
	// 2) check if we're root
	if common.SupportsOverlay() == nil && os.Geteuid() == 0 {
		if _, _, err := f.Ts.Render(hash, false); err != nil {
			return nil, errwrap.Wrap(errors.New("error rendering tree store"), err)
		}
	}
	h, err := types.NewHash(hash)
	if err != nil {
		// should never happen
		log.PanicE("invalid hash", err)
	}
	return h, nil
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:39,代码来源:fetcher.go

示例9: processAci

func (p *Pod) processAci(e common.RuntimeApp) (*schema.RuntimeApp, error) {
	aci, err := p.buildAci(e)
	if err != nil {
		return nil, err
	}

	name, err := types.NewACName(e.Name)
	if err != nil {
		return nil, errs.WithEF(err, p.fields.WithField("name", e.Name), "Invalid name format")
	}

	sum, err := Sha512sum(aci.target + pathImageAci)
	if err != nil {
		return nil, errs.WithEF(err, p.fields.WithField("file", aci.target+pathImageAci), "Failed to calculate sha512 of aci")
	}

	tmp, _ := types.NewHash("sha512-" + sum)

	labels := types.Labels{}
	labels = append(labels, types.Label{Name: "version", Value: aci.manifest.NameAndVersion.Version()})
	identifier, _ := types.NewACIdentifier(aci.manifest.NameAndVersion.Name())
	ttmp := schema.RuntimeImage{Name: identifier, ID: *tmp, Labels: labels}

	e.App.Group = aci.manifest.Aci.App.Group
	e.App.User = aci.manifest.Aci.App.User
	if e.App.User == "" {
		e.App.User = "0"
	}
	if e.App.Group == "" {
		e.App.Group = "0"
	}

	isolators, err := common.ToAppcIsolators(e.App.Isolators)
	if err != nil {
		return nil, errs.WithEF(err, p.fields, "Failed to prepare isolators")
	}

	return &schema.RuntimeApp{
		Name:  *name,
		Image: ttmp,
		App: &types.App{
			Exec:              e.App.Exec,
			User:              e.App.User,
			Group:             e.App.Group,
			WorkingDirectory:  e.App.WorkingDirectory,
			SupplementaryGIDs: e.App.SupplementaryGIDs,
			Environment:       e.App.Environment,
			MountPoints:       e.App.MountPoints,
			Ports:             e.App.Ports,
			Isolators:         isolators,
		},
		Mounts:      e.Mounts,
		Annotations: e.Annotations}, nil
}
开发者ID:nyodas,项目名称:cnt,代码行数:54,代码来源:pod-build.go

示例10: guessImageType

func guessImageType(image string) apps.AppImageType {
	if _, err := types.NewHash(image); err == nil {
		return apps.AppImageHash
	}
	if u, err := url.Parse(image); err == nil && u.Scheme != "" {
		return apps.AppImageURL
	}
	if filepath.IsAbs(image) {
		return apps.AppImagePath
	}

	// Well, at this point is basically heuristics time. The image
	// parameter can be either a relative path or an image name.

	// First, let's try to stat whatever file the URL would specify. If it
	// exists, that's probably what the user wanted.
	f, err := os.Stat(image)
	if err == nil && f.Mode().IsRegular() {
		return apps.AppImagePath
	}

	// Second, let's check if there is a colon in the image
	// parameter. Colon often serves as a paths separator (like in
	// the PATH environment variable), so if it exists, then it is
	// highly unlikely that the image parameter is a path. Colon
	// in this context is often used for specifying a version of
	// an image, like in "example.com/reduce-worker:1.0.0".
	if strings.ContainsRune(image, ':') {
		return apps.AppImageName
	}

	// Third, let's check if there is a dot followed by a slash
	// (./) - if so, it is likely that the image parameter is path
	// like ./aci-in-this-dir or ../aci-in-parent-dir
	if strings.Contains(image, "./") {
		return apps.AppImagePath
	}

	// Fourth, let's check if the image parameter has an .aci
	// extension. If so, likely a path like "stage1-coreos.aci".
	if filepath.Ext(image) == schema.ACIExtension {
		return apps.AppImagePath
	}

	// At this point, if the image parameter is something like
	// "coreos.com/rkt/stage1-coreos" and you have a directory
	// tree "coreos.com/rkt" in the current working directory and
	// you meant the image parameter to point to the file
	// "stage1-coreos" in this directory tree, then you better be
	// off prepending the parameter with "./", because I'm gonna
	// treat this as an image name otherwise.
	return apps.AppImageName
}
开发者ID:nhlfr,项目名称:rkt,代码行数:53,代码来源:common.go

示例11: runAddDep

func runAddDep(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("dependency add: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Adding dependency %q", args[0])
	}

	app, err := discovery.NewAppFromString(args[0])
	if err != nil {
		stderr("dependency add: couldn't parse dependency name: %v", err)
		return 1
	}

	appcLabels := types.Labels(labels)

	for name, value := range app.Labels {
		if _, ok := appcLabels.Get(string(name)); ok {
			stderr("multiple %s labels specified", name)
			return 1
		}
		appcLabels = append(appcLabels, types.Label{
			Name:  name,
			Value: value,
		})
	}

	var hash *types.Hash
	if imageId != "" {
		var err error
		hash, err = types.NewHash(imageId)
		if err != nil {
			stderr("dependency add: couldn't parse image ID: %v", err)
			return 1
		}
	}

	err = newACBuild().AddDependency(app.Name, hash, appcLabels, size)

	if err != nil {
		stderr("dependency add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
开发者ID:joshix,项目名称:acbuild,代码行数:52,代码来源:dependency.go

示例12: processAci

func (p *Pod) processAci() []schema.RuntimeApp {
	apps := []schema.RuntimeApp{}
	for _, e := range p.manifest.Pod.Apps {

		aciName := p.buildAciIfNeeded(e)
		// TODO: support not FS override by only storing info pod manifest
		//		if aciName == nil {
		//			aciName = &e.Image
		//		}

		name, _ := types.NewACName(e.Name)

		sum, err := utils.Sha512sum(p.path + "/" + e.Name + "/target/image.aci")
		if err != nil {
			log.Get().Panic(err)
		}

		tmp, _ := types.NewHash("sha512-" + sum)

		labels := types.Labels{}
		labels = append(labels, types.Label{Name: "version", Value: aciName.Version()})
		identifier, _ := types.NewACIdentifier(aciName.Name())
		ttmp := schema.RuntimeImage{Name: identifier, ID: *tmp, Labels: labels}

		if e.App.User == "" {
			e.App.User = "0"
		}
		if e.App.Group == "" {
			e.App.Group = "0"
		}

		apps = append(apps, schema.RuntimeApp{
			Name:  *name,
			Image: ttmp,
			App: &types.App{
				Exec:             e.App.Exec,
				EventHandlers:    e.App.EventHandlers,
				User:             e.App.User,
				Group:            e.App.Group,
				WorkingDirectory: e.App.WorkingDirectory,
				Environment:      e.App.Environment,
				MountPoints:      e.App.MountPoints,
				Ports:            e.App.Ports,
				Isolators:        e.App.Isolators,
			},
			Mounts:      e.Mounts,
			Annotations: e.Annotations})

	}

	return apps
}
开发者ID:PrFalken,项目名称:cnt,代码行数:52,代码来源:pod-build.go

示例13: TestDockerVolumeSemanticsPodManifest

func TestDockerVolumeSemanticsPodManifest(t *testing.T) {
	ctx := testutils.NewRktRunCtx()
	defer ctx.Cleanup()

	for i, tt := range volDockerTests {
		t.Logf("Running test #%v on directory %s", i, tt.dir)

		hash, err := patchImportAndFetchHash(fmt.Sprintf("rkt-volume-image-pm-%d.aci", i), []string{fmt.Sprintf("--mounts=mydir,path=%s,readOnly=false", tt.dir)}, t, ctx)
		if err != nil {
			t.Fatalf("%v", err)
		}

		imgID, err := types.NewHash(hash)
		if err != nil {
			t.Fatalf("Cannot generate types.Hash from %v: %v", hash, err)
		}

		pm := &schema.PodManifest{
			ACKind:    schema.PodManifestKind,
			ACVersion: schema.AppContainerVersion,
			Apps: []schema.RuntimeApp{
				{
					Name: "rkt-volume-image",
					App: &types.App{
						Exec:  []string{"/inspect", "--read-file"},
						User:  "0",
						Group: "0",
						Environment: []types.EnvironmentVariable{
							{"FILE", fmt.Sprintf("%s/file", tt.dir)},
						},
						MountPoints: []types.MountPoint{
							{"mydir", tt.dir, false},
						},
					},
					Image: schema.RuntimeImage{
						ID: *imgID,
					},
				},
			},
		}

		manifestFile := generatePodManifestFile(t, pm)
		defer os.Remove(manifestFile)

		cmd := fmt.Sprintf("%s --debug --insecure-options=image run --pod-manifest=%s", ctx.Cmd(), manifestFile)

		expected := fmt.Sprintf("<<<%s>>>", tt.expectedContent)

		runRktAndCheckOutput(t, cmd, expected, false)
	}
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:51,代码来源:rkt_volume_test.go

示例14: newAppcRuntimeApp

func (r *Runtime) newAppcRuntimeApp(pod *api.Pod, c api.Container, pullSecrets []api.Secret) (*appcschema.RuntimeApp, []kubecontainer.PortMapping, error) {
	if err, _ := r.imagePuller.PullImage(pod, &c, pullSecrets); err != nil {
		return nil, nil, err
	}
	imgManifest, err := r.getImageManifest(c.Image)
	if err != nil {
		return nil, nil, err
	}

	if imgManifest.App == nil {
		imgManifest.App = new(appctypes.App)
	}

	imageID, err := r.getImageID(c.Image)
	if err != nil {
		return nil, nil, err
	}
	hash, err := appctypes.NewHash(imageID)
	if err != nil {
		return nil, nil, err
	}

	opts, err := r.generator.GenerateRunContainerOptions(pod, &c)
	if err != nil {
		return nil, nil, err
	}

	if err := setApp(imgManifest.App, &c, opts); err != nil {
		return nil, nil, err
	}

	name, err := appctypes.SanitizeACName(c.Name)
	if err != nil {
		return nil, nil, err
	}
	appName := appctypes.MustACName(name)

	kubehash := kubecontainer.HashContainer(&c)

	return &appcschema.RuntimeApp{
		Name:  *appName,
		Image: appcschema.RuntimeImage{ID: *hash},
		App:   imgManifest.App,
		Annotations: []appctypes.Annotation{
			{
				Name:  *appctypes.MustACIdentifier(k8sRktContainerHashAnno),
				Value: strconv.FormatUint(kubehash, 10),
			},
		},
	}, opts.PortMappings, nil
}
开发者ID:timcrider,项目名称:kubernetes,代码行数:51,代码来源:rkt.go

示例15: getStoreKeyFromAppOrHash

func getStoreKeyFromAppOrHash(s *imagestore.Store, input string) (string, error) {
	var key string
	if _, err := types.NewHash(input); err == nil {
		key, err = s.ResolveKey(input)
		if err != nil {
			return "", errwrap.Wrap(errors.New("cannot resolve image ID"), err)
		}
	} else {
		key, err = getStoreKeyFromApp(s, input)
		if err != nil {
			return "", errwrap.Wrap(errors.New("cannot find image"), err)
		}
	}
	return key, nil
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:15,代码来源:image_cmd_common.go


注:本文中的github.com/appc/spec/schema/types.NewHash函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。