Esempio n. 1
0
func cmdAdd(c *cli.Context) {
	utils.FlagsRequired(c, []string{"cidr", "minPort", "maxPort", "ipProtocol"})

	// API accepts only 1 rule
	newRule := &Rule{
		c.String("ipProtocol"),
		c.String("cidr"),
		c.Int("minPort"),
		c.Int("maxPort"),
	}
	policy := get()

	exists := check(policy, *newRule)

	if exists == false {
		policy.Rules = append(policy.Rules, *newRule)
		webservice, err := webservice.NewWebService()
		utils.CheckError(err)

		nRule := make(map[string]Rule)
		nRule["rule"] = *newRule

		json, err := json.Marshal(nRule)
		utils.CheckError(err)
		err, res, code := webservice.Post(fmt.Sprintf("%s/rules", endpoint), json)
		if res == nil {
			log.Fatal(err)
		}
		utils.CheckError(err)
		utils.CheckReturnCode(code, res)
	}
}
Esempio n. 2
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "domain_id", "ssh_profile_id", "firewall_profile_id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("name")
	v["domain_id"] = c.String("domain_id")
	v["ssh_profile_id"] = c.String("ssh_profile_id")
	v["firewall_profile_id"] = c.String("firewall_profile_id")

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/cloud/workspaces", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var workspace Workspace
	err = json.Unmarshal(res, &workspace)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tDEFAULT\tDOMAIN ID\tSSH PROFILE ID\tFIREWALL PROFILE ID\r")
	fmt.Fprintf(w, "%s\t%s\t%t\t%s\t%s\t%s\n", workspace.Id, workspace.Name, workspace.Default, workspace.Domain_id, workspace.Ssh_profile_id, workspace.Firewall_profile_id)

	w.Flush()

}
Esempio n. 3
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "description", "code"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("name")
	v["description"] = c.String("description")
	v["code"] = c.String("code")
	if c.IsSet("parameters") {
		v["parameters"] = c.String("parameters")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/blueprint/scripts", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var new_script Script
	err = json.Unmarshal(res, &new_script)
	utils.CheckError(err)
	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tDESCRIPTION\tCODE\tPARAMETERS\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", new_script.Id, new_script.Name, new_script.Description, new_script.Code, new_script.Parameters)

	w.Flush()

}
Esempio n. 4
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"saas_provider_id", "account_data"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	credentialsString := []byte(c.String("account_data"))

	var jsonCredentials SaasRequiredCredentials
	err = json.Unmarshal(credentialsString, &jsonCredentials)

	v := make(map[string]interface{})

	v["saas_provider_id"] = c.String("saas_provider_id")
	v["account_data"] = jsonCredentials

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/settings/saas_accounts", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

}
Esempio n. 5
0
func cmdAddNode(c *cli.Context) {

	utils.FlagsRequired(c, []string{"balancer_id", "server_id", "port"})

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["server_id"] = c.String("server_id")
	v["port"] = c.String("port")

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post(fmt.Sprintf("/v1/network/load_balancers/%s/nodes", c.String("balancer_id")), jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var n Node

	err = json.Unmarshal(res, &n)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tPUBLIC IP\tSTATE\tSERVER ID\tPORT\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\n", n.Id, n.Name, n.PublicIp, n.State, n.ServerId, n.Port)

	w.Flush()

}
Esempio n. 6
0
func cmdCreateTemplateScript(c *cli.Context) {
	utils.FlagsRequired(c, []string{"template_id", "type", "parameter_values"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]interface{})
	var params TemplateScriptCredentials

	err = json.Unmarshal([]byte(c.String("credentials")), &params)
	v["script_id"] = c.String("script_id")
	v["type"] = c.String("type")
	v["parameter_values"] = params

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post(fmt.Sprintf("/v1/blueprint/templates/%s/scripts", c.String("template_id")), jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var templateScript TemplateScript
	err = json.Unmarshal(res, &templateScript)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tTYPE\tEXECUTION ORDER\tTEMPLATE ID\tSCRIPT ID\tPARAMETER VALUES\r")
	fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\n", templateScript.Id, templateScript.Type, templateScript.Execution_Order, templateScript.Template_Id, templateScript.Script_Id, templateScript.Parameter_Values)

	w.Flush()
}
Esempio n. 7
0
func cmdCommission(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "fqdn", "workspace_id", "template_id", "server_plan_id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("name")
	v["fqdn"] = c.String("fqdn")
	v["workspace_id"] = c.String("workspace_id")
	v["template_id"] = c.String("template_id")
	v["server_plan_id"] = c.String("server_plan_id")

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/cloud/servers/", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var server Server
	err = json.Unmarshal(res, &server)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tFQDN\tSTATE\tPUBLIC IP\tWORKSPACE ID\tTEMPLATE ID\tSERVER PLAN ID\tSSH PROFILE ID\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", server.Id, server.Name, server.Fqdn, server.State, server.Public_ip, server.Workspace_id, server.Template_id, server.Server_plan_id, server.Ssh_profile_id)

	w.Flush()
}
Esempio n. 8
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "public_key"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("name")
	v["public_key"] = c.String("public_key")

	if c.IsSet("private_key") {
		v["private_key"] = c.String("private_key")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/cloud/ssh_profiles", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var sshProfile SSHProfile
	err = json.Unmarshal(res, &sshProfile)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\rPUBLIC KEY\tPRIVATE KEY\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", sshProfile.Id, sshProfile.Name, sshProfile.Public_key, sshProfile.Private_key)
	w.Flush()
}
Esempio n. 9
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"protocol"})
	if c.String("protocol") == "https" {
		utils.FlagsRequired(c, []string{"name", "fqdn", "protocol", "domain_id", "cloud_provider_id", "ssl_certificate", "ssl_certificate_private_key"})
	} else {
		utils.FlagsRequired(c, []string{"name", "fqdn", "protocol", "domain_id", "cloud_provider_id"})
	}
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("name")
	v["fqdn"] = c.String("fqdn")
	v["protocol"] = strings.ToLower(c.String("protocol"))
	v["domain_id"] = c.String("domain_id")
	v["cloud_provider_id"] = c.String("cloud_provider_id")
	if c.IsSet("ssl_certificate") {
		v["ssl_certificate"] = c.String("ssl_certificate")
	}
	if c.IsSet("ssl_certificate_private_key") {
		v["ssl_certificate_private_key"] = c.String("ssl_certificate_private_key")
	}
	if c.IsSet("port") {
		v["port"] = c.String("port")
	}
	if c.IsSet("algorithm") {
		v["algorithm"] = c.String("algorithm")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/network/load_balancers", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var lb LoadBalancer

	err = json.Unmarshal(res, &lb)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tFQDN\tPROTOCOL\tPORT\tALGORITHM\tSSL CERTIFICATE\tSSL CERTIFICATE PRIVATE KEY\tDOMAIN ID\tCLOUD PROVIDER ID\tTRAFFIC IN\tTRAFFIC OUT\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%d\t%d\n", lb.Id, lb.Name, lb.Fqdn, lb.Protocol, lb.Port, lb.Algorithm, lb.SslCertificate, lb.Ssl_certificate_private_key, lb.Domain_id, lb.Cloud_provider_id, lb.Traffic_in, lb.Traffic_out)

	w.Flush()

}
Esempio n. 10
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "generic_image_id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	template := Template{
		Name:         c.String("name"),
		GenericImgId: c.String("generic_image_id"),
	}

	if c.IsSet("service_list") {
		var services []string
		err = json.Unmarshal([]byte(c.String("service_list")), &services)
		utils.CheckError(err)
		template.ServiceList = services
	}

	if c.IsSet("configuration_attributes") {
		attributes := []byte(c.String("configuration_attributes"))
		attributesAddress := (*json.RawMessage)(&attributes)
		template.ConfigurationAttributes = attributesAddress
		utils.CheckError(err)
	}

	jsonBytes, err := json.Marshal(template)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/blueprint/templates", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	err = json.Unmarshal(res, &template)
	utils.CheckError(err)
	serviceList, err := json.Marshal(template.ServiceList)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tGENERIC IMAGE ID\tSERVICE LIST\tCONFIGURATION ATTRIBUTES\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", template.Id, template.Name, template.GenericImgId, serviceList, *template.ConfigurationAttributes)
	w.Flush()

}
Esempio n. 11
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"name", "description"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	fp := FirewallProfile{
		Name:        c.String("name"),
		Description: c.String("description"),
	}

	if c.IsSet("rules") {
		var rules []Rule
		err = json.Unmarshal([]byte(c.String("rules")), &rules)
		utils.CheckError(err)
		fp.Rules = rules
	}

	jsonBytes, err := json.Marshal(fp)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/network/firewall_profiles", jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var firewallProfile FirewallProfile

	err = json.Unmarshal(res, &firewallProfile)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tNAME\tDESCRIPTION\tDEFAULT\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%t\n", firewallProfile.Id, firewallProfile.Name, firewallProfile.Description, firewallProfile.Default)
	fmt.Fprintln(w, "RULES:\r")
	fmt.Fprintln(w, "\tPROTOCOL\tMIN PORT\tMAX PORT\tSOURCE\r")
	for _, r := range firewallProfile.Rules {
		fmt.Fprintf(w, "\t%s\t%d\t%d\t%s\n", r.Protocol, r.MinPort, r.MaxPort, r.CidrIp)
	}
	w.Flush()

}
Esempio n. 12
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"cluster", "plan"})

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["fleet_name"] = c.String("cluster")
	v["plan"] = c.String("plan")

	json, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post("/v1/kaas/ships", json)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

}
Esempio n. 13
0
func cmdCreate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"cluster"})

	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["name"] = c.String("cluster")
	if c.IsSet("domain_id") {
		v["domain_id"] = c.String("domain_id")
	}

	json, err := json.Marshal(v)
	utils.CheckError(err)

	err, mesg, code := webservice.Post("/v1/kaas/fleets", json)
	utils.CheckError(err)
	utils.CheckReturnCode(code, mesg)

}
Esempio n. 14
0
func cmdDeploy(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id", "location_id", "cloud_provider_id", "hostname", "domain_id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["location_id"] = c.String("location_id")
	v["domain_id"] = c.String("domain_id")
	v["cloud_provider_id"] = c.String("cloud_provider_id")
	if c.IsSet("server_plan_id") {
		v["server_plan_id"] = c.String("server_plan_id")
	}
	v["hostname"] = c.String("hostname")

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post(fmt.Sprintf("/v1/wizard/apps/%s/deploy", c.String("id")), jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)
}
Esempio n. 15
0
func execute(phase string) {
	var scriptChars []ScriptCharacterization
	webservice, err := webservice.NewWebService()
	if err != nil {
		log.Fatal(err)
	}
	log.Debugf("Current Script Characterization %s", phase)
	err, data, _ := webservice.Get(fmt.Sprintf(characterizationsEndpoint, phase))

	json.Unmarshal(data, &scriptChars)

	log.Debugf(string(data))

	err = json.Unmarshal(data, &scriptChars)
	if err != nil {
		log.Fatal(err)
	}
	scripts := ByOrder(scriptChars)

	for _, ex := range scripts {
		log.Infof("------------------------------------------------------------------------------------------------")
		path, err := ioutil.TempDir("", "concerto")
		if err != nil {
			log.Fatal(err)
		}

		os.Setenv("ATTACHMENT_DIR", fmt.Sprintf("%s/%s", path, "attachments"))

		log.Infof("UUID: %s", ex.UUID)
		log.Infof("Home Folder: %s", path)
		err = os.Mkdir(os.Getenv("ATTACHMENT_DIR"), 0777)
		if err != nil {
			log.Fatal(err)
		}

		// Seting up Enviroment Variables
		log.Infof("Enviroment Variables")
		for index, value := range ex.Parameters {
			os.Setenv(index, value)
			log.Infof("\t - %s=%s", index, value)
		}

		if len(ex.Script.AttachmentPaths) > 0 {
			log.Infof("Attachment Folder: %s", os.Getenv("ATTACHMENT_DIR"))
			// Downloading Attachements
			log.Infof("Attachments")
			if err != nil {
				log.Fatal(err)
			}
			for _, endpoint := range ex.Script.AttachmentPaths {
				filename, err := webservice.GetFile(endpoint, os.Getenv("ATTACHMENT_DIR"))
				if err != nil {
					log.Fatal(err)
				}
				log.Infof("\t - %s --> %s", endpoint, filename)
			}
		}

		json, err := json.Marshal(executeScriptCharacterization(ex, path))
		if err != nil {
			log.Fatal(err)
		}

		err, _, _ = webservice.Post(conclusionsEndpoint, json)
		if err != nil {
			log.Fatal(err)
		}

		log.Infof("------------------------------------------------------------------------------------------------")
	}
}
Esempio n. 16
0
func cmdCreateDomainRecords(c *cli.Context) {
	utils.FlagsRequired(c, []string{"domain_id", "type", "name"})
	if c.String("type") == "A" {
		if !c.IsSet("content") && !c.IsSet("server_id") {
			log.Warn(fmt.Sprintf("Please use either parameter --content or --server_id"))
			fmt.Printf("\n")
			cli.ShowCommandHelp(c, c.Command.Name)
			os.Exit(2)
		}
	}
	if c.String("type") == "AAAA" {
		utils.FlagsRequired(c, []string{"content"})
	}

	if c.String("type") == "CNAME" {
		utils.FlagsRequired(c, []string{"content"})
	}

	if c.String("type") == "MX" {
		utils.FlagsRequired(c, []string{"content", "prio"})
	}
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	v["type"] = c.String("type")
	if c.IsSet("name") {
		v["name"] = c.String("name")
	}
	if c.IsSet("content") {
		v["content"] = c.String("content")
	}
	if c.IsSet("ttl") {
		v["ttl"] = c.String("ttl")
	}
	if c.IsSet("prio") {
		v["prio"] = c.String("prio")
	}
	if c.IsSet("server_id") {
		v["server_id"] = c.String("server_id")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Post(fmt.Sprintf("/v1/dns/domains/%s/records", c.String("domain_id")), jsonBytes)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var dr DomainRecord
	err = json.Unmarshal(res, &dr)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tTYPE\tNAME\tCONTENT\tTTL\tPRIORITY\tSERVER ID\tDOMAIN ID\r")
	fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%d\t%s\t%s\n", dr.Id, dr.Type, dr.Name, dr.Content, dr.Ttl, dr.Prio, dr.Server_id, dr.Domain_id)

	w.Flush()

}