Exemplo n.º 1
0
	Aliases: []string{"resize"},
	Short:   "Upgrade an instance",
	Example: "civo instance upgrade --size g1.medium [name or ID]",
	Long:    `Upgrade the CPU, RAM and SSD disk for an instance with the specifed name or partial/full ID`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {
			fmt.Println("You need to specify a name or a partial/whole ID")
			os.Exit(-1)
		}
		if instanceUpgradeSize == "" {
			fmt.Println("You need to specify a size with --size to specify the new size")
			os.Exit(-3)
		}

		search := args[0]
		id := api.InstanceFind(search)
		if id == "" {
			fmt.Println("Couldn't find a single instance based on that name or partial/whole ID, it must match exactly one instance")
			os.Exit(-1)
		}

		_, err := api.InstanceUpgrade(id, instanceUpgradeSize)
		if err != nil {
			errorColor := color.New(color.FgRed, color.Bold).SprintFunc()
			fmt.Println(errorColor("An error occured:"), err.Error())
			return
		}
		fmt.Printf("Resizing instance with ID %s to %s\n", id, instanceUpgradeSize)
	},
}
Exemplo n.º 2
0
	Use:     "create",
	Aliases: []string{"new", "backup"},
	Short:   "Create a new snapshot",
	Example: "civo snapshot create --name my-backup --instance my-host.example.com",
	Long:    `Create a new snapshot of the specified instance with the given name`,
	Run: func(cmd *cobra.Command, args []string) {
		if snapshotCreateName == "" && len(args) > 0 {
			snapshotCreateName = args[0]
		}
		if snapshotCreateInstanceID == "" && snapshotCreateName != "" && len(args) > 0 {
			snapshotCreateInstanceID = args[0]
		} else if len(args) > 1 {
			snapshotCreateInstanceID = args[1]
		}

		instanceID := api.InstanceFind(snapshotCreateInstanceID)
		if instanceID == "" {
			fmt.Println("Couldn't find a single instance based on that name or partial/whole ID, it must match exactly one instance")
			os.Exit(-1)
		}

		_, err := api.SnapshotCreate(snapshotCreateName, instanceID, snapshotCreateSafe)
		if err != nil {
			errorColor := color.New(color.FgRed, color.Bold).SprintFunc()
			fmt.Println(errorColor("An error occured:"), err.Error())
			return
		}
		fmt.Printf("Creating a snapshot of `%s` with name '%s'\n", instanceID, snapshotCreateName)
	},
}