Exemple #1
0
func (no *nukeOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	root := path.Join(env.DIR, "containers", id)

	_, err := os.Stat(root)

	if err != nil {
		// Look for an image instead
		return nukeImage(no, id)
	}

	_, err = ioutil.ReadFile(path.Join(root, "running"))

	if err == nil {
		fmt.Printf("Cowardly refusing to nuke running container\n")
		os.Exit(1)
	}

	err = os.RemoveAll(root)

	if err != nil {
		return err
	}

	fmt.Printf("Removed %s\n", id)

	return nil
}
Exemple #2
0
func (co *commitOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	cont, err := env.LoadContainer(env.DIR, id)

	if err != nil {
		return fmt.Errorf("Unable to load %s: %s\n", id, err)
	}

	ts, err := env.DefaultTagStore()

	if err != nil {
		return err
	}

	img, err := cont.Commit(co.Comment, co.Author, nil, co.Squash, false)

	if err != nil {
		return fmt.Errorf("Unable to create image: %s\n", err)
	}

	repo, tag := env.ParseRepositoryTag(args[1])

	ts.Add(repo, tag, img.ID)
	ts.Flush()

	return nil
}
Exemple #3
0
func (po *portOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	cont, err := env.LoadContainer(env.DIR, id)

	if err != nil {
		return fmt.Errorf("Error loading conatiner %s: %s\n", id, err)
	}

	if po.TCP != "" {
		h, ok := cont.NetworkSettings.PortMapping["Tcp"][po.TCP]

		if ok {
			fmt.Printf("%s\n", h)
		} else {
			return fmt.Errorf("Unknown tcp port %s\n", po.TCP)
		}

		return nil
	}

	if po.UDP != "" {
		h, ok := cont.NetworkSettings.PortMapping["Udp"][po.UDP]

		if ok {
			fmt.Printf("%s\n", h)
		} else {
			return fmt.Errorf("Unknown udp port %s\n", po.UDP)
		}

		return nil
	}

	for c, h := range cont.NetworkSettings.PortMapping["Tcp"] {
		fmt.Printf("tcp %s -> tcp %s\n", c, h)
	}

	for c, h := range cont.NetworkSettings.PortMapping["Udp"] {
		fmt.Printf("udp %s -> udp %s\n", c, h)
	}

	return nil
}
Exemple #4
0
func (io *inspectOptions) Execute(args []string) error {
	if err := app.CheckArity(1, 1, args); err != nil {
		return err
	}

	id := utils.ExpandID(env.DIR, args[0])

	cont, err := env.LoadContainer(env.DIR, id)

	if err != nil {
		return err
	}

	data, err := json.Marshal(cont)

	var out bytes.Buffer

	json.Indent(&out, data, "", "  ")

	out.WriteTo(os.Stdout)
	os.Stdout.Write([]byte("\n"))

	return nil
}