Пример #1
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
	}
}
Пример #2
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)
}
Пример #3
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)
}
Пример #4
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()
	}

	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, ""),
	}

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

	// Create subnet
	clnt.Subnet.Create(&s)
}
Пример #5
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()
	}

	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: ""}),
	}

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

	// Create site
	clnt.Site.Create(&s)
}
Пример #6
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
}
Пример #7
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)
}
Пример #8
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()))
}
Пример #9
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()
	}

	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)
	*/
}