本文整理汇总了Golang中github.com/docker/docker/utils.GenerateRandomID函数的典型用法代码示例。如果您正苦于以下问题:Golang GenerateRandomID函数的具体用法?Golang GenerateRandomID怎么用?Golang GenerateRandomID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenerateRandomID函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestRegister
func TestRegister(t *testing.T) {
graph, _ := tempGraph(t)
defer nukeGraph(graph)
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
image := &image.Image{
ID: utils.GenerateRandomID(),
Comment: "testing",
Created: time.Now(),
}
err = graph.Register(image, nil, archive)
if err != nil {
t.Fatal(err)
}
if images, err := graph.Map(); err != nil {
t.Fatal(err)
} else if l := len(images); l != 1 {
t.Fatalf("Wrong number of images. Should be %d, not %d", 1, l)
}
if resultImg, err := graph.Get(image.ID); err != nil {
t.Fatal(err)
} else {
if resultImg.ID != image.ID {
t.Fatalf("Wrong image ID. Should be '%s', not '%s'", image.ID, resultImg.ID)
}
if resultImg.Comment != image.Comment {
t.Fatalf("Wrong image comment. Should be '%s', not '%s'", image.Comment, resultImg.Comment)
}
}
}
开发者ID:Gandi,项目名称:docker,代码行数:32,代码来源:graph_test.go
示例2: Create
func (d *Driver) Create() error {
d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, utils.GenerateRandomID())
if err := d.resolveIds(); err != nil {
return err
}
if err := d.createSSHKey(); err != nil {
return err
}
if err := d.createMachine(); err != nil {
return err
}
if err := d.waitForInstanceActive(); err != nil {
return err
}
if d.FloatingIpPool != "" {
if err := d.assignFloatingIp(); err != nil {
return err
}
}
if err := d.lookForIpAddress(); err != nil {
return err
}
if err := d.waitForSSHServer(); err != nil {
return err
}
return nil
}
开发者ID:carriercomm,项目名称:machine-server,代码行数:28,代码来源:openstack.go
示例3: Mktemp
// Mktemp creates a temporary sub-directory inside the graph's filesystem.
func (graph *Graph) Mktemp(id string) (string, error) {
dir := path.Join(graph.Root, "_tmp", utils.GenerateRandomID())
if err := os.MkdirAll(dir, 0700); err != nil {
return "", err
}
return dir, nil
}
开发者ID:BreezeWu,项目名称:docker,代码行数:8,代码来源:graph.go
示例4: commitChanges
//krgo commit -r rootfs
//commit current changes in a new properly formated branch ready for pushing
func commitChanges(rootfs, message string) error {
if !isGitRepo(rootfs) {
return fmt.Errorf("%v not a git repository", rootfs)
}
gitRepo, _ := newGitRepo(rootfs)
layerData, err := gitRepo.exportUncommitedChangeSet()
if err != nil {
return err
}
defer layerData.Close()
//Load image data
image, err := image.LoadImage(gitRepo.Path) //reading json file in rootfs
if err != nil {
return err
}
//fill new infos
image.Parent = image.ID
image.ID = utils.GenerateRandomID()
image.Created = time.Now()
image.Comment = message
layer, err := archive.NewTempArchive(layerData, "")
if err != nil {
return err
}
image.Size = layer.Size
os.RemoveAll(layer.Name())
if err := image.SaveSize(rootfs); err != nil {
return err
}
jsonRaw, err := json.Marshal(image)
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(rootfs, "json"), jsonRaw, 0600)
if err != nil {
return err
}
//commit the changes in a new branch
n, _ := gitRepo.countBranch()
br := newBranch(n, image.ID)
if _, err = gitRepo.checkoutB(br); err != nil {
return err
}
if _, err := gitRepo.addAllAndCommit(message); err != nil {
return err
}
fmt.Printf("Changes commited in %v\n", br)
fmt.Printf("Image ID: %v\nParent: %v\nChecksum: %v\nLayer size: %v\n", image.ID, image.Parent, image.Size)
return nil
}
开发者ID:HowardMei,项目名称:krgo,代码行数:62,代码来源:commit.go
示例5: BenchmarkTruncIndexNew500
func BenchmarkTruncIndexNew500(b *testing.B) {
var testSet []string
for i := 0; i < 500; i++ {
testSet = append(testSet, utils.GenerateRandomID())
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
NewTruncIndex(testSet)
}
}
开发者ID:hgschmie,项目名称:docker,代码行数:10,代码来源:truncindex_test.go
示例6: TestByParent
func TestByParent(t *testing.T) {
archive1, _ := fakeTar()
archive2, _ := fakeTar()
archive3, _ := fakeTar()
graph, _ := tempGraph(t)
defer nukeGraph(graph)
parentImage := &image.Image{
ID: utils.GenerateRandomID(),
Comment: "parent",
Created: time.Now(),
Parent: "",
}
childImage1 := &image.Image{
ID: utils.GenerateRandomID(),
Comment: "child1",
Created: time.Now(),
Parent: parentImage.ID,
}
childImage2 := &image.Image{
ID: utils.GenerateRandomID(),
Comment: "child2",
Created: time.Now(),
Parent: parentImage.ID,
}
_ = graph.Register(parentImage, nil, archive1)
_ = graph.Register(childImage1, nil, archive2)
_ = graph.Register(childImage2, nil, archive3)
byParent, err := graph.ByParent()
if err != nil {
t.Fatal(err)
}
numChildren := len(byParent[parentImage.ID])
if numChildren != 2 {
t.Fatalf("Expected 2 children, found %d", numChildren)
}
}
开发者ID:Gandi,项目名称:docker,代码行数:38,代码来源:graph_test.go
示例7: BenchmarkTruncIndexAdd500
func BenchmarkTruncIndexAdd500(b *testing.B) {
var testSet []string
for i := 0; i < 500; i++ {
testSet = append(testSet, utils.GenerateRandomID())
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
index := NewTruncIndex([]string{})
for _, id := range testSet {
if err := index.Add(id); err != nil {
b.Fatal(err)
}
}
}
}
开发者ID:hgschmie,项目名称:docker,代码行数:15,代码来源:truncindex_test.go
示例8: ContainerExecCreate
func (d *Daemon) ContainerExecCreate(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Usage: %s [options] container command [args]", job.Name)
}
if strings.HasPrefix(d.execDriver.Name(), lxc.DriverName) {
return job.Error(lxc.ErrExec)
}
var name = job.Args[0]
container, err := d.getActiveContainer(name)
if err != nil {
return job.Error(err)
}
config, err := runconfig.ExecConfigFromJob(job)
if err != nil {
return job.Error(err)
}
entrypoint, args := d.getEntrypointAndArgs(nil, config.Cmd)
processConfig := execdriver.ProcessConfig{
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
}
execConfig := &execConfig{
ID: utils.GenerateRandomID(),
OpenStdin: config.AttachStdin,
OpenStdout: config.AttachStdout,
OpenStderr: config.AttachStderr,
StreamConfig: StreamConfig{},
ProcessConfig: processConfig,
Container: container,
Running: false,
}
container.LogEvent("exec_create: " + execConfig.ProcessConfig.Entrypoint + " " + strings.Join(execConfig.ProcessConfig.Arguments, " "))
d.registerExecCommand(execConfig)
job.Printf("%s\n", execConfig.ID)
return engine.StatusOK
}
开发者ID:hgschmie,项目名称:docker,代码行数:48,代码来源:exec.go
示例9: generateIdAndName
func (daemon *Daemon) generateIdAndName(name string) (string, string, error) {
var (
err error
id = utils.GenerateRandomID()
)
if name == "" {
if name, err = daemon.generateNewName(id); err != nil {
return "", "", err
}
return id, name, nil
}
if name, err = daemon.reserveName(id, name); err != nil {
return "", "", err
}
return id, name, nil
}
开发者ID:hantuo,项目名称:docker,代码行数:19,代码来源:daemon.go
示例10: ContainerExecCreate
func (d *Daemon) ContainerExecCreate(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
return job.Errorf("Usage: %s [options] container command [args]", job.Name)
}
var name = job.Args[0]
container, err := d.getActiveContainer(name)
if err != nil {
return job.Error(err)
}
config := runconfig.ExecConfigFromJob(job)
entrypoint, args := d.getEntrypointAndArgs(nil, config.Cmd)
processConfig := execdriver.ProcessConfig{
Privileged: config.Privileged,
User: config.User,
Tty: config.Tty,
Entrypoint: entrypoint,
Arguments: args,
}
execConfig := &execConfig{
ID: utils.GenerateRandomID(),
OpenStdin: config.AttachStdin,
OpenStdout: config.AttachStdout,
OpenStderr: config.AttachStderr,
StreamConfig: StreamConfig{},
ProcessConfig: processConfig,
Container: container,
Running: false,
}
d.registerExecCommand(execConfig)
job.Printf("%s\n", execConfig.ID)
return engine.StatusOK
}
开发者ID:bbinet,项目名称:docker,代码行数:41,代码来源:exec.go
示例11: NewVolume
func (r *Repository) NewVolume(path string, writable bool) (*Volume, error) {
var (
isBindMount bool
err error
id = utils.GenerateRandomID()
)
if path != "" {
isBindMount = true
}
if path == "" {
path, err = r.createNewVolumePath(id)
if err != nil {
return nil, err
}
}
path, err = filepath.EvalSymlinks(path)
if err != nil {
return nil, err
}
v := &Volume{
ID: id,
Path: path,
repository: r,
Writable: writable,
Containers: make(map[string]struct{}),
configPath: r.configPath + "/" + id,
IsBindMount: isBindMount,
}
if err := v.initialize(); err != nil {
return nil, err
}
if err := r.Add(v); err != nil {
return nil, err
}
return v, nil
}
开发者ID:rafecolton,项目名称:docker,代码行数:40,代码来源:repository.go
示例12: newVolume
func (r *Repository) newVolume(path string, writable bool) (*Volume, error) {
var (
isBindMount bool
err error
id = utils.GenerateRandomID()
)
if path != "" {
isBindMount = true
}
if path == "" {
path, err = r.createNewVolumePath(id)
if err != nil {
return nil, err
}
}
path = filepath.Clean(path)
// Ignore the error here since the path may not exist
// Really just want to make sure the path we are using is real(or non-existant)
if cleanPath, err := filepath.EvalSymlinks(path); err == nil {
path = cleanPath
}
v := &Volume{
ID: id,
Path: path,
repository: r,
Writable: writable,
containers: make(map[string]struct{}),
configPath: r.configPath + "/" + id,
IsBindMount: isBindMount,
}
if err := v.initialize(); err != nil {
return nil, err
}
return v, r.add(v)
}
开发者ID:MjAbuz,项目名称:docker,代码行数:40,代码来源:repository.go
示例13: TestInterruptedRegister
// Test that Register can be interrupted cleanly without side effects
func TestInterruptedRegister(t *testing.T) {
graph, _ := tempGraph(t)
defer nukeGraph(graph)
badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data
image := &image.Image{
ID: utils.GenerateRandomID(),
Comment: "testing",
Created: time.Now(),
}
w.CloseWithError(errors.New("But I'm not a tarball!")) // (Nobody's perfect, darling)
graph.Register(image, nil, badArchive)
if _, err := graph.Get(image.ID); err == nil {
t.Fatal("Image should not exist after Register is interrupted")
}
// Registering the same image again should succeed if the first register was interrupted
goodArchive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
if err := graph.Register(image, nil, goodArchive); err != nil {
t.Fatal(err)
}
}
开发者ID:Gandi,项目名称:docker,代码行数:24,代码来源:graph_test.go
示例14: Create
// Create creates a new image and registers it in the graph.
func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
img := &image.Image{
ID: utils.GenerateRandomID(),
Comment: comment,
Created: time.Now().UTC(),
DockerVersion: dockerversion.VERSION,
Author: author,
Config: config,
Architecture: runtime.GOARCH,
OS: runtime.GOOS,
}
if containerID != "" {
img.Parent = containerImage
img.Container = containerID
img.ContainerConfig = *containerConfig
}
if err := graph.Register(img, nil, layerData); err != nil {
return nil, err
}
return img, nil
}
开发者ID:BreezeWu,项目名称:docker,代码行数:24,代码来源:graph.go
示例15: BenchmarkTruncIndexGet500
func BenchmarkTruncIndexGet500(b *testing.B) {
var testSet []string
var testKeys []string
for i := 0; i < 500; i++ {
testSet = append(testSet, utils.GenerateRandomID())
}
index := NewTruncIndex([]string{})
for _, id := range testSet {
if err := index.Add(id); err != nil {
b.Fatal(err)
}
l := rand.Intn(12) + 12
testKeys = append(testKeys, id[:l])
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, id := range testKeys {
if res, err := index.Get(id); err != nil {
b.Fatal(res, err)
}
}
}
}
开发者ID:hgschmie,项目名称:docker,代码行数:23,代码来源:truncindex_test.go
示例16: Checkpoint
func (container *Container) Checkpoint(stop bool) error {
log.Debugf("Checkpointing %s", container.ID)
container.Lock()
defer container.Unlock()
if !container.Running {
return fmt.Errorf("Container %s is not running.", container.ID)
}
checkpoint := &ContainerCheckpoint{
ID: utils.GenerateRandomID(),
NetworkSettings: container.NetworkSettings,
CreatedAt: time.Now().UTC(),
container: container,
}
imagePath := checkpoint.imagePath()
os.RemoveAll(imagePath)
if err := os.MkdirAll(imagePath, 0755); err != nil {
return err
}
if err := container.daemon.Checkpoint(checkpoint, stop); err != nil {
return err
}
log.Debugf("checkpoint = %s", checkpoint)
img, err := container.commitForCheckpoint(stop)
if err != nil {
return err
}
checkpoint.ImageID = img.ID
container.Checkpoints[checkpoint.ID] = checkpoint
return nil
}
开发者ID:nilekala,项目名称:docker,代码行数:36,代码来源:container.go
示例17: generateVMName
func generateVMName() string {
randomID := utils.TruncateID(utils.GenerateRandomID())
return fmt.Sprintf("docker-host-%s", randomID)
}
开发者ID:carriercomm,项目名称:machine-server,代码行数:4,代码来源:azure.go
示例18: setMachineNameIfNotSet
func (d *Driver) setMachineNameIfNotSet() {
if d.MachineName == "" {
d.MachineName = fmt.Sprintf("docker-host-%s", utils.GenerateRandomID())
}
}
开发者ID:ajoy123,项目名称:docker-machine,代码行数:5,代码来源:virtualbox.go
注:本文中的github.com/docker/docker/utils.GenerateRandomID函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论