Skip to content

Commit

Permalink
Merge pull request #55 from liquidweb/cloud-ssh
Browse files Browse the repository at this point in the history
Add ssh, dedicated, and asset commands
  • Loading branch information
sgsullivan committed Oct 26, 2020
2 parents 146483b + 8f53d1c commit c3a6cf3
Show file tree
Hide file tree
Showing 22 changed files with 863 additions and 37 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ install: security
scripts/build/install

security:
#go get github.com/securego/gosec/cmd/gosec
@gosec ./...
@gosec --exclude=G204 ./...

clean:
rm -rf _exe/
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ Usage:
lw [command]
Available Commands:
asset All things assets
auth authentication actions
cloud Interact with LiquidWeb's Cloud platform.
cloud Interact with LiquidWeb's Cloud platform
completion Generate completion script
dedicated All things dedicated server
help Help about any command
network network actions
plan Process YAML plan file
ssh SSH to a Server
version show build information
Flags:
Expand Down Expand Up @@ -72,6 +76,7 @@ Current commands supported in a `plan` file:
- cloud server create
- cloud server resize
- cloud template restore
- ssh

Example:

Expand All @@ -93,6 +98,8 @@ cloud:
bandwidth: "SS.5000"
```

You can find more examples of plans in `examples/plans`.

### Plan Variables

Plan yaml can make use of golang's template variables. Allows variables to be passed on the
Expand Down
40 changes: 40 additions & 0 deletions cmd/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © LiquidWeb
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)

var assetCmd = &cobra.Command{
Use: "asset",
Short: "All things assets",
Long: `An asset is an individual component on an account.
For a full list of capabilities, please refer to the "Available Commands" section.`,
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
lwCliInst.Die(err)
}
os.Exit(1)
},
}

func init() {
rootCmd.AddCommand(assetCmd)
}
81 changes: 81 additions & 0 deletions cmd/assetDetails.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright © LiquidWeb
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/types/api"
"github.com/liquidweb/liquidweb-cli/validate"
)

var assetDetailsCmdUniqIdFlag []string

var assetDetailsCmd = &cobra.Command{
Use: "details",
Short: "Get details of a specific asset",
Long: `Get details of a specific asset.
An asset is an individual component on an account. Assets have categories.
`,
Run: func(cmd *cobra.Command, args []string) {
jsonFlag, _ := cmd.Flags().GetBool("json")

for _, uniqId := range assetDetailsCmdUniqIdFlag {
validateFields := map[interface{}]interface{}{
uniqId: "UniqId",
}
if err := validate.Validate(validateFields); err != nil {
fmt.Printf("%s ... skipping\n", err)
continue
}

var details apiTypes.Subaccnt
apiArgs := map[string]interface{}{
"uniq_id": uniqId,
"alsowith": []string{"categories"},
}

if err := lwCliInst.CallLwApiInto("bleed/asset/details", apiArgs, &details); err != nil {
lwCliInst.Die(err)
}

if jsonFlag {
pretty, err := lwCliInst.JsonEncodeAndPrettyPrint(details)
if err != nil {
lwCliInst.Die(err)
}
fmt.Print(pretty)
} else {
fmt.Print(details)
}
}
},
}

func init() {
assetCmd.AddCommand(assetDetailsCmd)

assetDetailsCmd.Flags().Bool("json", false, "output in json format")
assetDetailsCmd.Flags().StringSliceVar(&assetDetailsCmdUniqIdFlag, "uniq-id", []string{},
"uniq-id of the asset. For multiple, must be ',' separated")

if err := assetDetailsCmd.MarkFlagRequired("uniq-id"); err != nil {
lwCliInst.Die(err)
}
}
96 changes: 96 additions & 0 deletions cmd/assetList.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright © LiquidWeb
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/liquidweb/liquidweb-cli/instance"
"github.com/liquidweb/liquidweb-cli/types/api"
)

var assetListCmdCategoriesFlag []string

var assetListCmd = &cobra.Command{
Use: "list",
Short: "List assets on your account",
Long: `List assets on your account.
An asset is an individual component on an account. Assets have categories.
Examples:
* List all assets in the Provisioned and DNS categories:
- lw asset list --categories Provisioned,DNS
* List all dedicated servers:
- lw asset list --categories StrictDedicated
`,
Run: func(cmd *cobra.Command, args []string) {
jsonFlag, _ := cmd.Flags().GetBool("json")

apiArgs := map[string]interface{}{
"alsowith": []string{"categories"},
}

if len(assetListCmdCategoriesFlag) > 0 {
apiArgs["category"] = assetListCmdCategoriesFlag
}

methodArgs := instance.AllPaginatedResultsArgs{
Method: "bleed/asset/list",
ResultsPerPage: 100,
MethodArgs: apiArgs,
}
results, err := lwCliInst.AllPaginatedResults(&methodArgs)
if err != nil {
lwCliInst.Die(err)
}

if jsonFlag {
pretty, err := lwCliInst.JsonEncodeAndPrettyPrint(results)
if err != nil {
lwCliInst.Die(err)
}
fmt.Print(pretty)
} else {
cnt := 1
for _, item := range results.Items {

var details apiTypes.Subaccnt
if err := instance.CastFieldTypes(item, &details); err != nil {
lwCliInst.Die(err)
}

fmt.Printf("%d.) ", cnt)
fmt.Print(details)
cnt++
}
}
},
}

func init() {
assetCmd.AddCommand(assetListCmd)

assetListCmd.Flags().Bool("json", false, "output in json format")

assetListCmd.Flags().StringSliceVar(&assetListCmdCategoriesFlag, "categories",
[]string{}, "categories to include separated by ','")

}
2 changes: 1 addition & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var cloudCmd = &cobra.Command{
Use: "cloud",
Short: "Interact with LiquidWeb's Cloud platform.",
Short: "Interact with LiquidWeb's Cloud platform",
Long: `Command line interface to LiquidWeb's Cloud platform.
For a full list of capabilities, please refer to the "Available Commands" section.`,
Expand Down
32 changes: 31 additions & 1 deletion cmd/cloudServerCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Requires various flags. Please see the flag section of help.
Examples:
# Create a Cloud Server on a Private Parent named "private"
'cloud server create --private-parent private --memory 1024 --diskspace 40 --vcpu 2 --zone 40460 --template DEBIAN_10_UNMANAGED'
'cloud server create --private-parent private --memory 1024 --diskspace 40 --vcpu 2 --template DEBIAN_10_UNMANAGED'
# Create a Cloud Server on config-id 1
'cloud server create --config-id 1 --template DEBIAN_10_UNMANAGED --zone 40460'
Expand All @@ -55,6 +55,36 @@ These examples use default values for various flags, such as password, type, ssh
For a list of Templates, Configs, and Region/Zones, see 'cloud server options --configs --templates --zones'
For a list of images, see 'cloud images list'
For a list of backups, see 'cloud backups list'
Plan Example:
---
cloud:
server:
create:
- type: "SS.VPS.WIN"
password: "1fk4ds$jktl43u90dsa"
template: "WINDOWS_2019_UNMANAGED"
zone: 40460
hostname: "db1.dev.addictmud.org"
ips: 1
public-ssh-key: ""
config-id: 88
backup-days: 5
bandwidth: "SS.5000"
backup-id: -1
image-id: -1
pool-ips:
- "10.111.12.13"
- "10.12.13.14"
private-parent: "my pp"
memory: 0
diskspace: 0
vcpu: 0
winav: ""
ms-sql: ""
lw plan --file /tmp/cloud.server.create.yaml
`,
Run: func(cmd *cobra.Command, args []string) {
params := &instance.CloudServerCreateParams{}
Expand Down
46 changes: 24 additions & 22 deletions cmd/cloudServerDetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"

Expand All @@ -28,6 +27,7 @@ import (

var blockStorageVolumeList apiTypes.MergedPaginatedList
var fetchedBlockStorageVolumes bool
var cloudServerDetailsCmdUniqIdFlag []string

var cloudServerDetailsCmd = &cobra.Command{
Use: "details",
Expand All @@ -39,32 +39,33 @@ You can check this methods API documentation for what the returned fields mean:
https://cart.liquidweb.com/storm/api/docs/bleed/Storm/Server.html#method_details
`,
Run: func(cmd *cobra.Command, args []string) {
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
jsonFlag, _ := cmd.Flags().GetBool("json")

validateFields := map[interface{}]interface{}{
uniqIdFlag: "UniqId",
}
if err := validate.Validate(validateFields); err != nil {
lwCliInst.Die(err)
}

var details apiTypes.CloudServerDetails
if err := lwCliInst.CallLwApiInto("bleed/storm/server/details",
map[string]interface{}{"uniq_id": uniqIdFlag}, &details); err != nil {
lwCliInst.Die(err)
}
for _, uniqId := range cloudServerDetailsCmdUniqIdFlag {
validateFields := map[interface{}]interface{}{
uniqId: "UniqId",
}
if err := validate.Validate(validateFields); err != nil {
fmt.Printf("%s ... skipping\n", err)
continue
}

if jsonFlag {
pretty, err := lwCliInst.JsonEncodeAndPrettyPrint(details)
if err != nil {
var details apiTypes.CloudServerDetails
if err := lwCliInst.CallLwApiInto("bleed/storm/server/details",
map[string]interface{}{"uniq_id": uniqId}, &details); err != nil {
lwCliInst.Die(err)
}
fmt.Printf(pretty)
os.Exit(0)
}

_printExtendedCloudServerDetails(&details)
if jsonFlag {
pretty, err := lwCliInst.JsonEncodeAndPrettyPrint(details)
if err != nil {
lwCliInst.Die(err)
}
fmt.Print(pretty)
} else {
_printExtendedCloudServerDetails(&details)
}
}
},
}

Expand Down Expand Up @@ -122,7 +123,8 @@ func init() {
cloudServerCmd.AddCommand(cloudServerDetailsCmd)

cloudServerDetailsCmd.Flags().Bool("json", false, "output in json format")
cloudServerDetailsCmd.Flags().String("uniq-id", "", "get details of this uniq-id")
cloudServerDetailsCmd.Flags().StringSliceVar(&cloudServerDetailsCmdUniqIdFlag, "uniq-id", []string{},
"uniq-id of the cloud server. For multiple, must be ',' separated")

if err := cloudServerDetailsCmd.MarkFlagRequired("uniq-id"); err != nil {
lwCliInst.Die(err)
Expand Down
Loading

0 comments on commit c3a6cf3

Please sign in to comment.