Пример #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 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)
}
Пример #3
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)
	*/
}