Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit 1ce4341

Browse files
added inital version
0 parents  commit 1ce4341

File tree

14 files changed

+2369
-0
lines changed

14 files changed

+2369
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
glide.lock
3+
dist
4+
vendor
5+
vcloud-cli

.goreleaser.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# .goreleaser.yml
2+
# Build customization
3+
builds:
4+
- main: main.go
5+
binary: vcloud-cli
6+
goos:
7+
- windows
8+
- darwin
9+
- linux
10+
goarch:
11+
- amd64

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: go
2+
go: 1.8.1
3+
install: make setup
4+
script: make ci
5+
after_success:
6+
- bash <(curl -s https://codecov.io/bash)
7+
- test -n "$TRAVIS_TAG" && curl -sL http://git.io/goreleaser | bash
8+
notifications:
9+
email: false

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Carlos Alexandro Becker
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# a cli for the vcloud api
2+
3+
## api spec
4+
5+
https://pubs.vmware.com/vcd-55/topic/com.vmware.ICbase/PDF/vcd_55_api_guide.pdf
6+
https://pubs.vmware.com/vca/index.jsp#com.vmware.vcloud.api.doc_56/GUID-F4BF9D5D-EF66-4D36-A6EB-2086703F6E37.html
7+
8+
## usage
9+
10+
set the following env vars
11+
* VCD_URL
12+
* VCD_USER
13+
* VCD_PASSWORD
14+
* VCD_ORG
15+
16+
explore the possiblities of the cli by using the help.
17+
18+
the command structure of the vcloud-cli:
19+
`vcloud-cli --network query allocatedips`
20+
21+
`query` --> root command
22+
`allocatedips` --> sub command
23+
`--network` --> argument for the last command
24+
25+
at every level you can use the help:
26+
* `vcloud-cli query --help`
27+
* `vcloud-cli query allocatedips --help`

cmd/query.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/floriankammermann/vcloud-cli/vcdapi"
8+
"github.com/spf13/viper"
9+
)
10+
11+
var networkname string
12+
13+
// queryCmd represents the query command
14+
var queryCmd = &cobra.Command{
15+
Use: "query",
16+
Short: "execute queries",
17+
Long: "execute queries",
18+
}
19+
20+
var allocatedipCmd = &cobra.Command{
21+
Use: "allocatedip",
22+
Short: "allocatedip for an org network",
23+
Long: "get all allocated ips of an org network",
24+
Run: func(cmd *cobra.Command, args []string) {
25+
26+
if len(networkname) > 0 {
27+
url := viper.GetString("url")
28+
user := viper.GetString("user")
29+
password := viper.GetString("password")
30+
org := viper.GetString("org")
31+
vcdapi.GetAuthToken(url, user, password, org)
32+
vcdapi.GetAllocatedIpsForNetworkName(url, networkname)
33+
} else {
34+
fmt.Println("you have to provide the networkname")
35+
}
36+
},
37+
}
38+
39+
var vmCommand = &cobra.Command{
40+
Use: "vapp",
41+
Short: "vApps of org",
42+
Long: "show all vApps of the org",
43+
Run: func(cmd *cobra.Command, args []string) {
44+
url := viper.GetString("url")
45+
user := viper.GetString("user")
46+
password := viper.GetString("password")
47+
org := viper.GetString("org")
48+
vcdapi.GetAuthToken(url, user, password, org)
49+
vcdapi.GetAllVApp(url)
50+
},
51+
}
52+
53+
func init() {
54+
queryCmd.AddCommand(allocatedipCmd)
55+
allocatedipCmd.Flags().StringVarP(&networkname, "network", "n", "", "network name to search allocated ips on")
56+
queryCmd.AddCommand(vmCommand)
57+
RootCmd.AddCommand(queryCmd)
58+
}

cmd/root.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"github.com/spf13/cobra"
7+
"github.com/spf13/viper"
8+
)
9+
10+
// RootCmd represents the base command when called without any subcommands
11+
var RootCmd = &cobra.Command{
12+
Use: "vcloud-cli",
13+
Short: "a command line interface for the vcloud director api",
14+
Long: `a command line interface for the vcloud director api`,
15+
}
16+
17+
// Execute adds all child commands to the root command and sets flags appropriately.
18+
// This is called by main.main(). It only needs to happen once to the rootCmd.
19+
func Execute() {
20+
if err := RootCmd.Execute(); err != nil {
21+
fmt.Println(err)
22+
os.Exit(1)
23+
}
24+
}
25+
26+
func init() {
27+
28+
RootCmd.PersistentFlags().String("url", "", "url of vcloud director api")
29+
RootCmd.PersistentFlags().String("user", "", "Port to run Application server on")
30+
RootCmd.PersistentFlags().String( "password", "", "password of vcloud director api")
31+
RootCmd.PersistentFlags().String("org", "", "org of vcloud director api")
32+
viper.BindPFlag("url", RootCmd.PersistentFlags().Lookup("url"))
33+
viper.BindPFlag("user", RootCmd.PersistentFlags().Lookup("user"))
34+
viper.BindPFlag("password", RootCmd.PersistentFlags().Lookup("password"))
35+
viper.BindPFlag("org", RootCmd.PersistentFlags().Lookup("org"))
36+
37+
viper.SetEnvPrefix("vcd") // will be uppercased automatically
38+
viper.AutomaticEnv()
39+
40+
url := viper.GetString("url")
41+
if len(url) == 0 {
42+
fmt.Println("url has to be set, either as env var VCD_URL or as flag url")
43+
os.Exit(1)
44+
}
45+
user := viper.GetString("user")
46+
if len(user) == 0 {
47+
fmt.Println("user has to be set, either as env var VCD_USER or as flag user")
48+
os.Exit(1)
49+
}
50+
password := viper.GetString("password")
51+
if len(password) == 0 {
52+
fmt.Println("password has to be set, either as env var VCD_PASSWORD or as flag password")
53+
os.Exit(1)
54+
}
55+
org := viper.GetString("org")
56+
if len(org) == 0 {
57+
fmt.Println("user has to be set, either as env var VCD_ORG or as flag org")
58+
os.Exit(1)
59+
}
60+
61+
fmt.Printf("VCD_URL: [%s]\n", url)
62+
fmt.Printf("VCD_USER: [%s]\n", user)
63+
fmt.Printf("VCD_PASSWORD: [%s]\n", "***************")
64+
fmt.Printf("VCD_ORG: [%s]\n", org)
65+
}

glide.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package: github.com/floriankammermann/vcloud-cli
2+
import:
3+
- package: github.com/urfave/cli
4+
- package: github.com/spf13/cobra
5+
- package: github.com/spf13/viper

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"github.com/floriankammermann/vcloud-cli/cmd"
5+
"os"
6+
"fmt"
7+
)
8+
9+
func main() {
10+
if err := cmd.RootCmd.Execute(); err != nil {
11+
fmt.Println(err)
12+
os.Exit(1)
13+
}
14+
}

0 commit comments

Comments
 (0)