本文整理汇总了Golang中github.com/appc/spec/schema/types.NewUUID函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUUID函数的具体用法?Golang NewUUID怎么用?Golang NewUUID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUUID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
示例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)
}
}
示例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)
}
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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))
}
示例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)
}
}
示例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)
}
}
示例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)...)
}
示例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()
}
示例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)
}
示例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
}
示例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
}