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
	}
}
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
	}
}
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)
}
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)
}
Beispiel #5
0
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)
}
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
	}
}
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)
}
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
}
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
	}
}
Beispiel #10
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)
}
Beispiel #11
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)
}
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
	}
}
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()
	}

	if c.Bool("prompt") {
		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, "")

		/*
			h.Interfaces = []client.Interface{addInterface(clnt, h.SiteID)}
			if prompt.Bool("Do you want to add another network interface", false) {
				h.Interfaces = append(h.Interfaces, addInterface(clnt, h.SiteID))
			}
		*/

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

		// Create host
		clnt.Host.Create(&h)
		return
	}

	/*
		h := client.Host{
			Host:  hostname,
			Debug: c.Bool("debug"),
			GPT:   c.Bool("gpt"),
			KOpts: c.String("kopts"),
		}

		// Get build
		if c.Bool("disable-build") {
			h.Build = false
		} else {
			h.Build = true
		}

		// Check arguments
		if !c.IsSet("image") {
			log.Fatalf("You need to specify image")
		}

		if !c.IsSet("tenant") {
			log.Fatalf("You need to specify tenant")
		}

		if !c.IsSet("site") {
			log.Fatalf("You need to specify site")
		}

		// Get tag ID
		tag, err := clnt.Tag.Get(c.String("tag"))
		if err != nil {
			log.Fatalf(err.Error())
		}
		h.TagID = tag.ID

		// Get tenant
		tenant, err := clnt.Tenant.Get(c.String("tenant"))
		if err != nil {
			log.Fatalf(err.Error())
		}
		h.TenantID = tenant.ID

		// Get labels
		if !c.IsSet("labels") {
			h.Labels = []string{}
		} else {
			h.Labels = strings.Split(c.String("labels"), ",")
		}

		// Get site
		site, err := clnt.Site.Get(c.String("site"))
		if err != nil {
			log.Fatalf(err.Error())
		}
		h.SiteID = site.ID

		// Host Interface
		ifs := client.Interface{
			Interface: c.String("interface"),
			DHCP:      c.Bool("dhcp"),
			HwAddr:    c.String("hwaddr"),
		}

		if !ifs.DHCP {
			ifs.IPv4 = c.String("ipv4")

			// Get subnet
			subnet, err := clnt.Subnet.Get(c.String("subnet"))
			if err != nil {
				log.Fatalf(err.Error())
			}
			ifs.SubnetID = subnet.ID

			h.Interfaces = []client.Interface{ifs}
		}

		// Create host
		clnt.Host.Create(&h)
	*/
}