本文整理汇总了Golang中github.com/docker/docker/engine.NewTable函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTable函数的具体用法?Golang NewTable怎么用?Golang NewTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTable函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetImagesJSONLegacyFormat
func TestGetImagesJSONLegacyFormat(t *testing.T) {
eng := engine.New()
var called bool
eng.Register("images", func(job *engine.Job) error {
called = true
outsLegacy := engine.NewTable("Created", 0)
outsLegacy.Add(createEnvFromGetImagesJSONStruct(sampleImage))
if _, err := outsLegacy.WriteListTo(job.Stdout); err != nil {
return err
}
return nil
})
r := serveRequestUsingVersion("GET", "/images/json", "1.6", nil, eng, t)
if !called {
t.Fatal("handler was not called")
}
assertHttpNotError(r, t)
assertContentType(r, "application/json", t)
images := engine.NewTable("Created", 0)
if _, err := images.ReadListFrom(r.Body.Bytes()); err != nil {
t.Fatal(err)
}
if images.Len() != 1 {
t.Fatalf("Expected 1 image, %d found", images.Len())
}
image := images.Data[0]
if image.Get("Tag") != "test-tag" {
t.Errorf("Expected tag 'test-tag', found '%s'", image.Get("Tag"))
}
if image.Get("Repository") != "test-name" {
t.Errorf("Expected repository 'test-name', found '%s'", image.Get("Repository"))
}
}
开发者ID:nicholaskh,项目名称:docker,代码行数:33,代码来源:server_unit_test.go
示例2: ContainerChanges
func (daemon *Daemon) ContainerChanges(job *engine.Job) error {
if n := len(job.Args); n != 1 {
return fmt.Errorf("Usage: %s CONTAINER", job.Name)
}
name := job.Args[0]
container, err := daemon.Get(name)
if err != nil {
return err
}
outs := engine.NewTable("", 0)
changes, err := container.Changes()
if err != nil {
return err
}
for _, change := range changes {
out := &engine.Env{}
if err := out.Import(change); err != nil {
return err
}
outs.Add(out)
}
if _, err := outs.WriteListTo(job.Stdout); err != nil {
return err
}
return nil
}
开发者ID:nicholaskh,项目名称:docker,代码行数:31,代码来源:changes.go
示例3: Search
// Search queries the public registry for images matching the specified
// search terms, and returns the results.
//
// Argument syntax: search TERM
//
// Option environment:
// 'authConfig': json-encoded credentials to authenticate against the registry.
// The search extends to images only accessible via the credentials.
//
// 'metaHeaders': extra HTTP headers to include in the request to the registry.
// The headers should be passed as a json-encoded dictionary.
//
// Output:
// Results are sent as a collection of structured messages (using engine.Table).
// Each result is sent as a separate message.
// Results are ordered by number of stars on the public registry.
func (s *Service) Search(job *engine.Job) engine.Status {
if n := len(job.Args); n != 1 {
return job.Errorf("Usage: %s TERM", job.Name)
}
var (
term = job.Args[0]
metaHeaders = map[string][]string{}
authConfig = &AuthConfig{}
)
job.GetenvJson("authConfig", authConfig)
job.GetenvJson("metaHeaders", metaHeaders)
r, err := NewRegistry(authConfig, HTTPRequestFactory(metaHeaders), IndexServerAddress(), true)
if err != nil {
return job.Error(err)
}
results, err := r.SearchRepositories(term)
if err != nil {
return job.Error(err)
}
outs := engine.NewTable("star_count", 0)
for _, result := range results.Results {
out := &engine.Env{}
out.Import(result)
outs.Add(out)
}
outs.ReverseSort()
if _, err := outs.WriteListTo(job.Stdout); err != nil {
return job.Error(err)
}
return engine.StatusOK
}
开发者ID:JacsonPaz,项目名称:docker,代码行数:48,代码来源:service.go
示例4: ContainerChanges
func (srv *Server) ContainerChanges(job *engine.Job) engine.Status {
if n := len(job.Args); n != 1 {
return job.Errorf("Usage: %s CONTAINER", job.Name)
}
name := job.Args[0]
if container := srv.daemon.Get(name); container != nil {
outs := engine.NewTable("", 0)
changes, err := container.Changes()
if err != nil {
return job.Error(err)
}
for _, change := range changes {
out := &engine.Env{}
if err := out.Import(change); err != nil {
return job.Error(err)
}
outs.Add(out)
}
if _, err := outs.WriteListTo(job.Stdout); err != nil {
return job.Error(err)
}
} else {
return job.Errorf("No such container: %s", name)
}
return engine.StatusOK
}
开发者ID:JianfuLi,项目名称:docker,代码行数:26,代码来源:container.go
示例5: CmdDiff
// CmdDiff shows changes on a container's filesystem.
//
// Each changed file is printed on a separate line, prefixed with a single character that indicates the status of the file: C (modified), A (added), or D (deleted).
//
// Usage: docker diff CONTAINER
func (cli *DockerCli) CmdDiff(args ...string) error {
cmd := cli.Subcmd("diff", "CONTAINER", "Inspect changes on a container's filesystem", true)
cmd.Require(flag.Exact, 1)
utils.ParseFlags(cmd, args, true)
body, _, err := readBody(cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil))
if err != nil {
return err
}
outs := engine.NewTable("", 0)
if _, err := outs.ReadListFrom(body); err != nil {
return err
}
for _, change := range outs.Data {
var kind string
switch change.GetInt("Kind") {
case archive.ChangeModify:
kind = "C"
case archive.ChangeAdd:
kind = "A"
case archive.ChangeDelete:
kind = "D"
}
fmt.Fprintf(cli.out, "%s %s\n", kind, change.Get("Path"))
}
return nil
}
开发者ID:nicholaskh,项目名称:docker,代码行数:35,代码来源:diff.go
示例6: TestDeleteImages
func TestDeleteImages(t *testing.T) {
eng := NewTestEngine(t)
//we expect errors, so we disable stderr
eng.Stderr = ioutil.Discard
defer mkDaemonFromEngine(eng, t).Nuke()
initialImages := getImages(eng, t, true, "")
if err := eng.Job("tag", unitTestImageName, "test", "test").Run(); err != nil {
t.Fatal(err)
}
images := getImages(eng, t, true, "")
if len(images.Data[0].GetList("RepoTags")) != len(initialImages.Data[0].GetList("RepoTags"))+1 {
t.Errorf("Expected %d images, %d found", len(initialImages.Data[0].GetList("RepoTags"))+1, len(images.Data[0].GetList("RepoTags")))
}
req, err := http.NewRequest("DELETE", "/images/"+unitTestImageID, nil)
if err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
if r.Code != http.StatusConflict {
t.Fatalf("Expected http status 409-conflict, got %v", r.Code)
}
req2, err := http.NewRequest("DELETE", "/images/test:test", nil)
if err != nil {
t.Fatal(err)
}
r2 := httptest.NewRecorder()
if err := server.ServeRequest(eng, api.APIVERSION, r2, req2); err != nil {
t.Fatal(err)
}
assertHttpNotError(r2, t)
if r2.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
outs := engine.NewTable("Created", 0)
if _, err := outs.ReadListFrom(r2.Body.Bytes()); err != nil {
t.Fatal(err)
}
if len(outs.Data) != 1 {
t.Fatalf("Expected %d event (untagged), got %d", 1, len(outs.Data))
}
images = getImages(eng, t, false, "")
if images.Len() != initialImages.Len() {
t.Errorf("Expected %d image, %d found", initialImages.Len(), images.Len())
}
}
开发者ID:BreezeWu,项目名称:docker,代码行数:58,代码来源:api_test.go
示例7: CmdSearch
// CmdSearch searches the Docker Hub for images.
//
// Usage: docker search [OPTIONS] TERM
func (cli *DockerCli) CmdSearch(args ...string) error {
cmd := cli.Subcmd("search", "TERM", "Search the Docker Hub for images", true)
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
trusted := cmd.Bool([]string{"#t", "#trusted", "#-trusted"}, false, "Only show trusted builds")
automated := cmd.Bool([]string{"-automated"}, false, "Only show automated builds")
stars := cmd.Int([]string{"s", "#stars", "-stars"}, 0, "Only displays with at least x stars")
cmd.Require(flag.Exact, 1)
utils.ParseFlags(cmd, args, true)
name := cmd.Arg(0)
v := url.Values{}
v.Set("term", name)
// Resolve the Repository name from fqn to hostname + name
taglessRemote, _ := parsers.ParseRepositoryTag(name)
repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
if err != nil {
return err
}
cli.LoadConfigFile()
body, statusCode, errReq := cli.clientRequestAttemptLogin("GET", "/images/search?"+v.Encode(), nil, nil, repoInfo.Index, "search")
rawBody, _, err := readBody(body, statusCode, errReq)
if err != nil {
return err
}
outs := engine.NewTable("star_count", 0)
if _, err := outs.ReadListFrom(rawBody); err != nil {
return err
}
w := tabwriter.NewWriter(cli.out, 10, 1, 3, ' ', 0)
fmt.Fprintf(w, "NAME\tDESCRIPTION\tSTARS\tOFFICIAL\tAUTOMATED\n")
for _, out := range outs.Data {
if ((*automated || *trusted) && (!out.GetBool("is_trusted") && !out.GetBool("is_automated"))) || (*stars > out.GetInt("star_count")) {
continue
}
desc := strings.Replace(out.Get("description"), "\n", " ", -1)
desc = strings.Replace(desc, "\r", " ", -1)
if !*noTrunc && len(desc) > 45 {
desc = utils.Trunc(desc, 42) + "..."
}
fmt.Fprintf(w, "%s\t%s\t%d\t", out.Get("name"), desc, out.GetInt("star_count"))
if out.GetBool("is_official") {
fmt.Fprint(w, "[OK]")
}
fmt.Fprint(w, "\t")
if out.GetBool("is_automated") || out.GetBool("is_trusted") {
fmt.Fprint(w, "[OK]")
}
fmt.Fprint(w, "\n")
}
w.Flush()
return nil
}
开发者ID:nicholaskh,项目名称:docker,代码行数:61,代码来源:search.go
示例8: CmdHistory
// CmdHistory shows the history of an image.
//
// Usage: docker history [OPTIONS] IMAGE
func (cli *DockerCli) CmdHistory(args ...string) error {
cmd := cli.Subcmd("history", "IMAGE", "Show the history of an image", true)
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
cmd.Require(flag.Exact, 1)
utils.ParseFlags(cmd, args, true)
body, _, err := readBody(cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil))
if err != nil {
return err
}
outs := engine.NewTable("Created", 0)
if _, err := outs.ReadListFrom(body); err != nil {
return err
}
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
if !*quiet {
fmt.Fprintln(w, "IMAGE\tCREATED\tCREATED BY\tSIZE")
}
for _, out := range outs.Data {
outID := out.Get("Id")
if !*quiet {
if *noTrunc {
fmt.Fprintf(w, "%s\t", outID)
} else {
fmt.Fprintf(w, "%s\t", stringid.TruncateID(outID))
}
fmt.Fprintf(w, "%s ago\t", units.HumanDuration(time.Now().UTC().Sub(time.Unix(out.GetInt64("Created"), 0))))
if *noTrunc {
fmt.Fprintf(w, "%s\t", out.Get("CreatedBy"))
} else {
fmt.Fprintf(w, "%s\t", utils.Trunc(out.Get("CreatedBy"), 45))
}
fmt.Fprintf(w, "%s\n", units.HumanSize(float64(out.GetInt64("Size"))))
} else {
if *noTrunc {
fmt.Fprintln(w, outID)
} else {
fmt.Fprintln(w, stringid.TruncateID(outID))
}
}
}
w.Flush()
return nil
}
开发者ID:nicholaskh,项目名称:docker,代码行数:54,代码来源:history.go
示例9: TestDeleteTagWithExistingContainers
// Regression test for being able to untag an image with an existing
// container
func TestDeleteTagWithExistingContainers(t *testing.T) {
eng := NewTestEngine(t)
defer nuke(mkDaemonFromEngine(eng, t))
srv := mkServerFromEngine(eng, t)
// Tag the image
if err := eng.Job("tag", unitTestImageID, "utest", "tag1").Run(); err != nil {
t.Fatal(err)
}
// Create a container from the image
config, _, _, err := runconfig.Parse([]string{unitTestImageID, "echo test"}, nil)
if err != nil {
t.Fatal(err)
}
id := createNamedTestContainer(eng, config, t, "testingtags")
if id == "" {
t.Fatal("No id returned")
}
job := srv.Eng.Job("containers")
job.SetenvBool("all", true)
outs, err := job.Stdout.AddListTable()
if err != nil {
t.Fatal(err)
}
if err := job.Run(); err != nil {
t.Fatal(err)
}
if len(outs.Data) != 1 {
t.Fatalf("Expected 1 container got %d", len(outs.Data))
}
// Try to remove the tag
imgs := engine.NewTable("", 0)
if err := srv.DeleteImage("utest:tag1", imgs, true, false, false); err != nil {
t.Fatal(err)
}
if len(imgs.Data) != 1 {
t.Fatalf("Should only have deleted one untag %d", len(imgs.Data))
}
if untag := imgs.Data[0].Get("Untagged"); untag != "utest:tag1" {
t.Fatalf("Expected %s got %s", unitTestImageID, untag)
}
}
开发者ID:JianfuLi,项目名称:docker,代码行数:52,代码来源:server_test.go
示例10: getImagesJSON
func getImagesJSON(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return err
}
var (
err error
outs *engine.Table
job = eng.Job("images")
)
job.Setenv("filters", r.Form.Get("filters"))
// FIXME this parameter could just be a match filter
job.Setenv("filter", r.Form.Get("filter"))
job.Setenv("all", r.Form.Get("all"))
if version.GreaterThanOrEqualTo("1.7") {
streamJSON(job, w, false)
} else if outs, err = job.Stdout.AddListTable(); err != nil {
return err
}
if err := job.Run(); err != nil {
return err
}
if version.LessThan("1.7") && outs != nil { // Convert to legacy format
outsLegacy := engine.NewTable("Created", 0)
for _, out := range outs.Data {
for _, repoTag := range out.GetList("RepoTags") {
repo, tag := parsers.ParseRepositoryTag(repoTag)
outLegacy := &engine.Env{}
outLegacy.Set("Repository", repo)
outLegacy.SetJson("Tag", tag)
outLegacy.Set("Id", out.Get("Id"))
outLegacy.SetInt64("Created", out.GetInt64("Created"))
outLegacy.SetInt64("Size", out.GetInt64("Size"))
outLegacy.SetInt64("VirtualSize", out.GetInt64("VirtualSize"))
outsLegacy.Add(outLegacy)
}
}
w.Header().Set("Content-Type", "application/json")
if _, err := outsLegacy.WriteListTo(w); err != nil {
return err
}
}
return nil
}
开发者ID:houbl,项目名称:docker,代码行数:48,代码来源:server.go
示例11: ImageDelete
func (daemon *Daemon) ImageDelete(job *engine.Job) engine.Status {
if n := len(job.Args); n != 1 {
return job.Errorf("Usage: %s IMAGE", job.Name)
}
imgs := engine.NewTable("", 0)
if err := daemon.DeleteImage(job.Eng, job.Args[0], imgs, true, job.GetenvBool("force"), job.GetenvBool("noprune")); err != nil {
return job.Error(err)
}
if len(imgs.Data) == 0 {
return job.Errorf("Conflict, %s wasn't deleted", job.Args[0])
}
if _, err := imgs.WriteListTo(job.Stdout); err != nil {
return job.Error(err)
}
return engine.StatusOK
}
开发者ID:viirya,项目名称:docker,代码行数:16,代码来源:image_delete.go
示例12: TestGetContainersJSON
func TestGetContainersJSON(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
job := eng.Job("containers")
job.SetenvBool("all", true)
outs, err := job.Stdout.AddTable()
if err != nil {
t.Fatal(err)
}
if err := job.Run(); err != nil {
t.Fatal(err)
}
beginLen := len(outs.Data)
containerID := createTestContainer(eng, &runconfig.Config{
Image: unitTestImageID,
Cmd: []string{"echo", "test"},
}, t)
if containerID == "" {
t.Fatalf("Received empty container ID")
}
req, err := http.NewRequest("GET", "/containers/json?all=1", nil)
if err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
assertHttpNotError(r, t)
containers := engine.NewTable("", 0)
if _, err := containers.ReadListFrom(r.Body.Bytes()); err != nil {
t.Fatal(err)
}
if len(containers.Data) != beginLen+1 {
t.Fatalf("Expected %d container, %d found (started with: %d)", beginLen+1, len(containers.Data), beginLen)
}
if id := containers.Data[0].Get("Id"); id != containerID {
t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", containerID, id)
}
}
开发者ID:BreezeWu,项目名称:docker,代码行数:45,代码来源:api_test.go
示例13: CmdRmi
// CmdRmi removes all images with the specified name(s).
//
// Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
func (cli *DockerCli) CmdRmi(args ...string) error {
var (
cmd = cli.Subcmd("rmi", "IMAGE [IMAGE...]", "Remove one or more images", true)
force = cmd.Bool([]string{"f", "-force"}, false, "Force removal of the image")
noprune = cmd.Bool([]string{"-no-prune"}, false, "Do not delete untagged parents")
)
cmd.Require(flag.Min, 1)
utils.ParseFlags(cmd, args, true)
v := url.Values{}
if *force {
v.Set("force", "1")
}
if *noprune {
v.Set("noprune", "1")
}
var encounteredError error
for _, name := range cmd.Args() {
body, _, err := readBody(cli.call("DELETE", "/images/"+name+"?"+v.Encode(), nil, nil))
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
encounteredError = fmt.Errorf("Error: failed to remove one or more images")
} else {
outs := engine.NewTable("Created", 0)
if _, err := outs.ReadListFrom(body); err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
encounteredError = fmt.Errorf("Error: failed to remove one or more images")
continue
}
for _, out := range outs.Data {
if out.Get("Deleted") != "" {
fmt.Fprintf(cli.out, "Deleted: %s\n", out.Get("Deleted"))
} else {
fmt.Fprintf(cli.out, "Untagged: %s\n", out.Get("Untagged"))
}
}
}
}
return encounteredError
}
开发者ID:nicholaskh,项目名称:docker,代码行数:45,代码来源:rmi.go
示例14: Search
// Search queries the public registry for images matching the specified
// search terms, and returns the results.
//
// Argument syntax: search TERM
//
// Option environment:
// 'authConfig': json-encoded credentials to authenticate against the registry.
// The search extends to images only accessible via the credentials.
//
// 'metaHeaders': extra HTTP headers to include in the request to the registry.
// The headers should be passed as a json-encoded dictionary.
//
// Output:
// Results are sent as a collection of structured messages (using engine.Table).
// Each result is sent as a separate message.
// Results are ordered by number of stars on the public registry.
func (s *Service) Search(job *engine.Job) engine.Status {
if n := len(job.Args); n != 1 {
return job.Errorf("Usage: %s TERM", job.Name)
}
var (
term = job.Args[0]
metaHeaders = map[string][]string{}
authConfig = &AuthConfig{}
)
job.GetenvJson("authConfig", authConfig)
job.GetenvJson("metaHeaders", metaHeaders)
repoInfo, err := ResolveRepositoryInfo(job, term)
if err != nil {
return job.Error(err)
}
// *TODO: Search multiple indexes.
endpoint, err := repoInfo.GetEndpoint()
if err != nil {
return job.Error(err)
}
r, err := NewSession(authConfig, HTTPRequestFactory(metaHeaders), endpoint, true)
if err != nil {
return job.Error(err)
}
results, err := r.SearchRepositories(repoInfo.GetSearchTerm())
if err != nil {
return job.Error(err)
}
outs := engine.NewTable("star_count", 0)
for _, result := range results.Results {
out := &engine.Env{}
out.Import(result)
outs.Add(out)
}
outs.ReverseSort()
if _, err := outs.WriteListTo(job.Stdout); err != nil {
return job.Error(err)
}
return engine.StatusOK
}
开发者ID:Crispy1975,项目名称:deis,代码行数:57,代码来源:service.go
示例15: TestGetContainersChanges
func TestGetContainersChanges(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
// Create a container and remove a file
containerID := createTestContainer(eng,
&runconfig.Config{
Image: unitTestImageID,
Cmd: []string{"/bin/rm", "/etc/passwd"},
},
t,
)
containerRun(eng, containerID, t)
r := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/containers/"+containerID+"/changes", nil)
if err != nil {
t.Fatal(err)
}
if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
assertHttpNotError(r, t)
outs := engine.NewTable("", 0)
if _, err := outs.ReadListFrom(r.Body.Bytes()); err != nil {
t.Fatal(err)
}
// Check the changelog
success := false
for _, elem := range outs.Data {
if elem.Get("Path") == "/etc/passwd" && elem.GetInt("Kind") == 2 {
success = true
}
}
if !success {
t.Fatalf("/etc/passwd as been removed but is not present in the diff")
}
}
开发者ID:BreezeWu,项目名称:docker,代码行数:39,代码来源:api_test.go
示例16: getContainersJSON
func getContainersJSON(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := parseForm(r); err != nil {
return err
}
var (
err error
outs *engine.Table
job = eng.Job("containers")
)
job.Setenv("all", r.Form.Get("all"))
job.Setenv("size", r.Form.Get("size"))
job.Setenv("since", r.Form.Get("since"))
job.Setenv("before", r.Form.Get("before"))
job.Setenv("limit", r.Form.Get("limit"))
job.Setenv("filters", r.Form.Get("filters"))
if version.GreaterThanOrEqualTo("1.5") {
streamJSON(job, w, false)
} else if outs, err = job.Stdout.AddTable(); err != nil {
return err
}
if err = job.Run(); err != nil {
return err
}
if version.LessThan("1.5") { // Convert to legacy format
for _, out := range outs.Data {
ports := engine.NewTable("", 0)
ports.ReadListFrom([]byte(out.Get("Ports")))
out.Set("Ports", api.DisplayablePorts(ports))
}
w.Header().Set("Content-Type", "application/json")
if _, err = outs.WriteListTo(w); err != nil {
return err
}
}
return nil
}
开发者ID:pombredanne,项目名称:docker,代码行数:38,代码来源:server.go
示例17: PortMappingAPI
func (settings *NetworkSettings) PortMappingAPI() *engine.Table {
var outs = engine.NewTable("", 0)
for port, bindings := range settings.Ports {
p, _ := nat.ParsePort(port.Port())
if len(bindings) == 0 {
out := &engine.Env{}
out.SetInt("PrivatePort", p)
out.Set("Type", port.Proto())
outs.Add(out)
continue
}
for _, binding := range bindings {
out := &engine.Env{}
h, _ := nat.ParsePort(binding.HostPort)
out.SetInt("PrivatePort", p)
out.SetInt("PublicPort", h)
out.Set("Type", port.Proto())
out.Set("IP", binding.HostIp)
outs.Add(out)
}
}
return outs
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:23,代码来源:network_settings.go
示例18: CmdHistory
func (s *TagStore) CmdHistory(job *engine.Job) error {
if n := len(job.Args); n != 1 {
return fmt.Errorf("Usage: %s IMAGE", job.Name)
}
name := job.Args[0]
foundImage, err := s.LookupImage(name)
if err != nil {
return err
}
lookupMap := make(map[string][]string)
for name, repository := range s.Repositories {
for tag, id := range repository {
// If the ID already has a reverse lookup, do not update it unless for "latest"
if _, exists := lookupMap[id]; !exists {
lookupMap[id] = []string{}
}
lookupMap[id] = append(lookupMap[id], utils.ImageReference(name, tag))
}
}
outs := engine.NewTable("Created", 0)
err = foundImage.WalkHistory(func(img *image.Image) error {
out := &engine.Env{}
out.SetJson("Id", img.ID)
out.SetInt64("Created", img.Created.Unix())
out.Set("CreatedBy", strings.Join(img.ContainerConfig.Cmd, " "))
out.SetList("Tags", lookupMap[img.ID])
out.SetInt64("Size", img.Size)
outs.Add(out)
return nil
})
if _, err := outs.WriteListTo(job.Stdout); err != nil {
return err
}
return nil
}
开发者ID:nicholaskh,项目名称:docker,代码行数:37,代码来源:history.go
示例19: Containers
func (srv *Server) Containers(job *engine.Job) engine.Status {
var (
foundBefore bool
displayed int
all = job.GetenvBool("all")
since = job.Getenv("since")
before = job.Getenv("before")
n = job.GetenvInt("limit")
size = job.GetenvBool("size")
)
outs := engine.NewTable("Created", 0)
names := map[string][]string{}
srv.daemon.ContainerGraph().Walk("/", func(p string, e *graphdb.Entity) error {
names[e.ID()] = append(names[e.ID()], p)
return nil
}, -1)
var beforeCont, sinceCont *daemon.Container
if before != "" {
beforeCont = srv.daemon.Get(before)
if beforeCont == nil {
return job.Error(fmt.Errorf("Could not find container with name or id %s", before))
}
}
if since != "" {
sinceCont = srv.daemon.Get(since)
if sinceCont == nil {
return job.Error(fmt.Errorf("Could not find container with name or id %s", since))
}
}
errLast := errors.New("last container")
writeCont := func(container *daemon.Container) error {
container.Lock()
defer container.Unlock()
if !container.State.IsRunning() && !all && n <= 0 && since == "" && before == "" {
return nil
}
if before != "" && !foundBefore {
if container.ID == beforeCont.ID {
foundBefore = true
}
return nil
}
if n > 0 && displayed == n {
return errLast
}
if since != "" {
if container.ID == sinceCont.ID {
return errLast
}
}
displayed++
out := &engine.Env{}
out.Set("Id", container.ID)
out.SetList("Names", names[container.ID])
out.Set("Image", srv.daemon.Repositories().ImageName(container.Image))
if len(container.Args) > 0 {
args := []string{}
for _, arg := range container.Args {
if strings.Contains(arg, " ") {
args = append(args, fmt.Sprintf("'%s'", arg))
} else {
args = append(args, arg)
}
}
argsAsString := strings.Join(args, " ")
out.Set("Command", fmt.Sprintf("\"%s %s\"", container.Path, argsAsString))
} else {
out.Set("Command", fmt.Sprintf("\"%s\"", container.Path))
}
out.SetInt64("Created", container.Created.Unix())
out.Set("Status", container.State.String())
str, err := container.NetworkSettings.PortMappingAPI().ToListString()
if err != nil {
return err
}
out.Set("Ports", str)
if size {
sizeRw, sizeRootFs := container.GetSize()
out.SetInt64("SizeRw", sizeRw)
out.SetInt64("SizeRootFs", sizeRootFs)
}
outs.Add(out)
return nil
}
for _, container := range srv.daemon.List() {
if err := writeCont(container); err != nil {
if err != errLast {
return job.Error(err)
}
break
}
}
outs.ReverseSort()
if _, err := outs.WriteListTo(job.Stdout); err != nil {
//.........这里部分代码省略.........
开发者ID:JianfuLi,项目名称:docker,代码行数:101,代码来源:container.go
示例20: Containers
func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
var (
foundBefore bool
displayed int
all = job.GetenvBool("all")
since = job.Getenv("since")
before = job.Getenv("before")
n = job.GetenvInt("limit")
size = job.GetenvBool("size")
psFilters filters.Args
filt_exited []int
)
outs := engine.NewTable("Created", 0)
psFilters, err := filters.FromParam(job.Getenv("filters"))
if err != nil {
return job.Error(err)
}
if i, ok := psFilters["exited"]; ok {
for _, value := range i {
code, err := strconv.Atoi(value)
if err != nil {
return job.Error(err)
}
filt_exited = append(filt_exited, code)
}
}
if i, ok := psFilters["status"]; ok {
for _, value := range i {
if value == "exited" {
all = true
}
}
}
names := map[string][]string{}
daemon.ContainerGraph().Walk("/", func(p string, e *graphdb.Entity) error {
names[e.ID()] = append(names[e.ID()], p)
return nil
}, 1)
var beforeCont, sinceCont *Container
if before != "" {
beforeCont, err = daemon.Get(before)
if err != nil {
return job.Error(err)
}
}
if since != "" {
sinceCont, err = daemon.Get(since)
if err != nil {
return job.Error(err)
}
}
errLast := errors.New("last container")
writeCont := func(container *Container) error {
container.Lock()
defer container.Unlock()
if !container.Running && !all && n <= 0 && since == "" && before == "" {
return nil
}
if !psFilters.Match("name", container.Name) {
return nil
}
if !psFilters.Match("id", container.ID) {
return nil
}
if !psFilters.MatchKVList("label", container.Config.Labels) {
return nil
}
if before != "" && !foundBefore {
if container.ID == beforeCont.ID {
foundBefore = true
}
return nil
}
if n > 0 && displayed == n {
return errLast
}
if since != "" {
if container.ID == sinceCont.ID {
return errLast
}
}
if len(filt_exited) > 0 {
should_skip := true
for _, code := range filt_exited {
if code == container.ExitCode && !container.Running {
should_skip = false
break
}
}
if should_skip {
return nil
}
//.........这里部分代码省略.........
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:101,代码来源:list.go
注:本文中的github.com/docker/docker/engine.NewTable函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论