Example #1
0
func cmdUpdateTemplateScript(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id", "template_id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

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

	if c.IsSet("parameter_values") {
		var params TemplateScriptCredentials
		err = json.Unmarshal([]byte(c.String("credentials")), &params)
		v["parameter_values"] = params
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/blueprint/templates/%s/scripts/%s", c.String("template_id"), c.String("id")), jsonBytes)
	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()
}
Example #2
0
func cmdReorderTemplateScripts(c *cli.Context) {
	utils.FlagsRequired(c, []string{"template_id", "type", "script_ids"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]interface{})
	v["type"] = c.String("type")
	v["script_ids"] = c.GlobalStringSlice("script_ids")

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/blueprint/templates/%s/scripts/reorder", c.String("template_id")), jsonBytes)
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var templateScripts []TemplateScript
	err = json.Unmarshal(res, &templateScripts)
	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")
	for _, templateScript := range templateScripts {
		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()
}
Example #3
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

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

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/cloud/servers/%s", c.String("id")), jsonBytes)
	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()
}
Example #4
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	if c.IsSet("name") {
		v["name"] = c.String("name")
	}
	if c.IsSet("public_key") {
		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.Put(fmt.Sprintf("/v1/cloud/ssh_profiles/%s", c.String("id")), jsonBytes)
	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()
}
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	fp := FirewallProfile{
		Id: c.String("id"),
	}

	if c.IsSet("name") {
		fp.Name = c.String("name")
	}
	if c.IsSet("description") {
		fp.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.Put(fmt.Sprintf("/v1/network/firewall_profiles/%s", c.String("id")), jsonBytes)
	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()

}
Example #6
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	template := Template{
		Id: c.String("id"),
	}

	if c.IsSet("name") {
		template.Name = c.String("name")
	}

	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.Put(fmt.Sprintf("/v1/blueprint/templates/%s", c.String("id")), jsonBytes)
	utils.CheckReturnCode(code, res)

	utils.CheckError(err)
	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()
}
Example #7
0
func cmdExecuteScript(c *cli.Context) {
	utils.FlagsRequired(c, []string{"server_id", "script_id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	err, res, code := webservice.Put(fmt.Sprintf("/v1/cloud/servers/%s/operational_scripts/%s/execute", c.String("server_id"), c.String("script_id")), nil)
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)

	var event Event
	err = json.Unmarshal(res, &event)
	utils.CheckError(err)

	w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
	fmt.Fprintln(w, "ID\tTIMESTAMP\tLEVEL\tHEADER\tDESCRIPTION\r")
	fmt.Fprintf(w, "%s\t%s\t%t\t%s\t%t\n", event.Id, event.Timestamp, event.Level, event.Header, event.Description)

	w.Flush()
}
Example #8
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

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

	if c.IsSet("credentials") {
		credentialsString := []byte(c.String("credentials"))
		var jsonCredentials RequiredCredentials
		err = json.Unmarshal(credentialsString, &jsonCredentials)
		v["credentials"] = jsonCredentials
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/settings/cloud_accounts/%s", c.String("id")), jsonBytes)

	utils.CheckError(err)
	utils.CheckReturnCode(code, res)
}
Example #9
0
func cmdRemove(c *cli.Context) {
	utils.FlagsRequired(c, []string{"cidr", "minPort", "maxPort", "ipProtocol"})

	existingRule := &Rule{
		c.String("ipProtocol"),
		c.String("cidr"),
		c.Int("minPort"),
		c.Int("maxPort"),
	}
	policy := get()

	exists := check(policy, *existingRule)

	if exists == true {
		for i, rule := range policy.Rules {
			if rule == *existingRule {
				policy.Rules = append(policy.Rules[:i], policy.Rules[1+i:]...)
				break
			}
		}

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

		profile := &FirewallProfile{
			policy,
		}

		json, err := json.Marshal(profile)
		utils.CheckError(err)
		err, res, code := webservice.Put(endpoint, json)
		if res == nil {
			log.Fatal(err)
		}
		utils.CheckError(err)
		utils.CheckReturnCode(code, res)
	}

}
Example #10
0
func cmdUpdate(c *cli.Context) {
	if c.String("protocol") == "HTTPS" {
		utils.FlagsRequired(c, []string{"id", "name", "fqdn", "protocol", "ssl_certificate", "ssl_certificate_private_key"})
	} else {
		utils.FlagsRequired(c, []string{"id", "name", "fqdn", "protocol"})
	}
	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"))
	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")
	}

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/network/load_balancers/%s", c.String("id")), jsonBytes)
	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()

}
Example #11
0
func cmdUpdateDomainRecords(c *cli.Context) {
	utils.FlagsRequired(c, []string{"domain_id", "id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

	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.Put(fmt.Sprintf("/v1/dns/domains/%s/records/%s", c.String("domain_id"), c.String("id")), jsonBytes)
	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()

}
Example #12
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)
	if c.IsSet("name") {
		v["name"] = c.String("name")
	}
	if c.IsSet("description") {
		v["description"] = c.String("description")
	}
	if c.IsSet("code") {
		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.Put(fmt.Sprintf("/v1/blueprint/scripts/%s", c.String("id")), 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()
}
Example #13
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"id"})
	webservice, err := webservice.NewWebService()
	utils.CheckError(err)

	v := make(map[string]string)

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

	jsonBytes, err := json.Marshal(v)
	utils.CheckError(err)
	err, res, code := webservice.Put(fmt.Sprintf("/v1/cloud/workspaces/%s", c.String("id")), jsonBytes)
	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()
}
Example #14
0
func cmdUpdate(c *cli.Context) {
	utils.FlagsRequired(c, []string{"rules"})

	fp := &FirewallProfile{
		Policy{},
	}

	var rules []Rule
	err := json.Unmarshal([]byte(c.String("rules")), &rules)
	utils.CheckError(err)
	fp.Profile.Rules = rules

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

	json, err := json.Marshal(fp)
	utils.CheckError(err)
	err, res, code := webservice.Put(endpoint, json)
	if res == nil {
		log.Fatal(err)
	}
	utils.CheckError(err)
	utils.CheckReturnCode(code, res)
}