Ejemplo n.º 1
0
func deleteIP(client *clc.Client) cli.Command {
	return cli.Command{
		Name:    "delete",
		Aliases: []string{"d"},
		Usage:   "delete public ip",
		Flags: []cli.Flag{
			cli.StringFlag{Name: "name, n", Usage: "server name [required]"},
			cli.StringFlag{Name: "ip", Usage: "ip [required]"},
		},
		Before: func(c *cli.Context) error {
			return util.CheckStringFlag(c, "name", "ip")
		},
		Action: func(c *cli.Context) {
			client, err := util.MaybeLoadConfig(c, client)
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			resp, err := client.Server.DeletePublicIP(c.String("name"), c.String("ip"))
			if err != nil {
				fmt.Printf("err %s\n", err)
				return
			}
			b, err := json.MarshalIndent(resp, "", "  ")
			if err != nil {
				fmt.Printf("%s", err)
				return
			}
			fmt.Printf("%s\n", b)
		},
	}
}
Ejemplo n.º 2
0
func restore(client *clc.Client) cli.Command {
	return cli.Command{
		Name:    "restore",
		Aliases: []string{"r"},
		Usage:   "restore server",
		Flags: []cli.Flag{
			cli.StringFlag{Name: "name, n", Usage: "name of server to restore [required]"},
			cli.StringFlag{Name: "group, g", Usage: "group for server to restore to [required]"},
		},
		Before: func(c *cli.Context) error {
			return util.CheckStringFlag(c, "name", "group")
		},
		Action: func(c *cli.Context) {
			client, err := util.MaybeLoadConfig(c, client)
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			resp, err := client.Server.Restore(c.String("name"), c.String("group"))
			if err != nil {
				fmt.Printf("failed to restore %s", c.String("name"))
				return
			}
			b, err := json.MarshalIndent(resp, "", "  ")
			if err != nil {
				fmt.Printf("%s", err)
				return
			}
			fmt.Printf("%s\n", b)
		},
	}
}
Ejemplo n.º 3
0
func create(client *clc.Client) cli.Command {
	return cli.Command{
		Name:        "create",
		Aliases:     []string{"c"},
		Usage:       "create server",
		Description: "example: clc server create -n 'my cool server' -c 1 -m 1 -g [group id] -t standard --ubuntu-14",
		Flags:       append(createFlags(), templateFlags()...),
		Before: func(c *cli.Context) error {
			err := util.CheckStringFlag(c, "name", "cpu", "memory", "group")
			if err == nil {
				err = util.CheckForEitherBooleanFlag(c, "standard", "hyperscale")
			}
			return err
		},
		Action: func(c *cli.Context) {
			client, err := util.MaybeLoadConfig(c, client)
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			source, err := findTemplateInContext(c)
			if err != nil {
				return
			}
			server := server.Server{
				Name:           c.String("name"),
				CPU:            c.Int("cpu"),
				MemoryGB:       c.Int("memory"),
				GroupID:        c.String("group"),
				SourceServerID: source,
				Type:           deriveServerType(c),
			}
			server.Password = c.String("password")
			server.Description = c.String("description")
			server.IPaddress = c.String("ip")
			server.IsManagedOS = c.Bool("managed")
			server.PrimaryDNS = c.String("primaryDNS")
			server.SecondaryDNS = c.String("secondaryDNS")
			server.NetworkID = c.String("network")
			server.Storagetype = deriveStorageType(c)

			resp, err := client.Server.Create(server)
			if err != nil {
				fmt.Printf("failed to create %s", server.Name)
				return
			}
			b, err := json.MarshalIndent(resp, "", "  ")
			if err != nil {
				fmt.Printf("%s", err)
				return
			}
			fmt.Printf("%s\n", b)
		},
	}
}
Ejemplo n.º 4
0
func createIP(client *clc.Client) cli.Command {
	return cli.Command{
		Name:    "add",
		Aliases: []string{"a"},
		Usage:   "add public ip to server",
		Flags: []cli.Flag{
			cli.StringFlag{Name: "name, n", Usage: "server name [required]"},
			cli.StringSliceFlag{Name: "tcp", Usage: "provide a port [8080] or a port range [8080:8082]"},
			cli.StringSliceFlag{Name: "udp", Usage: "provide a port [8080] or a port range [8080:8082]"},
			cli.StringSliceFlag{Name: "restriction, r", Usage: "provide an ip subnet to restrict to access the public ip [ex. 10.0.0.1/24 (must be cidr notation)]"},
		},
		Before: func(c *cli.Context) error {
			err := util.CheckStringFlag(c, "name")
			if err == nil {
				err = util.CheckForAnyOfStringSliceFlag(c, "tcp", "udp")
			}
			return err
		},
		Action: func(c *cli.Context) {
			client, err := util.MaybeLoadConfig(c, client)
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			ports := make([]server.Port, 0)
			tcps, err := parsePort("tcp", c.StringSlice("tcp"))
			if err != nil {
				fmt.Println(err.Error())
			}
			ports = append(ports, tcps...)
			udps, err := parsePort("udp", c.StringSlice("udp"))
			if err != nil {
				fmt.Println(err.Error())
			}
			ports = append(ports, udps...)
			restrictions := make([]server.SourceRestriction, 0)
			for _, v := range c.StringSlice("restriction") {
				restrictions = append(restrictions, server.SourceRestriction{CIDR: v})
			}

			ip := server.PublicIP{Ports: ports}
			resp, err := client.Server.AddPublicIP(c.String("name"), ip)
			if err != nil {
				fmt.Printf("err %s\n", err)
				return
			}
			b, err := json.MarshalIndent(resp, "", "  ")
			if err != nil {
				fmt.Printf("%s", err)
				return
			}
			fmt.Printf("%s\n", b)
		},
	}
}
Ejemplo n.º 5
0
func create(client *clc.Client) cli.Command {
	return cli.Command{
		Name:    "create",
		Aliases: []string{"c"},
		Usage:   "create group",
		Flags: []cli.Flag{
			cli.StringFlag{Name: "name, n", Usage: "group name [required]"},
			cli.StringFlag{Name: "parent, p", Usage: "parent group id [required]"},
			cli.StringFlag{Name: "description, d", Usage: "group description"},
		},
		Before: func(c *cli.Context) error {
			return util.CheckStringFlag(c, "name", "parent")
		},
		Action: func(c *cli.Context) {
			client, err := util.MaybeLoadConfig(c, client)
			if err != nil {
				fmt.Println(err.Error())
				return
			}
			g := group.Group{
				Name:          c.String("name"),
				ParentGroupID: c.String("parent"),
				Description:   c.String("description"),
			}
			resp, err := client.Group.Create(g)
			if err != nil {
				fmt.Printf("failed to create %s", c.String("name"))
				return
			}
			b, err := json.MarshalIndent(resp, "", "  ")
			if err != nil {
				fmt.Printf("%s", err)
				return
			}
			fmt.Printf("%s\n", b)
		},
	}
}