本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.NewUUID函数的典型用法代码示例。如果您正苦于以下问题:Golang NewUUID函数的具体用法?Golang NewUUID怎么用?Golang NewUUID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewUUID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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:NeilW,项目名称:rkt,代码行数:34,代码来源:metadata_service.go
示例2: 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:NeilW,项目名称:rkt,代码行数:33,代码来源:metadata_service.go
示例3: 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:NeilW,项目名称:rkt,代码行数:29,代码来源:metadata_service.go
示例4: InspectPod
func (s *v1AlphaAPIServer) InspectPod(ctx context.Context, request *v1alpha.InspectPodRequest) (*v1alpha.InspectPodResponse, error) {
uuid, err := types.NewUUID(request.Id)
if err != nil {
log.Printf("Invalid pod id %q: %v", request.Id, err)
return nil, err
}
p, err := getPod(uuid)
if err != nil {
log.Printf("Failed to get pod %q: %v", 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().
if err := fillAppInfo(s.store, p, pod); err != nil {
return nil, err
}
return &v1alpha.InspectPodResponse{Pod: pod}, nil
}
开发者ID:krnowak,项目名称:rkt,代码行数:26,代码来源:api_service.go
示例5: 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:matomesc,项目名称:rkt,代码行数:9,代码来源:uuid.go
示例6: 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, true)
// 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, true)
}
开发者ID:Snaveena,项目名称:rkt,代码行数:57,代码来源:rkt_image_rm_test.go
示例7: 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:matomesc,项目名称:rkt,代码行数:13,代码来源:metadata_service_test.go
示例8: 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:matomesc,项目名称:rkt,代码行数:15,代码来源:validator.go
示例9: runRktAndGetUUID
func runRktAndGetUUID(t *testing.T, rktCmd string) string {
child := spawnOrFail(t, rktCmd)
defer waitOrFail(t, child, true)
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:aaronlevy,项目名称:rkt,代码行数:17,代码来源:rkt_tests.go
示例10: 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:NeilW,项目名称:rkt,代码行数:18,代码来源:metadata_service.go
示例11: main
func main() {
flag.Parse()
if !debug {
log.SetOutput(ioutil.Discard)
}
podID, err := types.NewUUID(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, "UUID is missing or malformed")
os.Exit(1)
}
if err := gcNetworking(podID); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
开发者ID:vincentvdk,项目名称:rkt,代码行数:18,代码来源:gc.go
示例12: 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 fmt.Errorf("failed to get pods: %v", err)
}
sort.Strings(ls)
for _, uuid := range ls {
u, err := types.NewUUID(uuid)
if err != nil {
stderr("Skipping %q: %v", uuid, err)
continue
}
p, err := getPod(u)
if err != nil {
stderr("Skipping %q: %v", 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:jimberlage,项目名称:rkt,代码行数:43,代码来源:pods.go
示例13: 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:matomesc,项目名称:rkt,代码行数:22,代码来源:metadata_service_test.go
示例14: resolveUUID
// resolveUUID attempts to resolve the uuid specified as uuid against all pods present.
// An unambiguously matched uuid or nil is returned.
func resolveUUID(uuid string) (*types.UUID, error) {
uuid = strings.ToLower(uuid)
m, err := matchUUID(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, fmt.Errorf("invalid UUID: %v", err)
}
return u, nil
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:24,代码来源:uuid.go
示例15: 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() (*pod, error) {
if err := initPods(); err != nil {
return nil, err
}
p := &pod{
createdByMe: true,
isEmbryo: true, // starts as an embryo, then xToPreparing locks, renames, and sets isPreparing
// rest start false.
}
var err error
p.uuid, err = types.NewUUID(uuid.New())
if err != nil {
return nil, fmt.Errorf("error creating UUID: %v", 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.xToPreparing()
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:jimberlage,项目名称:rkt,代码行数:41,代码来源:pods.go
示例16: runRktAndGetUUID
func runRktAndGetUUID(t *testing.T, rktCmd string) string {
child, err := gexpect.Spawn(rktCmd)
if err != nil {
t.Fatalf("cannot exec rkt: %v", err)
}
result, out, err := expectRegexWithOutput(child, "\n[0-9a-f-]{36}")
if err != nil || len(result) != 1 {
t.Fatalf("Error: %v\nOutput: %v", err, out)
}
if err = child.Wait(); err != nil {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
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:samarvin,项目名称:rkt,代码行数:23,代码来源:rkt_tests.go
示例17: TestPodManifest
//.........这里部分代码省略.........
},
{
// Simple read after write with read-only volume mounted, no apps in pod manifest.
// This should fail as the volume is read-only.
"rkt-test-run-pod-manifest-vol-ro-no-app.aci",
[]string{
"--exec=/inspect --write-file --read-file --file-name=/dir1/file --content=baz",
"--mounts=dir1,path=/dir1,readOnly=false",
},
&schema.PodManifest{
Apps: []schema.RuntimeApp{
{Name: baseAppName},
},
Volumes: []types.Volume{
{"dir1", "host", tmpdir, &boolTrue},
},
},
false,
`Cannot write to file "/dir1/file": open /dir1/file: read-only file system`,
},
}
for i, tt := range tests {
patchTestACI(tt.imageName, tt.imagePatches...)
hash := importImageAndFetchHash(t, ctx, tt.imageName)
defer os.Remove(tt.imageName)
tt.podManifest.ACKind = schema.PodManifestKind
tt.podManifest.ACVersion = schema.AppContainerVersion
imgName := types.MustACIdentifier(tt.imageName)
imgID, err := types.NewHash(hash)
if err != nil {
t.Fatalf("Cannot generate types.Hash from %v: %v", hash, err)
}
for i := range tt.podManifest.Apps {
ra := &tt.podManifest.Apps[i]
ra.Image.Name = imgName
ra.Image.ID = *imgID
}
manifestFile := generatePodManifestFile(t, tt.podManifest)
defer os.Remove(manifestFile)
// 1. Test 'rkt run'.
runCmd := fmt.Sprintf("%s run --pod-manifest=%s", ctx.cmd(), manifestFile)
t.Logf("Running 'run' test #%v: %v", i, runCmd)
child, err := gexpect.Spawn(runCmd)
if err != nil {
t.Fatalf("Cannot exec rkt #%v: %v", i, err)
}
if tt.expectedResult != "" {
if err := child.Expect(tt.expectedResult); err != nil {
t.Fatalf("Expected %q but not found: %v", tt.expectedResult, err)
}
}
if err := child.Wait(); err != nil {
if tt.shouldSuccess {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
verifyHostFile(t, tmpdir, "file", i, tt.expectedResult)
// 2. Test 'rkt prepare' + 'rkt run-prepared'.
cmds := strings.Fields(ctx.cmd())
prepareCmd := exec.Command(cmds[0], cmds[1:]...)
prepareArg := fmt.Sprintf("--pod-manifest=%s", manifestFile)
prepareCmd.Args = append(prepareCmd.Args, "--insecure-skip-verify", "prepare", prepareArg)
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)
}
runPreparedCmd := fmt.Sprintf("%s run-prepared %s", ctx.cmd(), podID.String())
t.Logf("Running 'run' test #%v: %v", i, runPreparedCmd)
child, err = gexpect.Spawn(runPreparedCmd)
if err != nil {
t.Fatalf("Cannot exec rkt #%v: %v", i, err)
}
if tt.expectedResult != "" {
if err := child.Expect(tt.expectedResult); err != nil {
t.Fatalf("Expected %q but not found: %v", tt.expectedResult, err)
}
}
if err := child.Wait(); err != nil {
if tt.shouldSuccess {
t.Fatalf("rkt didn't terminate correctly: %v", err)
}
}
verifyHostFile(t, tmpdir, "file", i, tt.expectedResult)
}
}
开发者ID:danieltaborda,项目名称:rkt,代码行数:101,代码来源:rkt_run_pod_manifest_test.go
示例18: stage1
func stage1() int {
uuid, err := types.NewUUID(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, "UUID is missing or malformed")
return 1
}
root := "."
p, err := LoadPod(root, uuid)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load pod: %v\n", err)
return 1
}
// set close-on-exec flag on RKT_LOCK_FD so it gets correctly closed when invoking
// network plugins
lfd, err := common.GetRktLockFD()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get rkt lock fd: %v\n", err)
return 1
}
if err := sys.CloseOnExec(lfd, true); err != nil {
fmt.Fprintf(os.Stderr, "Failed to set FD_CLOEXEC on rkt lock: %v\n", err)
return 1
}
mirrorLocalZoneInfo(p.Root)
if privNet.Any() {
fps, err := forwardedPorts(p)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return 6
}
n, err := networking.Setup(root, p.UUID, fps, privNet)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to setup network: %v\n", err)
return 6
}
if err = n.Save(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to save networking state %v\n", err)
n.Teardown()
return 6
}
if len(mdsToken) > 0 {
hostIP, err := n.GetDefaultHostIP()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get default Host IP: %v\n", err)
return 6
}
p.MetadataServiceURL = common.MetadataServicePublicURL(hostIP, mdsToken)
}
} else {
if len(mdsToken) > 0 {
p.MetadataServiceURL = common.MetadataServicePublicURL(localhostIP, mdsToken)
}
}
flavor, systemdStage1Version, err := p.getFlavor()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get stage1 flavor: %v\n", err)
return 3
}
if err = p.WritePrepareAppTemplate(systemdStage1Version); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write prepare-app service template: %v\n", err)
return 2
}
if err = p.PodToSystemd(interactive); err != nil {
fmt.Fprintf(os.Stderr, "Failed to configure systemd: %v\n", err)
return 2
}
args, env, err := getArgsEnv(p, flavor, systemdStage1Version, debug)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return 3
}
// create a separate mount namespace so the cgroup filesystems
// are unmounted when exiting the pod
if err := syscall.Unshare(syscall.CLONE_NEWNS); err != nil {
log.Fatalf("error unsharing: %v", err)
}
// we recursively make / a "shared and slave" so mount events from the
// new namespace don't propagate to the host namespace but mount events
// from the host propagate to the new namespace and are forwarded to
// its peer group
// See https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
if err := syscall.Mount("", "/", "none", syscall.MS_REC|syscall.MS_SLAVE, ""); err != nil {
log.Fatalf("error making / a slave mount: %v", err)
}
if err := syscall.Mount("", "/", "none", syscall.MS_REC|syscall.MS_SHARED, ""); err != nil {
//.........这里部分代码省略.........
开发者ID:rot26,项目名称:rkt,代码行数:101,代码来源:init.go
示例19: stage1
func stage1() int {
uuid, err := types.NewUUID(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, "UUID is missing or malformed")
return 1
}
root := "."
p, err := stage1commontypes.LoadPod(root, uuid)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load pod: %v\n", err)
return 1
}
// set close-on-exec flag on RKT_LOCK_FD so it gets correctly closed when invoking
// network plugins
lfd, err := common.GetRktLockFD()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get rkt lock fd: %v\n", err)
return 1
}
if err := sys.CloseOnExec(lfd, true); err != nil {
fmt.Fprintf(os.Stderr, "Failed to set FD_CLOEXEC on rkt lock: %v\n", err)
return 1
}
mirrorLocalZoneInfo(p.Root)
flavor, _, err := stage1initcommon.GetFlavor(p)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get stage1 flavor: %v\n", err)
return 3
}
var n *networking.Networking
if netList.Contained() {
fps, err := forwardedPorts(p)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return 6
}
n, err = networking.Setup(root, p.UUID, fps, netList, localConfig, flavor)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to setup network: %v\n", err)
return 6
}
if err = n.Save(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to save networking state %v\n", err)
n.Teardown(flavor)
return 6
}
if len(mdsToken) > 0 {
hostIP, err := n.GetDefaultHostIP()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get default Host IP: %v\n", err)
return 6
}
p.MetadataServiceURL = common.MetadataServicePublicURL(hostIP, mdsToken)
}
} else {
if flavor == "kvm" {
fmt.Fprintf(os.Stderr, "Flavor kvm requires private network configuration (try --net).\n")
return 6
}
if len(mdsToken) > 0 {
p.MetadataServiceURL = common.MetadataServicePublicURL(localhostIP, mdsToken)
}
}
if err = stage1initcommon.WriteDefaultTarget(p); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write default.target: %v\n", err)
return 2
}
if err = stage1initcommon.WritePrepareAppTemplate(p); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write prepare-app service template: %v\n", err)
return 2
}
if err := stage1initcommon.SetJournalPermissions(p); err != nil {
fmt.Fprintf(os.Stderr, "Warning: error setting journal ACLs, you'll need root to read the pod journal: %v", err)
}
if flavor == "kvm" {
if err := KvmPodToSystemd(p, n); err != nil {
fmt.Fprintf(os.Stderr, "Failed to configure systemd for kvm: %v\n", err)
return 2
}
}
if err = stage1initcommon.PodToSystemd(p, interactive, flavor, privateUsers); err != nil {
fmt.Fprintf(os.Stderr, "Failed to configure systemd: %v\n", err)
return 2
}
//.........这里部分代码省略.........
开发者ID:jshxu,项目名称:rkt,代码行数:101,代码来源:init.go
示例20: stage1
func stage1() int {
uuid, err := types.NewUUID(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, "UUID is missing or malformed")
return 1
}
root := "."
p, err := LoadPod(root, uuid)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load pod: %v\n", err)
return 1
}
// set close-on-exec flag on RKT_LOCK_FD so it gets correctly closed when invoking
// network plugins
lfd, err := common.GetRktLockFD()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get rkt lock fd: %v\n", err)
return 1
}
if err := sys.CloseOnExec(lfd, true); err != nil {
fmt.Fprintf(os.Stderr, "Failed to set FD_CLOEXEC on rkt lock: %v\n", err)
return 1
}
mirrorLocalZoneInfo(p.Root)
if privNet {
fps, err := forwardedPorts(p)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return 6
}
n, err := networking.Setup(root, p.UUID, fps)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to setup network: %v\n", err)
return 6
}
defer n.Teardown()
if err = n.Save(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to save networking state %v\n", err)
return 6
}
p.MetadataServiceURL = common.MetadataServicePublicURL(n.GetDefaultHostIP())
if err = registerPod(p, n.GetDefaultIP()); err != nil {
fmt.Fprintf(os.Stderr, "Failed to register pod: %v\n", err)
return 6
}
defer unregisterPod(p)
}
if err = p.PodToSystemd(interactive); err != nil {
fmt.Fprintf(os.Stderr, "Failed to configure systemd: %v\n", err)
return 2
}
args, env, err := getArgsEnv(p, debug)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get execution parameters: %v\n", err)
return 3
}
var execFn func() error
if privNet {
cmd := exec.Cmd{
Path: args[0],
Args: args,
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Env: env,
}
execFn = cmd.Run
} else {
execFn = func() error {
return syscall.Exec(args[0], args, env)
}
}
err = withClearedCloExec(lfd, execFn)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to execute nspawn: %v\n", err)
return 5
}
return 0
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:94,代码来源:init.go
注:本文中的github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.NewUUID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论