コード例 #1
0
func updateTagCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tag")
	}
	tag := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	v, err := clnt.Tag.Get(tag)
	if err != nil {
		log.Fatal(err.Error())
	}

	if c.Bool("prompt") {
		s := client.Tag{
			ID:      v.ID,
			Tag:     prompt.String("Image", prompt.Prompt{Default: v.Tag, FuncPtr: prompt.Regex, FuncInp: ""}),
			Created: prompt.String("Created", prompt.Prompt{Default: v.Created, FuncPtr: prompt.Regex, FuncInp: ""}),
			SHA256:  prompt.String("SHA256", prompt.Prompt{Default: v.SHA256, FuncPtr: prompt.Regex, FuncInp: "^[0-9a-f]+$"}),
			ImageID: *chooseImage(clnt, v.ImageID),
		}

		// Update tag
		clnt.Tag.Update(tag, &s)
		return
	}
}
コード例 #2
0
func createTenantCommandFunc(c *cli.Context) {
	var tenant string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tenant")
	} else {
		tenant = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	s := client.Tenant{
		Tenant: tenant,
	}

	// Is this correct?
	fmt.Println(string(s.JSON()))
	if !prompt.Bool("Is this correct", true) {
		os.Exit(1)
	}

	// Create tenant
	clnt.Tenant.Create(&s)
	return
}
コード例 #3
0
func createImageCommandFunc(c *cli.Context) {
	var image string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a image")
	} else {
		image = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	if c.Bool("prompt") {
		s := client.Image{
			Image:     image,
			Type:      prompt.String("Type", prompt.Prompt{Default: "docker", FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
			BootTagID: *chooseTag(clnt, ""),
		}

		// Create image
		clnt.Image.Create(&s)
		return
	}
}
コード例 #4
0
func createSiteCommandFunc(c *cli.Context) {
	var site string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a site")
	} else {
		site = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	if c.Bool("prompt") {
		s := client.Site{
			Site:               site,
			Domain:             prompt.String("Domain", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: ""}),
			DNS:                strings.Split(prompt.String("DNS", prompt.Prompt{NoDefault: true, FuncPtr: validateIPv4List, FuncInp: ""}), ","),
			DockerRegistry:     prompt.String("Docker Registry", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: ""}),
			ArtifactRepository: prompt.String("Artifact Repository", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: ""}),
			NamingScheme:       prompt.String("Naming Scheme", prompt.Prompt{Default: "hardware-address", FuncPtr: prompt.Enum, FuncInp: "serial-number,hardware-address,external"}),
			PXETheme:           prompt.String("PXE Theme", prompt.Prompt{Default: "night", FuncPtr: prompt.Regex, FuncInp: ""}),
		}

		// Create site
		clnt.Site.Create(&s)
		return
	}
}
コード例 #5
0
func updateSubnetCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a subnet")
	}
	subnet := strings.Replace(c.Args()[0], "/", "-", 1)

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	v, err := clnt.Subnet.Get(subnet)
	if err != nil {
		log.Fatal(err.Error())
	}

	s := client.Subnet{
		ID:     v.ID,
		Subnet: prompt.String("Subnet", prompt.Prompt{Default: v.Subnet, FuncPtr: prompt.Regex, FuncInp: ""}),
		Mask:   prompt.String("Mask", prompt.Prompt{Default: v.Mask, FuncPtr: validateIPv4, FuncInp: ""}),
		Gw:     prompt.String("Gateway", prompt.Prompt{Default: v.Gw, FuncPtr: validateIPv4, FuncInp: ""}),
		SiteID: *chooseSite(clnt, v.SiteID),
	}

	// Create subnet
	clnt.Subnet.Update(subnet, &s)
}
コード例 #6
0
func updateImageCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a image")
	}
	image := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	v, err := clnt.Image.Get(image)
	if err != nil {
		log.Fatal(err.Error())
	}

	s := client.Image{
		ID:        v.ID,
		Image:     prompt.String("Image", prompt.Prompt{Default: v.Image, FuncPtr: prompt.Regex, FuncInp: ""}),
		Type:      prompt.String("Type", prompt.Prompt{Default: v.Type, FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
		BootTagID: *chooseTag(clnt, v.BootTagID),
	}

	// Update image
	clnt.Image.Update(image, &s)
}
コード例 #7
0
ファイル: create_tag_command.go プロジェクト: pbh101/dock2box
func createTagCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tag")
	}
	tag := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	s := client.Tag{
		Tag:     tag,
		Created: prompt.String("Created", prompt.Prompt{Default: strftime.Format("%Y-%m-%dT%H:%M:%SZ", time.Now()), FuncPtr: prompt.Regex, FuncInp: ""}),
		SHA256:  prompt.String("SHA256", prompt.Prompt{NoDefault: true, FuncPtr: prompt.Regex, FuncInp: "^[0-9a-f]+$"}),
		ImageID: *chooseImage(clnt, ""),
	}

	// Is this correct?
	fmt.Println(string(s.JSON()))
	if !prompt.Bool("Is this correct", true) {
		os.Exit(1)
	}

	// Create image
	clnt.Tag.Create(&s)
}
コード例 #8
0
func updateSiteCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a site")
	}
	site := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	v, err := clnt.Site.Get(site)
	if err != nil {
		log.Fatal(err.Error())
	}

	s := client.Site{
		ID:                 v.ID,
		Site:               prompt.String("Site", prompt.Prompt{Default: v.Site, FuncPtr: prompt.Regex, FuncInp: ""}),
		Domain:             prompt.String("Domain", prompt.Prompt{Default: v.Domain, FuncPtr: prompt.Regex, FuncInp: ""}),
		DNS:                strings.Split(prompt.String("DNS", prompt.Prompt{Default: strings.Join(v.DNS, ","), FuncPtr: validateIPv4List, FuncInp: ""}), ","),
		DockerRegistry:     prompt.String("Docker Registry", prompt.Prompt{Default: v.DockerRegistry, FuncPtr: prompt.Regex, FuncInp: ""}),
		ArtifactRepository: prompt.String("Artifact Repository", prompt.Prompt{Default: v.ArtifactRepository, FuncPtr: prompt.Regex, FuncInp: ""}),
		NamingScheme:       prompt.String("Naming Scheme", prompt.Prompt{Default: v.NamingScheme, FuncPtr: prompt.Enum, FuncInp: "serial-number,hardware-address,external"}),
		PXETheme:           prompt.String("PXE Theme", prompt.Prompt{Default: v.PXETheme, FuncPtr: prompt.Regex, FuncInp: ""}),
	}

	// Create site
	clnt.Site.Update(site, &s)
}
コード例 #9
0
func createImageCommandFunc(c *cli.Context) {
	var image string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a image")
	} else {
		image = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	s := client.Image{
		Image:     image,
		Type:      prompt.String("Type", prompt.Prompt{Default: "docker", FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
		BootTagID: *chooseTag(clnt, ""),
	}

	// Is this correct?
	fmt.Println(string(s.JSON()))
	if !prompt.Bool("Is this correct", true) {
		os.Exit(1)
	}

	// Create image
	clnt.Image.Create(&s)
}
コード例 #10
0
func updateTenantCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tenant")
	}
	tenant := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	v, err := clnt.Tenant.Get(tenant)
	if err != nil {
		log.Fatal(err.Error())
	}

	s := client.Tenant{
		ID:     v.ID,
		Tenant: prompt.String("Tenant", prompt.Prompt{Default: v.Tenant, FuncPtr: prompt.Regex, FuncInp: ""}),
	}

	// Create tenant
	clnt.Tenant.Update(tenant, &s)
	return
}
コード例 #11
0
func createSubnetCommandFunc(c *cli.Context) {
	var subnet string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a subnet")
	} else {
		subnet = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	if c.Bool("prompt") {
		s := client.Subnet{
			Subnet: subnet,
			// Calculate automatically based on subnet/prefix
			Mask: prompt.String("Mask", prompt.Prompt{NoDefault: true, FuncPtr: validateIPv4, FuncInp: ""}),
			// Default to .254 for subnet
			Gw:     prompt.String("Gateway", prompt.Prompt{NoDefault: true, FuncPtr: validateIPv4, FuncInp: ""}),
			SiteID: *chooseSite(clnt, ""),
		}

		// Create subnet
		clnt.Subnet.Create(&s)
		return
	}
}
コード例 #12
0
ファイル: main.go プロジェクト: bfloriang/dock2box
func main() {
	c := client.New("http://localhost:8080/v1")

	hosts, err := c.Host.All()
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(hosts.JSON())
}
コード例 #13
0
func getHostsCommandFunc(c *cli.Context) {
	clnt := client.New(c.GlobalString("server"))

	h, err := clnt.Host.All()
	if err != nil {
		log.Fatal(err.Error())
	}
	b, _ := json.MarshalIndent(h, "", "  ")
	fmt.Printf("%v\n", string(b))
}
コード例 #14
0
func updateHostCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a hostname")
	}
	hostname := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	v, err := clnt.Host.Get(hostname)
	if err != nil {
		log.Fatal(err.Error())
	}

	if c.Bool("prompt") {
		h := client.Host{
			ID:    v.ID,
			Host:  prompt.String("Host", prompt.Prompt{Default: v.Host, FuncPtr: prompt.Regex, FuncInp: ""}),
			Build: prompt.Bool("Build", v.Build),
			Debug: prompt.Bool("Debug", v.Debug),
			GPT:   prompt.Bool("GPT", v.GPT),
			TagID: *chooseTag(clnt, v.TagID),
		}

		// Get labels
		labels := prompt.String("Comma-separated list of labels", prompt.Prompt{Default: strings.Join(v.Labels, ","), FuncPtr: prompt.Regex, FuncInp: "^([a-zA-Z][a-zA-Z0-9-]+,)*([a-zA-Z][a-zA-Z0-9-]+)$"})
		if labels == "" {
			h.Labels = []string{}
		} else {
			h.Labels = strings.Split(labels, ",")
		}

		h.KOpts = prompt.String("KOpts", prompt.Prompt{Default: v.KOpts, FuncPtr: prompt.Regex, FuncInp: "^(|[a-zA-Z0-9- ])+$"})
		h.TenantID = *chooseTenants(clnt, v.TenantID)
		h.SiteID = *chooseSite(clnt, v.SiteID)

		/*
			for _, v := range v.Interfaces {
				h.Interfaces = append(h.Interfaces, updateHostInterface(clnt, h.SiteID, v))
			}
		*/

		// Is this correct?
		fmt.Println(string(h.JSON()))
		if !prompt.Bool("Is this correct", true) {
			os.Exit(1)
		}

		// Update host
		clnt.Host.Update(hostname, &h)
		return
	}
}
コード例 #15
0
ファイル: example_test.go プロジェクト: bfloriang/dock2box
func Example_GetHost() {
	server := "http://localhost:8080/v1"
	hostname := "test1.example.com"

	clnt := client.New(server)
	h, err := clnt.Host.Get(hostname)
	if err != nil {
		log.Fatal(err.Error())
	}

	fmt.Printf("%v\n", string(h.JSON()))
}
コード例 #16
0
ファイル: get_images_command.go プロジェクト: pbh101/dock2box
func getImagesCommandFunc(c *cli.Context) {
	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	i, err := clnt.Image.All()
	if err != nil {
		log.Fatal(err.Error())
	}
	b, _ := json.MarshalIndent(i, "", "  ")
	fmt.Printf("%v\n", string(b))
}
コード例 #17
0
func deleteTagCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tag")
	}
	tag := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))

	h, err := clnt.Image.Delete(tag)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(h.JSON()))
}
コード例 #18
0
func getSiteCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a site")
	}
	site := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))

	s, err := clnt.Site.Get(site)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(s.JSON()))
}
コード例 #19
0
func getTenantCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tenantname")
	}
	tenant := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))

	t, err := clnt.Tenant.Get(tenant)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(t.JSON()))
}
コード例 #20
0
func getInterfaceCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify an interface")
	}
	intf := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))

	i, err := clnt.Interface.Get(intf)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(i.JSON()))
}
コード例 #21
0
func deleteSubnetCommandFunc(c *cli.Context) {
	var subnet string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a subnet")
	} else {
		subnet = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))

	h, err := clnt.Subnet.Delete(subnet)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(h.JSON()))
}
コード例 #22
0
func deleteImageCommandFunc(c *cli.Context) {
	var image string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a image")
	} else {
		image = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))

	h, err := clnt.Image.Delete(image)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(h.JSON()))
}
コード例 #23
0
func deleteTenantCommandFunc(c *cli.Context) {
	var tenant string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tenant")
	} else {
		tenant = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))

	t, err := clnt.Tenant.Delete(tenant)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(t.JSON()))
}
コード例 #24
0
func deleteHostCommandFunc(c *cli.Context) {
	var hostname string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a hostname")
	} else {
		hostname = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))

	h, err := clnt.Host.Delete(hostname)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(h.JSON()))
}
コード例 #25
0
ファイル: get_image_command.go プロジェクト: pbh101/dock2box
func getImageCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a image")
	}
	image := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	i, err := clnt.Image.Get(image)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(i.JSON()))
}
コード例 #26
0
ファイル: get_subnet_command.go プロジェクト: pbh101/dock2box
func getSubnetCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a subnet")
	}
	subnet := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	s, err := clnt.Subnet.Get(subnet)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(s.JSON()))
}
コード例 #27
0
func getHostCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a hostname")
	}
	hostname := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	h, err := clnt.Host.Query(map[string]string{"host": hostname})
	if err != nil {
		log.Fatal(err.Error())
	}

	b, _ := json.MarshalIndent(h, "", "  ")
	fmt.Printf("%v\n", string(b))
}
コード例 #28
0
func createHostCommandFunc(c *cli.Context) {
	var hostname string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a hostname")
	} else {
		hostname = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	h := client.Host{
		Host:  hostname,
		Build: prompt.Bool("Build", true),
		Debug: prompt.Bool("Debug", false),
		GPT:   prompt.Bool("GPT", false),
		TagID: *chooseTag(clnt, ""),
	}

	// Get labels
	labels := prompt.String("Comma-separated list of labels", prompt.Prompt{Default: "", FuncPtr: prompt.Regex, FuncInp: "^([a-zA-Z][a-zA-Z0-9-]+,)*([a-zA-Z][a-zA-Z0-9-]+)$"})
	if labels == "" {
		h.Labels = []string{}
	} else {
		h.Labels = strings.Split(labels, ",")
	}

	h.KOpts = prompt.String("KOpts", prompt.Prompt{Default: "", FuncPtr: prompt.Regex, FuncInp: "^(|[a-zA-Z0-9- ])+$"})
	h.TenantID = *chooseTenants(clnt, "")
	h.SiteID = *chooseSite(clnt, "")

	// Is this correct?
	fmt.Println(string(h.JSON()))
	if !prompt.Bool("Is this correct", true) {
		os.Exit(1)
	}

	// Create host
	clnt.Host.Create(&h)
}
コード例 #29
0
func createTenantCommandFunc(c *cli.Context) {
	var tenant string
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify a tenant")
	} else {
		tenant = c.Args()[0]
	}

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	s := client.Tenant{
		Tenant: tenant,
	}

	// Create tenant
	clnt.Tenant.Create(&s)
	return
}
コード例 #30
0
func deleteInterfaceCommandFunc(c *cli.Context) {
	if len(c.Args()) == 0 {
		log.Fatal("You need to specify an interface id")
	}
	id := c.Args()[0]

	clnt := client.New(c.GlobalString("server"))
	if c.GlobalBool("debug") {
		clnt.SetDebug()
	}

	if !prompt.Bool("Are you sure you wan't to remove interface id: "+id, true) {
		os.Exit(1)
	}

	s, err := clnt.Interface.Delete(id)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmt.Printf("%v\n", string(s.JSON()))
}