This repository has been archived by the owner on Jan 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1ce4341
Showing
14 changed files
with
2,369 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
glide.lock | ||
dist | ||
vendor | ||
vcloud-cli |
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,11 @@ | ||
# .goreleaser.yml | ||
# Build customization | ||
builds: | ||
- main: main.go | ||
binary: vcloud-cli | ||
goos: | ||
- windows | ||
- darwin | ||
- linux | ||
goarch: | ||
- amd64 |
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,9 @@ | ||
language: go | ||
go: 1.8.1 | ||
install: make setup | ||
script: make ci | ||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) | ||
- test -n "$TRAVIS_TAG" && curl -sL http://git.io/goreleaser | bash | ||
notifications: | ||
email: false |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Carlos Alexandro Becker | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,27 @@ | ||
# a cli for the vcloud api | ||
|
||
## api spec | ||
|
||
https://pubs.vmware.com/vcd-55/topic/com.vmware.ICbase/PDF/vcd_55_api_guide.pdf | ||
https://pubs.vmware.com/vca/index.jsp#com.vmware.vcloud.api.doc_56/GUID-F4BF9D5D-EF66-4D36-A6EB-2086703F6E37.html | ||
|
||
## usage | ||
|
||
set the following env vars | ||
* VCD_URL | ||
* VCD_USER | ||
* VCD_PASSWORD | ||
* VCD_ORG | ||
|
||
explore the possiblities of the cli by using the help. | ||
|
||
the command structure of the vcloud-cli: | ||
`vcloud-cli --network query allocatedips` | ||
|
||
`query` --> root command | ||
`allocatedips` --> sub command | ||
`--network` --> argument for the last command | ||
|
||
at every level you can use the help: | ||
* `vcloud-cli query --help` | ||
* `vcloud-cli query allocatedips --help` |
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,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/floriankammermann/vcloud-cli/vcdapi" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var networkname string | ||
|
||
// queryCmd represents the query command | ||
var queryCmd = &cobra.Command{ | ||
Use: "query", | ||
Short: "execute queries", | ||
Long: "execute queries", | ||
} | ||
|
||
var allocatedipCmd = &cobra.Command{ | ||
Use: "allocatedip", | ||
Short: "allocatedip for an org network", | ||
Long: "get all allocated ips of an org network", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
|
||
if len(networkname) > 0 { | ||
url := viper.GetString("url") | ||
user := viper.GetString("user") | ||
password := viper.GetString("password") | ||
org := viper.GetString("org") | ||
vcdapi.GetAuthToken(url, user, password, org) | ||
vcdapi.GetAllocatedIpsForNetworkName(url, networkname) | ||
} else { | ||
fmt.Println("you have to provide the networkname") | ||
} | ||
}, | ||
} | ||
|
||
var vmCommand = &cobra.Command{ | ||
Use: "vapp", | ||
Short: "vApps of org", | ||
Long: "show all vApps of the org", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
url := viper.GetString("url") | ||
user := viper.GetString("user") | ||
password := viper.GetString("password") | ||
org := viper.GetString("org") | ||
vcdapi.GetAuthToken(url, user, password, org) | ||
vcdapi.GetAllVApp(url) | ||
}, | ||
} | ||
|
||
func init() { | ||
queryCmd.AddCommand(allocatedipCmd) | ||
allocatedipCmd.Flags().StringVarP(&networkname, "network", "n", "", "network name to search allocated ips on") | ||
queryCmd.AddCommand(vmCommand) | ||
RootCmd.AddCommand(queryCmd) | ||
} |
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,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// RootCmd represents the base command when called without any subcommands | ||
var RootCmd = &cobra.Command{ | ||
Use: "vcloud-cli", | ||
Short: "a command line interface for the vcloud director api", | ||
Long: `a command line interface for the vcloud director api`, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
|
||
RootCmd.PersistentFlags().String("url", "", "url of vcloud director api") | ||
RootCmd.PersistentFlags().String("user", "", "Port to run Application server on") | ||
RootCmd.PersistentFlags().String( "password", "", "password of vcloud director api") | ||
RootCmd.PersistentFlags().String("org", "", "org of vcloud director api") | ||
viper.BindPFlag("url", RootCmd.PersistentFlags().Lookup("url")) | ||
viper.BindPFlag("user", RootCmd.PersistentFlags().Lookup("user")) | ||
viper.BindPFlag("password", RootCmd.PersistentFlags().Lookup("password")) | ||
viper.BindPFlag("org", RootCmd.PersistentFlags().Lookup("org")) | ||
|
||
viper.SetEnvPrefix("vcd") // will be uppercased automatically | ||
viper.AutomaticEnv() | ||
|
||
url := viper.GetString("url") | ||
if len(url) == 0 { | ||
fmt.Println("url has to be set, either as env var VCD_URL or as flag url") | ||
os.Exit(1) | ||
} | ||
user := viper.GetString("user") | ||
if len(user) == 0 { | ||
fmt.Println("user has to be set, either as env var VCD_USER or as flag user") | ||
os.Exit(1) | ||
} | ||
password := viper.GetString("password") | ||
if len(password) == 0 { | ||
fmt.Println("password has to be set, either as env var VCD_PASSWORD or as flag password") | ||
os.Exit(1) | ||
} | ||
org := viper.GetString("org") | ||
if len(org) == 0 { | ||
fmt.Println("user has to be set, either as env var VCD_ORG or as flag org") | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("VCD_URL: [%s]\n", url) | ||
fmt.Printf("VCD_USER: [%s]\n", user) | ||
fmt.Printf("VCD_PASSWORD: [%s]\n", "***************") | ||
fmt.Printf("VCD_ORG: [%s]\n", org) | ||
} |
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,5 @@ | ||
package: github.com/floriankammermann/vcloud-cli | ||
import: | ||
- package: github.com/urfave/cli | ||
- package: github.com/spf13/cobra | ||
- package: github.com/spf13/viper |
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,14 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/floriankammermann/vcloud-cli/cmd" | ||
"os" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
if err := cmd.RootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.