本文整理汇总了Golang中github.com/appc/spec/schema/types.NewUUID函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUUID函数的具体用法?Golang NewUUID怎么用?Golang NewUUID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUUID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRefreshPodIsGone
func TestRefreshPodIsGone(t *testing.T) {
uuid, err := types.NewUUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")
if err != nil {
panic(err)
}
tmpDir, err := ioutil.TempDir("", "")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpDir)
podPath := filepath.Join(embryoDir(tmpDir), uuid.String())
os.MkdirAll(podPath, 0777)
p, err := getPod(tmpDir, uuid)
if err != nil {
t.Fatalf("unable to get pod: %v", err)
}
os.RemoveAll(tmpDir)
err = p.refreshState()
if err != nil {
t.Fatalf("error refreshing state: %v", err)
}
pstate := podToStates(p)
expected := states{isGone: true}
if !reflect.DeepEqual(expected, pstate) {
t.Errorf("expected %+v == %+v after refrshState", expected, pstate)
}
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:31,代码来源:pods_test.go
示例2: handlePodVerify
func handlePodVerify(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
uuid, err := types.NewUUID(r.FormValue("uuid"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "uuid field missing or malformed: %v", err)
return
}
content := r.FormValue("content")
if content == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "content field missing")
return
}
sig, err := base64.StdEncoding.DecodeString(r.FormValue("signature"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "signature field missing or corrupt: %v", err)
return
}
h := hmac.New(sha512.New, hmacKey[:])
h.Write((*uuid)[:])
h.Write([]byte(content))
if hmac.Equal(sig, h.Sum(nil)) {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusForbidden)
}
}
开发者ID:hwinkel,项目名称:rkt,代码行数:34,代码来源:metadata_service.go
示例3: main
func main() {
flag.Parse()
log, diag, _ = rktlog.NewLogSet("stage1 gc", debug)
if !debug {
diag.SetOutput(ioutil.Discard)
}
podID, err := types.NewUUID(flag.Arg(0))
if err != nil {
log.Fatal("UUID is missing or malformed")
}
diag.Printf("Removing journal link.")
if err := removeJournalLink(podID); err != nil {
log.PrintE("error removing journal link", err)
}
diag.Printf("Cleaning up cgroups.")
if err := cleanupV1Cgroups(); err != nil {
log.PrintE("error cleaning up cgroups", err)
}
diag.Printf("Tearing down networks.")
if err := gcNetworking(podID); err != nil {
log.FatalE("", err)
}
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:28,代码来源:gc.go
示例4: handleRegisterPod
func handleRegisterPod(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
uuid, err := types.NewUUID(mux.Vars(r)["uuid"])
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "UUID is missing or malformed: %v", err)
return
}
token := queryValue(r.URL, "token")
if token == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, "token missing")
return
}
pm := &schema.PodManifest{}
if err := json.NewDecoder(r.Body).Decode(pm); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "JSON-decoding failed: %v", err)
return
}
pods.addPod(uuid, token, pm)
w.WriteHeader(http.StatusOK)
}
开发者ID:hwinkel,项目名称:rkt,代码行数:29,代码来源:metadata_service.go
示例5: InspectPod
func (s *v1AlphaAPIServer) InspectPod(ctx context.Context, request *v1alpha.InspectPodRequest) (*v1alpha.InspectPodResponse, error) {
uuid, err := types.NewUUID(request.Id)
if err != nil {
stderr.PrintE(fmt.Sprintf("invalid pod id %q", request.Id), err)
return nil, err
}
p, err := getPod(uuid)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to get pod %q", request.Id), err)
return nil, err
}
defer p.Close()
pod, _, err := getBasicPod(p)
if err != nil {
return nil, err
}
// Fill the extra pod info that is not available in ListPods(detail=false).
if err := fillAppInfo(s.store, p, pod); err != nil {
return nil, err
}
return &v1alpha.InspectPodResponse{Pod: pod}, nil
}
开发者ID:carriercomm,项目名称:rkt,代码行数:26,代码来源:api_service.go
示例6: handleRegisterApp
func handleRegisterApp(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
uuid, err := types.NewUUID(mux.Vars(r)["uuid"])
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "UUID is missing or malformed: %v", err)
return
}
an := mux.Vars(r)["app"]
if an == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, "app missing")
return
}
im := &schema.ImageManifest{}
if err := json.NewDecoder(r.Body).Decode(im); err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "JSON-decoding failed: %v", err)
return
}
err = pods.addApp(uuid, an, im)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "Pod with given UUID not found")
return
}
w.WriteHeader(http.StatusOK)
}
开发者ID:hwinkel,项目名称:rkt,代码行数:33,代码来源:metadata_service.go
示例7: TestImagePrepareRmIDRun
func TestImagePrepareRmIDRun(t *testing.T) {
imageFile := patchTestACI(unreferencedACI, fmt.Sprintf("--name=%s", unreferencedApp))
defer os.Remove(imageFile)
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
cmd := fmt.Sprintf("%s --insecure-options=image fetch %s", ctx.Cmd(), imageFile)
t.Logf("Fetching %s", imageFile)
spawnAndWaitOrFail(t, cmd, 0)
// at this point we know that RKT_INSPECT_IMAGE env var is not empty
referencedACI := os.Getenv("RKT_INSPECT_IMAGE")
cmds := strings.Fields(ctx.Cmd())
prepareCmd := exec.Command(cmds[0], cmds[1:]...)
prepareCmd.Args = append(prepareCmd.Args, "--insecure-options=image", "prepare", referencedACI)
output, err := prepareCmd.Output()
if err != nil {
t.Fatalf("Cannot read the output: %v", err)
}
podIDStr := strings.TrimSpace(string(output))
podID, err := types.NewUUID(podIDStr)
if err != nil {
t.Fatalf("%q is not a valid UUID: %v", podIDStr, err)
}
t.Logf("Retrieving stage1 imageID")
stage1ImageID, err := getImageID(ctx, stage1App)
if err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
t.Logf("Retrieving %s image ID", referencedApp)
referencedImageID, err := getImageID(ctx, referencedApp)
if err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
t.Logf("Retrieving %s image ID", unreferencedApp)
unreferencedImageID, err := getImageID(ctx, unreferencedApp)
if err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
t.Logf("Removing stage1 image (should work)")
removeImage(t, ctx, stage1ImageID)
t.Logf("Removing image for app %s (should work)", referencedApp)
removeImage(t, ctx, referencedImageID)
t.Logf("Removing image for app %s (should work)", unreferencedApp)
removeImage(t, ctx, unreferencedImageID)
cmd = fmt.Sprintf("%s run-prepared --mds-register=false %s", ctx.Cmd(), podID.String())
t.Logf("Running %s", referencedACI)
spawnAndWaitOrFail(t, cmd, 0)
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:57,代码来源:rkt_image_rm_test.go
示例8: readUUIDFromFile
func readUUIDFromFile(path string) (*types.UUID, error) {
uuid, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
uuid = bytes.TrimSpace(uuid)
return types.NewUUID(string(uuid))
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:9,代码来源:uuid.go
示例9: TestPodStoreAddApp
func TestPodStoreAddApp(t *testing.T) {
ps, _, _, app := setupPodStoreTest(t)
uuid2, err := types.NewUUID("fe305d54-75b4-431b-adb2-eb6b9e546013")
if err != nil {
panic("bad uuid literal")
}
im := &schema.ImageManifest{}
if err = ps.addApp(uuid2, app, im); err != errPodNotFound {
t.Errorf("addApp with unknown pod returned: %v", err)
}
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:13,代码来源:metadata_service_test.go
示例10: main
func main() {
flag.Parse()
log := rktlog.New(os.Stderr, "stage1 gc", debug)
podID, err := types.NewUUID(flag.Arg(0))
if err != nil {
log.Fatal("UUID is missing or malformed")
}
if err := gcNetworking(podID); err != nil {
log.FatalE("", err)
}
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:14,代码来源:gc.go
示例11: validatePodMetadata
func validatePodMetadata(metadataURL string, pm *schema.PodManifest) results {
r := results{}
uuid, err := metadataGet(metadataURL, "/pod/uuid")
if err != nil {
return append(r, err)
}
_, err = types.NewUUID(string(uuid))
if err != nil {
return append(r, fmt.Errorf("malformed UUID returned (%v): %v", string(uuid), err))
}
return append(r, validatePodAnnotations(metadataURL, pm)...)
}
开发者ID:dataVerve,项目名称:jetpack,代码行数:15,代码来源:validator.go
示例12: runRktAndGetUUID
func runRktAndGetUUID(t *testing.T, rktCmd string) string {
child := spawnOrFail(t, rktCmd)
defer waitOrFail(t, child, 0)
result, out, err := expectRegexWithOutput(child, "\n[0-9a-f-]{36}")
if err != nil || len(result) != 1 {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
podIDStr := strings.TrimSpace(result[0])
podID, err := types.NewUUID(podIDStr)
if err != nil {
t.Fatalf("%q is not a valid UUID: %v", podIDStr, err)
}
return podID.String()
}
开发者ID:coderhaoxin,项目名称:rkt,代码行数:17,代码来源:rkt_tests.go
示例13: handleUnregisterPod
func handleUnregisterPod(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
uuid, err := types.NewUUID(mux.Vars(r)["uuid"])
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "UUID is missing or malformed: %v", err)
return
}
if err := pods.remove(uuid); err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, err)
return
}
w.WriteHeader(http.StatusOK)
}
开发者ID:hwinkel,项目名称:rkt,代码行数:18,代码来源:metadata_service.go
示例14: walkPods
// walkPods iterates over the included directories calling function f for every pod found.
func walkPods(include includeMask, f func(*pod)) error {
if err := initPods(); err != nil {
return err
}
ls, err := listPods(include)
if err != nil {
return errwrap.Wrap(errors.New("failed to get pods"), err)
}
sort.Strings(ls)
for _, uuid := range ls {
u, err := types.NewUUID(uuid)
if err != nil {
stderr.PrintE(fmt.Sprintf("skipping %q", uuid), err)
continue
}
p, err := getPod(u)
if err != nil {
stderr.PrintE(fmt.Sprintf("skipping %q", uuid), err)
continue
}
// omit pods found in unrequested states
// this is to cover a race between listPods finding the uuids and pod states changing
// it's preferable to keep these operations lock-free, for example a `rkt gc` shouldn't block `rkt run`.
if p.isEmbryo && include&includeEmbryoDir == 0 ||
p.isExitedGarbage && include&includeExitedGarbageDir == 0 ||
p.isGarbage && include&includeGarbageDir == 0 ||
p.isPrepared && include&includePreparedDir == 0 ||
((p.isPreparing || p.isAbortedPrepare) && include&includePrepareDir == 0) ||
p.isRunning() && include&includeRunDir == 0 {
p.Close()
continue
}
f(p)
p.Close()
}
return nil
}
开发者ID:yanghongkjxy,项目名称:rkt,代码行数:43,代码来源:pods.go
示例15: InspectPod
func (s *v1AlphaAPIServer) InspectPod(ctx context.Context, request *v1alpha.InspectPodRequest) (*v1alpha.InspectPodResponse, error) {
uuid, err := types.NewUUID(request.Id)
if err != nil {
stderr.PrintE(fmt.Sprintf("invalid pod id %q", request.Id), err)
return nil, err
}
p, err := getPod(uuid)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to get pod %q", request.Id), err)
return nil, err
}
defer p.Close()
pod := s.getBasicPod(p)
fillPodDetails(s.store, p, pod)
return &v1alpha.InspectPodResponse{Pod: pod}, nil
}
开发者ID:yanghongkjxy,项目名称:rkt,代码行数:20,代码来源:api_service.go
示例16: main
func main() {
flag.Parse()
podID, err := types.NewUUID(flag.Arg(0))
if err != nil {
log.Fatal("UUID is missing or malformed")
}
if err := removeJournalLink(podID); err != nil {
log.PrintE("error removing journal link", err)
}
if err := cleanupV1Cgroups(); err != nil {
log.PrintE("error cleaning up cgroups", err)
}
if err := gcNetworking(podID); err != nil {
log.FatalE("", err)
}
}
开发者ID:nhlfr,项目名称:rkt,代码行数:20,代码来源:gc.go
示例17: ProcessArgsAndReturnPodUUID
func ProcessArgsAndReturnPodUUID() *types.UUID {
flag.Parse()
if cliDebugFlag {
logs.SetLevel(logs.DEBUG)
}
if lvlStr := os.Getenv(common.EnvLogLevel); lvlStr != "" {
lvl, err := logs.ParseLevel(lvlStr)
if err != nil {
fmt.Printf("Unknown log level : %s", lvlStr)
os.Exit(1)
}
logs.SetLevel(lvl)
}
arg := flag.Arg(0)
uuid, err := types.NewUUID(arg)
if err != nil {
logs.WithE(err).WithField("content", arg).Fatal("UUID is missing or malformed")
}
return uuid
}
开发者ID:blablacar,项目名称:dgr,代码行数:22,代码来源:args.go
示例18: resolveUUID
// resolveUUID attempts to resolve the uuid specified as uuid against all pods present.
// An unambiguously matched uuid or nil is returned.
func resolveUUID(dataDir, uuid string) (*types.UUID, error) {
uuid = strings.ToLower(uuid)
m, err := matchUUID(dataDir, uuid)
if err != nil {
return nil, err
}
if len(m) == 0 {
return nil, fmt.Errorf("no matches found for %q", uuid)
}
if len(m) > 1 {
return nil, fmt.Errorf("ambiguous uuid, %d matches", len(m))
}
u, err := types.NewUUID(m[0])
if err != nil {
return nil, errwrap.Wrap(errors.New("invalid UUID"), err)
}
return u, nil
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:24,代码来源:uuid.go
示例19: setupPodStoreTest
func setupPodStoreTest(t *testing.T) (*podStore, *types.UUID, string, string) {
ps := newPodStore()
uuid, err := types.NewUUID("de305d54-75b4-431b-adb2-eb6b9e546013")
if err != nil {
panic("bad uuid literal")
}
ip := "1.2.3.4"
app := "myapp"
pm := &schema.PodManifest{}
ps.addPod(uuid, ip, pm)
im := &schema.ImageManifest{}
err = ps.addApp(uuid, app, im)
if err != nil {
t.Fatalf("addApp failed with %v", err)
}
return ps, uuid, ip, app
}
开发者ID:sinfomicien,项目名称:rkt,代码行数:22,代码来源:metadata_service_test.go
示例20: NewPod
// NewPod creates a new pod directory in the "preparing" state, allocating a unique uuid for it in the process.
// The returned pod is always left in an exclusively locked state (preparing is locked in the prepared directory)
// The pod must be closed using pod.Close()
func NewPod(dataDir string) (*Pod, error) {
if err := initPods(dataDir); err != nil {
return nil, err
}
p := &Pod{
dataDir: dataDir,
createdByMe: true,
isEmbryo: true, // starts as an embryo, then ToPreparing locks, renames, and sets isPreparing
// rest start false.
}
var err error
p.UUID, err = types.NewUUID(uuid.New())
if err != nil {
return nil, errwrap.Wrap(errors.New("error creating UUID"), err)
}
err = os.Mkdir(p.embryoPath(), 0750)
if err != nil {
return nil, err
}
p.FileLock, err = lock.NewLock(p.embryoPath(), lock.Dir)
if err != nil {
os.Remove(p.embryoPath())
return nil, err
}
err = p.ToPreparing()
if err != nil {
return nil, err
}
// At this point we we have:
// /var/lib/rkt/pods/prepare/$uuid << exclusively locked to indicate "preparing"
return p, nil
}
开发者ID:joshix,项目名称:rkt,代码行数:42,代码来源:pods.go
注:本文中的github.com/appc/spec/schema/types.NewUUID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论