-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Joshd/sc 113095/api cli changes for vms (#414)
* vm list * Adding vm versions * Adding vm rm * Adding VM create * Added vm update ttl * adding group ls for vm
- Loading branch information
Showing
25 changed files
with
1,262 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/replicatedhq/replicated/pkg/credentials" | ||
"github.com/replicatedhq/replicated/pkg/kotsclient" | ||
"github.com/replicatedhq/replicated/pkg/platformclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitVMCommand(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "vm", | ||
Short: "Manage test vms", | ||
Long: ``, | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func (r *runners) initVMClient() error { | ||
if apiToken == "" { | ||
creds, err := credentials.GetCurrentCredentials() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
apiToken = creds.APIToken | ||
} | ||
|
||
httpClient := platformclient.NewHTTPClient(platformOrigin, apiToken) | ||
kotsAPI := &kotsclient.VendorV3Client{HTTPClient: *httpClient} | ||
r.kotsAPI = kotsAPI | ||
return nil | ||
} | ||
|
||
func (r *runners) completeVMIDs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
err := r.initVMClient() | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
var vmIDs []string | ||
vms, err := r.kotsAPI.ListVMs(false, nil, nil) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
for _, vm := range vms { | ||
vmIDs = append(vmIDs, vm.ID) | ||
} | ||
return vmIDs, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
func (r *runners) completeVMNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
err := r.initVMClient() | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
var vmNames []string | ||
vms, err := r.kotsAPI.ListVMs(false, nil, nil) | ||
if err != nil { | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
|
||
for _, vm := range vms { | ||
vmNames = append(vmNames, vm.Name) | ||
} | ||
return vmNames, cobra.ShellCompDirectiveNoFileComp | ||
} |
Oops, something went wrong.