Esempio n. 1
0
func main() {

	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
			os.Exit(1)
		}
	}()

	utils.LogInfo("\nDeploying Agent Server...")

	var ln string
	var e error
	rd := bufio.NewReader(os.Stdin)

	for {
		ln, e = rd.ReadString('\n')
		println(ln)
		if e != nil {
			panic(e)
		} else if strings.ContainsAny(ln, "AGENT_KUBER_API") {
			break
		}
	}

	if !strings.ContainsAny(ln, "AGENT_KUBER_API") {
		panic("Missing Key, AGENT_KUBER_API. Cannot proceed.")
	}

	kv := strings.Split(ln, "=")
	utils.SetKey("AGENT_KUBER_API", kv[1])

	pk, puk, _ := utils.CreateSSHKey()

	c := deploy.CenturyLink{
		PublicSSHKey:   puk,
		APIUsername:    os.Getenv("USERNAME"),
		APIPassword:    os.Getenv("PASSWORD"),
		GroupID:        os.Getenv("GROUP_ID"),
		CPU:            1,
		MemoryGB:       1,
		TCPOpenPorts:   []int{3001},
		ServerName:     "AGENT",
		ServerTemplate: "UBUNTU-14-64-TEMPLATE",
	}

	utils.LogInfo("\nWaiting for server creation...")
	s, e := c.DeployVM()

	if e != nil {
		panic(e)
	}

	utils.SetKey("AGENT_PRIVATE_KEY", base64.StdEncoding.EncodeToString([]byte(pk)))
	utils.SetKey("AGENT_PUBLIC_IP", s.PublicIP)

	utils.LogInfo("\nAgent server deployment complete!!")
}
Esempio n. 2
0
func (clc *CenturyLink) initProvider() error {
	clc.uname = os.Getenv("USERNAME")
	clc.password = os.Getenv("PASSWORD")
	clc.groupID = os.Getenv("GROUP_ID")
	clc.cpu, _ = strconv.Atoi(os.Getenv("CPU"))
	clc.memGb, _ = strconv.Atoi(os.Getenv("MEMORY_GB"))
	ps := os.Getenv("OPEN_TCP_PORTS")
	if ps != "" {
		s := strings.Split(ps, ",")
		for _, p := range s {
			v, e := strconv.Atoi(p)
			if e == nil {
				clc.minionPorts = append(clc.minionPorts, v)
			}
		}
	}

	if clc.uname == "" || clc.password == "" || clc.groupID == "" {
		return errors.New("\n\nMissing values to create cluster. Check documentation for required values\n\n")
	}

	if clc.cpu <= 0 || clc.memGb <= 0 {
		return errors.New("\n\nMake sure CPU & MemoryGB values are greater than 0.\n\n")
	}

	pk, puk, err := utils.CreateSSHKey()
	clc.masterPK = pk
	clc.masterPuK = puk

	if err != nil {
		return err
	}

	return nil

}