├── cmd ├── cmd_suite_test.go ├── manifest_delete.go ├── manifest_update.go ├── manifest_retrieve.go ├── root.go ├── manifest.go ├── get_nodes.go ├── manifest_test.go ├── manifest_create.go ├── commands_test.go ├── get_nodes_test.go └── target.go ├── .gitignore ├── glide.yaml ├── ci ├── tasks │ ├── unit.sh │ ├── util.sh │ ├── build-candidate.sh │ ├── run-integration.sh │ ├── integration.sh │ └── cli-release.sh └── pipeline.yml ├── README.md ├── main.go ├── Makefile ├── glide.lock └── LICENSE /cmd/cmd_suite_test.go: -------------------------------------------------------------------------------- 1 | package cmd_test 2 | 3 | import ( 4 | . "github.com/onsi/ginkgo" 5 | . "github.com/onsi/gomega" 6 | 7 | "testing" 8 | ) 9 | 10 | func TestCmd(t *testing.T) { 11 | RegisterFailHandler(Fail) 12 | RunSpecs(t, "Cmd Suite") 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | bin 16 | *.coverprofile 17 | -------------------------------------------------------------------------------- /glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/RackHD/voyager-cli 2 | import: 3 | - package: github.com/fatih/color 4 | version: ~1.2.0 5 | - package: github.com/mitchellh/go-homedir 6 | - package: github.com/olekukonko/tablewriter 7 | - package: github.com/RackHD/voyager-houston 8 | version: ~33.0.0 9 | subpackages: 10 | - model 11 | - package: github.com/spf13/cobra 12 | testImport: 13 | - package: github.com/onsi/ginkgo 14 | version: ~1.2.0 15 | - package: github.com/onsi/gomega 16 | version: ~1.0.0 17 | subpackages: 18 | - ghttp 19 | -------------------------------------------------------------------------------- /ci/tasks/unit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e -x 4 | source voyager-cli/ci/tasks/util.sh 5 | 6 | check_param GITHUB_USER 7 | check_param GITHUB_PASSWORD 8 | 9 | echo -e "machine github.com\n login $GITHUB_USER\n password $GITHUB_PASSWORD" >> ~/.netrc 10 | 11 | export GOPATH=$PWD 12 | export PATH=$PATH:$GOPATH/bin 13 | mkdir -p $GOPATH/src/github.com/RackHD/ 14 | cp -r voyager-cli $GOPATH/src/github.com/RackHD/voyager-cli 15 | 16 | pushd $GOPATH/src/github.com/RackHD/voyager-cli 17 | make deps 18 | make build 19 | make unit-test 20 | echo "Unit test complete." 21 | popd 22 | -------------------------------------------------------------------------------- /ci/tasks/util.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e -x 3 | 4 | check_param() { 5 | local name=$1 6 | local value=$(eval echo '$'$name) 7 | if [ "$value" == 'replace-me' ]; then 8 | echo "environment variable $name must be set" 9 | exit 1 10 | fi 11 | } 12 | 13 | set_env() { 14 | WORK_DIR=${PWD} 15 | export GOPATH=${PWD} 16 | SOURCE_DIR=${GOPATH}/src/github.com/RackHD 17 | mkdir -p ${SOURCE_DIR} 18 | } 19 | 20 | build_binary() { 21 | cp -r $1 ${SOURCE_DIR}/$1 22 | pushd ${SOURCE_DIR}/$1 23 | make deps 24 | make build 25 | cp -r bin ${WORK_DIR}/build 26 | cp Dockerfile ${WORK_DIR}/build 27 | popd 28 | } 29 | -------------------------------------------------------------------------------- /ci/tasks/build-candidate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e -x 4 | source voyager-cli/ci/tasks/util.sh 5 | 6 | check_param GITHUB_USER 7 | check_param GITHUB_PASSWORD 8 | 9 | echo -e "machine github.com\n login $GITHUB_USER\n password $GITHUB_PASSWORD" >> ~/.netrc 10 | 11 | export GOPATH=$PWD 12 | export PATH=$PATH:$GOPATH/bin 13 | mkdir -p $GOPATH/src/github.com/RackHD/ 14 | cp -r voyager-cli $GOPATH/src/github.com/RackHD/voyager-cli 15 | 16 | export MCC_VERSION=$(cat $PWD/version/version) 17 | 18 | pushd $GOPATH/src/github.com/RackHD/voyager-cli 19 | make deps 20 | make build 21 | 22 | zip -rq voyager-cli-v${MCC_VERSION}.zip ./bin/* 23 | popd 24 | 25 | cp -r $GOPATH/src/github.com/RackHD/voyager-cli build 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # voyager-cli 2 | Command Line Interface for Project Voyager 3 | 4 | Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. 5 | 6 | ## Licensing 7 | 8 | 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 9 | 10 | 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. 11 | 12 | RackHD is a Trademark of Dell EMC 13 | -------------------------------------------------------------------------------- /ci/tasks/run-integration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e -x 4 | 5 | [[ -s "/home/emc/.gvm/scripts/gvm" ]] >/dev/null 2>/dev/null 6 | source "/home/emc/.gvm/scripts/gvm" >/dev/null 2>/dev/null 7 | 8 | PROJECT_PATH=$GOPATH/src/github.com/RackHD 9 | 10 | cleanUp() 11 | { 12 | # Don't exit on error here. All commands in this cleanUp must run, 13 | # even if some of them fail 14 | set +e 15 | 16 | # Clean up all cloned repos 17 | cd $GOPATH 18 | rm -rf $GOPATH/src 19 | } 20 | 21 | trap cleanUp EXIT 22 | 23 | pushd $PROJECT_PATH/voyager-cli 24 | echo "Testing Mission Control Center" 25 | 26 | make deps 27 | make build 28 | make integration-test 29 | 30 | echo "Mission Control Center PASS\n\n" 31 | popd 32 | 33 | exit 34 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2016 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "github.com/RackHD/voyager-cli/cmd" 18 | 19 | func main() { 20 | cmd.Execute() 21 | } 22 | -------------------------------------------------------------------------------- /ci/tasks/integration.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e -x 4 | source voyager-cli/ci/tasks/util.sh 5 | 6 | # Get the env ip from locks input 7 | export INTEGRATION_VM_IP=$(cat $PWD/it-env/metadata) 8 | 9 | check_param INTEGRATION_VM_IP 10 | check_param INTEGRATION_VM_SSH_KEY 11 | check_param INTEGRATION_VM_USER 12 | 13 | echo "$INTEGRATION_VM_SSH_KEY" > ssh.key 14 | chmod 400 ssh.key 15 | 16 | project_path=/home/emc/.gvm/pkgsets/go1.7/global/src/github.com/RackHD 17 | ssh -i ssh.key -o "StrictHostKeyChecking no" ${INTEGRATION_VM_USER}@${INTEGRATION_VM_IP} "rm -rf $project_path && mkdir -p $project_path" 18 | scp -i ssh.key -o "StrictHostKeyChecking no" -r voyager-cli ${INTEGRATION_VM_USER}@${INTEGRATION_VM_IP}:$project_path 19 | 20 | integration_file=$PWD/voyager-cli/ci/tasks/run-integration.sh 21 | ssh -i ssh.key -o "StrictHostKeyChecking no" ${INTEGRATION_VM_USER}@${INTEGRATION_VM_IP} 'bash -s' < $integration_file 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ORGANIZATION = RackHD 2 | PROJECT = voyager-cli 3 | BINARYNAME = mcc 4 | GOOUT = ./bin 5 | 6 | default: deps build test 7 | 8 | deps: 9 | go get github.com/onsi/ginkgo/ginkgo 10 | 11 | go get github.com/fatih/color 12 | go get github.com/onsi/gomega 13 | go get github.com/onsi/gomega/ghttp 14 | go get ./... 15 | env GOOS=windows go get ./... 16 | 17 | integration-test: build 18 | ginkgo -r -race -trace -cover -randomizeAllSpecs --slowSpecThreshold=30 --focus="\bINTEGRATION\b" 19 | 20 | unit-test: build 21 | ginkgo -r -race -trace -cover -randomizeAllSpecs --slowSpecThreshold=30 --focus="\bUNIT\b" 22 | 23 | test: build 24 | ginkgo -r -race -trace -cover -randomizeAllSpecs --slowSpecThreshold=30 25 | 26 | cover-cmd: test 27 | go tool cover -html=cmd/cmd.coverprofile 28 | 29 | build: build-Linux build-Mac build-Windows 30 | 31 | build-Linux: 32 | env GOOS=linux go build -o $(GOOUT)/linux/$(BINARYNAME) 33 | 34 | build-Mac: 35 | env GOOS=darwin go build -o $(GOOUT)/darwin/$(BINARYNAME) 36 | 37 | build-Windows: 38 | env GOOS=windows go build -o $(GOOUT)/windows/$(BINARYNAME).exe 39 | -------------------------------------------------------------------------------- /ci/tasks/cli-release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e -x 4 | source voyager-cli/ci/tasks/util.sh 5 | 6 | check_param GITHUB_EMAIL 7 | check_param GITHUB_USER 8 | check_param GITHUB_PASSWORD 9 | 10 | echo -e "machine github.com\n login $GITHUB_USER\n password $GITHUB_PASSWORD" >> ~/.netrc 11 | git config --global user.email ${GITHUB_EMAIL} 12 | git config --global user.name ${GITHUB_USER} 13 | git config --global push.default current 14 | 15 | export GOPATH=$PWD 16 | export PATH=$PATH:$GOPATH/bin 17 | mkdir -p $GOPATH/src/github.com/RackHD/ 18 | cp -r voyager-cli $GOPATH/src/github.com/RackHD/voyager-cli 19 | 20 | pushd $GOPATH/src/github.com/RackHD/voyager-cli 21 | make deps 22 | make build 23 | 24 | release_version=`cat version | tr -d '\n'` 25 | release_version=$((release_version+1)) 26 | printf ${release_version} > version 27 | 28 | git add version 29 | git commit -m ":airplane: New release v${release_version}" -m "[ci skip]" 30 | 31 | printf "Mission Control Center Release v${release_version}" > name 32 | printf "v${release_version}" > tag 33 | tar -czvf voyager-cli-v${release_version}.tar.gz ./bin/* 34 | zip -rq voyager-cli-v${release_version}.zip ./bin/* 35 | echo "New version released." 36 | popd 37 | 38 | cp -r $GOPATH/src/github.com/RackHD/voyager-cli release 39 | -------------------------------------------------------------------------------- /cmd/manifest_delete.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | // deleteCmd represents the delete command 24 | var deleteCmd = &cobra.Command{ 25 | Use: "delete", 26 | Short: "A brief description of your command", 27 | Long: `A longer description that spans multiple lines and likely contains examples 28 | and usage of using your command. For example: 29 | 30 | Cobra is a CLI library for Go that empowers applications. 31 | This application is a tool to generate the needed files 32 | to quickly create a Cobra application.`, 33 | Run: func(cmd *cobra.Command, args []string) { 34 | // TODO: Work your own magic here 35 | fmt.Println("delete called") 36 | }, 37 | } 38 | 39 | func init() { 40 | manifestCmd.AddCommand(deleteCmd) 41 | 42 | // Here you will define your flags and configuration settings. 43 | 44 | // Cobra supports Persistent Flags which will work for this command 45 | // and all subcommands, e.g.: 46 | // deleteCmd.PersistentFlags().String("foo", "", "A help for foo") 47 | 48 | // Cobra supports local flags which will only run when this command 49 | // is called directly, e.g.: 50 | // deleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 51 | 52 | } 53 | -------------------------------------------------------------------------------- /cmd/manifest_update.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | // updateCmd represents the update command 24 | var updateCmd = &cobra.Command{ 25 | Use: "update", 26 | Short: "A brief description of your command", 27 | Long: `A longer description that spans multiple lines and likely contains examples 28 | and usage of using your command. For example: 29 | 30 | Cobra is a CLI library for Go that empowers applications. 31 | This application is a tool to generate the needed files 32 | to quickly create a Cobra application.`, 33 | Run: func(cmd *cobra.Command, args []string) { 34 | // TODO: Work your own magic here 35 | fmt.Println("update called") 36 | }, 37 | } 38 | 39 | func init() { 40 | manifestCmd.AddCommand(updateCmd) 41 | 42 | // Here you will define your flags and configuration settings. 43 | 44 | // Cobra supports Persistent Flags which will work for this command 45 | // and all subcommands, e.g.: 46 | // updateCmd.PersistentFlags().String("foo", "", "A help for foo") 47 | 48 | // Cobra supports local flags which will only run when this command 49 | // is called directly, e.g.: 50 | // updateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 51 | 52 | } 53 | -------------------------------------------------------------------------------- /cmd/manifest_retrieve.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | // retrieveCmd represents the retrieve command 24 | var retrieveCmd = &cobra.Command{ 25 | Use: "retrieve", 26 | Short: "A brief description of your command", 27 | Long: `A longer description that spans multiple lines and likely contains examples 28 | and usage of using your command. For example: 29 | 30 | Cobra is a CLI library for Go that empowers applications. 31 | This application is a tool to generate the needed files 32 | to quickly create a Cobra application.`, 33 | Run: func(cmd *cobra.Command, args []string) { 34 | // TODO: Work your own magic here 35 | fmt.Println("retrieve called") 36 | }, 37 | } 38 | 39 | func init() { 40 | manifestCmd.AddCommand(retrieveCmd) 41 | 42 | // Here you will define your flags and configuration settings. 43 | 44 | // Cobra supports Persistent Flags which will work for this command 45 | // and all subcommands, e.g.: 46 | // retrieveCmd.PersistentFlags().String("foo", "", "A help for foo") 47 | 48 | // Cobra supports local flags which will only run when this command 49 | // is called directly, e.g.: 50 | // retrieveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 51 | 52 | } 53 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2016 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var cfgFile string 25 | 26 | // RootCmd represents the base command when called without any subcommands 27 | var RootCmd = &cobra.Command{ 28 | Use: "mcc", 29 | Short: "A CLI to interact with the Project Voyager Houston API", 30 | // Long: `A CLI to interact with the Project Voyager Houston API`, 31 | 32 | // Uncomment the following line if your bare application 33 | // has an action associated with it: 34 | // Run: func(cmd *cobra.Command, args []string) { }, 35 | } 36 | 37 | // Execute adds all child commands to the root command sets flags appropriately. 38 | // This is called by main.main(). It only needs to happen once to the rootCmd. 39 | func Execute() { 40 | if err := RootCmd.Execute(); err != nil { 41 | fmt.Println(err) 42 | os.Exit(-1) 43 | } 44 | } 45 | 46 | func init() { 47 | cobra.OnInitialize(initConfig) 48 | 49 | // Here you will define your flags and configuration settings. 50 | // Cobra supports Persistent Flags, which, if defined here, 51 | // will be global for your application. 52 | } 53 | 54 | // initConfig reads in config file and ENV variables if set. 55 | func initConfig() { 56 | 57 | } 58 | 59 | // InfoResponse is the response from the info call 60 | type InfoResponse struct { 61 | Name string 62 | } 63 | -------------------------------------------------------------------------------- /glide.lock: -------------------------------------------------------------------------------- 1 | hash: 206de8d6cb3a0acf69986caf7cbb5587fa6b249f78bafb5a61b1dca95e44b712 2 | updated: 2017-01-05T14:31:55.175527355-05:00 3 | imports: 4 | - name: github.com/fatih/color 5 | version: 34e4ee095d12986a2cef5ddb9aeb3b8cfcfea17c 6 | - name: github.com/inconshreveable/mousetrap 7 | version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75 8 | - name: github.com/mattn/go-colorable 9 | version: d228849504861217f796da67fae4f6e347643f15 10 | - name: github.com/mattn/go-isatty 11 | version: 30a891c33c7cde7b02a981314b4228ec99380cca 12 | - name: github.com/mattn/go-runewidth 13 | version: 737072b4e32b7a5018b4a7125da8d12de90e8045 14 | - name: github.com/mitchellh/go-homedir 15 | version: b8bc1bf767474819792c23f32d8286a45736f1c6 16 | - name: github.com/olekukonko/tablewriter 17 | version: 44e365d423f4f06769182abfeeae2b91be9d529b 18 | - name: github.com/RackHD/voyager-houston 19 | version: f5718ab666c72ef5736c8b69f410342be31fa16f 20 | subpackages: 21 | - model 22 | - name: github.com/spf13/cobra 23 | version: 1dd5ff2e11b6dca62fdcb275eb804b94607d8b06 24 | - name: github.com/spf13/pflag 25 | version: 25f8b5b07aece3207895bf19f7ab517eb3b22a40 26 | - name: golang.org/x/sys 27 | version: d75a52659825e75fff6158388dddc6a5b04f9ba5 28 | subpackages: 29 | - unix 30 | testImports: 31 | - name: github.com/onsi/ginkgo 32 | version: 462326b1628e124b23f42e87a8f2750e3c4e2d24 33 | subpackages: 34 | - config 35 | - internal/codelocation 36 | - internal/containernode 37 | - internal/failer 38 | - internal/leafnodes 39 | - internal/remote 40 | - internal/spec 41 | - internal/specrunner 42 | - internal/suite 43 | - internal/testingtproxy 44 | - internal/writer 45 | - reporters 46 | - reporters/stenographer 47 | - types 48 | - name: github.com/onsi/gomega 49 | version: a78ae492d53aad5a7a232d0d0462c14c400e3ee7 50 | subpackages: 51 | - format 52 | - ghttp 53 | - internal/assertion 54 | - internal/asyncassertion 55 | - internal/testingtsupport 56 | - matchers 57 | - matchers/support/goraph/bipartitegraph 58 | - matchers/support/goraph/edge 59 | - matchers/support/goraph/node 60 | - matchers/support/goraph/util 61 | - types 62 | -------------------------------------------------------------------------------- /cmd/manifest.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | "io/ioutil" 21 | "log" 22 | "net/url" 23 | "os" 24 | 25 | "github.com/fatih/color" 26 | homedir "github.com/mitchellh/go-homedir" 27 | "github.com/spf13/cobra" 28 | ) 29 | 30 | // manifestCmd represents the manifest command 31 | var manifestCmd = &cobra.Command{ 32 | Use: "manifest", 33 | Short: "Manifest for voyager configuration deployment.", 34 | Long: `A manifest that voyager uses to deploy and configure infrastructure. 35 | Usage: manifest [create|retrieve|update|delete]`, 36 | 37 | Run: func(cmd *cobra.Command, args []string) { 38 | }, 39 | } 40 | 41 | func init() { 42 | RootCmd.AddCommand(manifestCmd) 43 | 44 | // Here you will define your flags and configuration settings. 45 | 46 | // Cobra supports Persistent Flags which will work for this command 47 | // and all subcommands, e.g.: 48 | // manifestCmd.PersistentFlags().String("foo", "", "A help for foo") 49 | 50 | // Cobra supports local flags which will only run when this command 51 | // is called directly, e.g.: 52 | // manifestCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 53 | 54 | } 55 | 56 | // CheckMccTarget is a helper function that reads mcc target 57 | func CheckMccTarget() (url.URL, error) { 58 | dir, err := homedir.Dir() 59 | if err != nil { 60 | log.Fatal(err) 61 | } 62 | fileLocation := fmt.Sprintf("%s/.voyager", dir) 63 | 64 | url := url.URL{} 65 | // Read IP target from file 66 | _, err = os.Stat(fileLocation) 67 | if err != nil { 68 | color.Red("Cannot find mcc config file (expecting $HOME/.voyager)\n") 69 | return url, err 70 | } 71 | 72 | fileContent, err := ioutil.ReadFile(fileLocation) 73 | if err != nil { 74 | log.Fatal(err) 75 | } 76 | 77 | // Unmarshal data and print 78 | err = json.Unmarshal(fileContent, &url) 79 | if err != nil { 80 | log.Fatal(err) 81 | return url, err 82 | } 83 | return url, nil 84 | } 85 | -------------------------------------------------------------------------------- /cmd/get_nodes.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "net/http" 9 | "net/url" 10 | "os" 11 | 12 | "github.com/fatih/color" 13 | "github.com/mitchellh/go-homedir" 14 | "github.com/olekukonko/tablewriter" 15 | "github.com/spf13/cobra" 16 | ) 17 | 18 | // NodesResponse is ... 19 | type NodesResponse struct { 20 | ID string `json:"ID"` 21 | Type string `json:"Type"` 22 | Status string `json:"Status"` 23 | IP string `json:"IP"` 24 | } 25 | 26 | var nodesCmd = &cobra.Command{ 27 | Use: "nodes", 28 | Short: "List nodes' information", 29 | Long: `List nodes' ID, Type, Status 30 | Usage: mcc nodes`, 31 | 32 | Run: func(cmd *cobra.Command, args []string) { 33 | dir, err := homedir.Dir() 34 | if err != nil { 35 | log.Fatal(err) 36 | } 37 | urlObject := url.URL{} 38 | fileLocation := fmt.Sprintf("%s/.voyager", dir) 39 | 40 | // Read IP target from file 41 | _, err = os.Stat(fileLocation) 42 | if err != nil { 43 | color.Red("Cannot find mcc config file (expecting $HOME/.voyager)\n") 44 | return 45 | } 46 | 47 | fileContent, err := ioutil.ReadFile(fileLocation) 48 | if err != nil { 49 | log.Fatal(err) 50 | } 51 | 52 | // Unmarshal data and print 53 | err = json.Unmarshal(fileContent, &urlObject) 54 | if err != nil { 55 | log.Fatal(err) 56 | } 57 | 58 | // Send http GET request to IP target 59 | targetURL := fmt.Sprintf("%s://%s/nodes", urlObject.Scheme, urlObject.Host) 60 | res, err := http.Get(targetURL) 61 | if err != nil { 62 | color.Red("Error sending '/nodes' API call to Voyager at %s: %s\n", urlObject.Host, err) 63 | return 64 | } 65 | 66 | // Parse response 67 | responseBytes, err := ioutil.ReadAll(res.Body) 68 | if err != nil { 69 | color.Red("Error reading response body: %s\n", err) 70 | return 71 | } 72 | 73 | if res.StatusCode != 200 { 74 | color.Red("Server returned (%d): %s\n", res.StatusCode, responseBytes) 75 | return 76 | } 77 | 78 | jsonToTable(responseBytes) 79 | }, 80 | } 81 | 82 | func jsonToTable(jsonIn []byte) { 83 | var nodes []NodesResponse 84 | err := json.Unmarshal(jsonIn, &nodes) 85 | if err != nil { 86 | fmt.Println("error:", err) 87 | } 88 | table := tablewriter.NewWriter(os.Stdout) 89 | table.SetHeader([]string{"ID", "Type", "Status", "IP"}) 90 | 91 | for _, v := range nodes { 92 | table.Append([]string{v.ID, v.Type, v.Status, v.IP}) 93 | } 94 | 95 | table.Render() 96 | } 97 | 98 | func init() { 99 | RootCmd.AddCommand(nodesCmd) 100 | } 101 | -------------------------------------------------------------------------------- /ci/pipeline.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | - name: unit 3 | plan: 4 | - aggregate: 5 | - get: voyager-cli 6 | trigger: true 7 | - get: concourse-whale 8 | - task: unit 9 | image: concourse-whale 10 | config: 11 | platform: linux 12 | inputs: 13 | - name: voyager-cli 14 | params: 15 | GITHUB_USER: {{github_username}} 16 | GITHUB_PASSWORD: {{github_password}} 17 | run: 18 | path: voyager-cli/ci/tasks/unit.sh 19 | 20 | - name: integration 21 | plan: 22 | - aggregate: 23 | - put: it-env 24 | params: {acquire: true} 25 | - get: voyager-cli 26 | trigger: true 27 | passed: [unit] 28 | - get: concourse-whale 29 | - task: integration 30 | image: concourse-whale 31 | config: 32 | platform: linux 33 | inputs: 34 | - name: voyager-cli 35 | - name: it-env 36 | params: 37 | GITHUB_USER: {{github_username}} 38 | GITHUB_PASSWORD: {{github_password}} 39 | INTEGRATION_VM_USER: {{integration_vm_user}} 40 | INTEGRATION_VM_SSH_KEY: {{integration_vm_ssh_key}} 41 | run: 42 | path: voyager-cli/ci/tasks/integration.sh 43 | ensure: 44 | put: it-env 45 | params: {release: it-env} 46 | 47 | - name: build-binaries 48 | serial: true 49 | plan: 50 | - aggregate: 51 | - get: version 52 | params: {bump: patch} 53 | - get: concourse-whale 54 | - get: voyager-cli 55 | trigger: true 56 | passed: [integration] 57 | - task: build 58 | image: concourse-whale 59 | config: 60 | platform: linux 61 | inputs: 62 | - name: voyager-cli 63 | - name: version 64 | outputs: 65 | - name: build 66 | params: 67 | GITHUB_USER: {{github_username}} 68 | GITHUB_PASSWORD: {{github_password}} 69 | run: 70 | path: voyager-cli/ci/tasks/build-candidate.sh 71 | - put: mcc-cli-zip 72 | params: 73 | file: build/voyager-cli/voyager-cli-*.zip 74 | - put: version 75 | params: {file: version/version} 76 | 77 | resources: 78 | - name: voyager-cli 79 | type: git 80 | default-github: &github-secrets 81 | username: {{github_username}} 82 | password: {{github_password}} 83 | skip_ssl_verification: true 84 | source: 85 | uri: https://github.com/RackHD/voyager-cli.git 86 | branch: master 87 | <<: *github-secrets 88 | 89 | - name: version 90 | type: semver 91 | source: 92 | driver: git 93 | uri: https://github.com/RackHD/voyager-cli.git 94 | branch: version 95 | file: version 96 | <<: *github-secrets 97 | 98 | - name: it-env 99 | type: pool 100 | source: 101 | uri: https://github.com/RackHD/voyager-release.git 102 | branch: locks 103 | pool: integration 104 | <<: *github-secrets 105 | 106 | - name: concourse-whale 107 | type: docker-image 108 | source: 109 | repository: {{concourse_whale_repository}} 110 | insecure_registries: [{{docker_insecure_registries}}] 111 | 112 | - name: mcc-cli-zip 113 | type: s3 114 | source: 115 | bucket: voyager-cli 116 | regexp: voyager-cli-v(.*).zip 117 | endpoint: {{minio_endpoint_url}} 118 | access_key_id: {{minio_access_key}} 119 | secret_access_key: {{minio_secret_key}} 120 | -------------------------------------------------------------------------------- /cmd/manifest_test.go: -------------------------------------------------------------------------------- 1 | package cmd_test 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | "net/url" 10 | "os" 11 | "os/exec" 12 | "runtime" 13 | 14 | . "github.com/onsi/ginkgo" 15 | . "github.com/onsi/gomega" 16 | "github.com/onsi/gomega/ghttp" 17 | ) 18 | 19 | var _ = Describe("Manifest", func() { 20 | var binLocation string 21 | BeforeEach(func() { 22 | binLocation = fmt.Sprintf("../bin/%s/mcc", runtime.GOOS) 23 | }) 24 | 25 | Context("When there is a valid statefile", func() { 26 | 27 | Context("When the target URL is valid", func() { 28 | var server *ghttp.Server 29 | var stateFile string 30 | 31 | BeforeEach(func() { 32 | server = ghttp.NewServer() 33 | target, _ := url.Parse(server.URL()) 34 | targetb, err := json.Marshal(target) 35 | Expect(err).ToNot(HaveOccurred()) 36 | 37 | stateFile = os.Getenv("HOME") + "/.voyager" 38 | err = ioutil.WriteFile(stateFile, targetb, 0666) 39 | Expect(err).ToNot(HaveOccurred()) 40 | }) 41 | 42 | AfterEach(func() { 43 | server.Close() 44 | os.Remove(stateFile) 45 | }) 46 | 47 | Context("When there is not a manifest file", func() { 48 | It("UNIT should print error", func() { 49 | cmd := exec.Command(binLocation, "manifest", "create") 50 | out, _ := cmd.StdoutPipe() 51 | cmd.Start() 52 | 53 | buf := new(bytes.Buffer) 54 | buf.ReadFrom(out) 55 | Expect(buf.String()).To(Equal("Cannot find voyager manifest file (expecting $HOME/voyager-manifest.json)\n")) 56 | }) 57 | }) 58 | 59 | Context("When there is a manifest file", func() { 60 | 61 | Context("When Creating a manifest", func() { 62 | 63 | type Manifest struct { 64 | ID string `json:"id"` 65 | Environment string `json:"environemnt"` 66 | DNS string `json:"dns"` 67 | IP string `json:"ip"` 68 | } 69 | var manifestFile string 70 | 71 | var data Manifest 72 | BeforeEach(func() { 73 | manifestFile = os.Getenv("HOME") + "/voyager-manifest.json" 74 | data = Manifest{ 75 | ID: "123456", 76 | Environment: "ESXi", 77 | DNS: "SOME DNS HERE :)", 78 | IP: "0.0.0.0", 79 | } 80 | manifestData, err := json.Marshal(data) 81 | Expect(err).ToNot(HaveOccurred()) 82 | err = ioutil.WriteFile(manifestFile, manifestData, 0666) 83 | Expect(err).ToNot(HaveOccurred()) 84 | 85 | }) 86 | 87 | AfterEach(func() { 88 | os.Remove(manifestFile) 89 | }) 90 | 91 | It("UNIT should create the manifest file and return a success", func() { 92 | 93 | server.AppendHandlers( 94 | ghttp.CombineHandlers( 95 | ghttp.VerifyRequest("POST", "/manifest"), 96 | ghttp.RespondWith(http.StatusOK, nil), 97 | ), 98 | ) 99 | 100 | cmd := exec.Command(binLocation, "manifest", "create", "-f $HOME/voyager-manifest.json") 101 | out, _ := cmd.StdoutPipe() 102 | cmd.Start() 103 | 104 | fileContent, err := ioutil.ReadFile(manifestFile) 105 | Expect(err).ToNot(HaveOccurred()) 106 | jsonData, err := json.Marshal(data) 107 | Expect(err).ToNot(HaveOccurred()) 108 | Expect(fileContent).To(Equal(jsonData)) 109 | 110 | buf := new(bytes.Buffer) 111 | buf.ReadFrom(out) 112 | Expect(buf.String()).To(Equal("Manifest file successfully uploaded\n")) 113 | }) 114 | }) 115 | }) 116 | }) 117 | }) 118 | }) 119 | -------------------------------------------------------------------------------- /cmd/manifest_create.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "bytes" 19 | "fmt" 20 | "io/ioutil" 21 | "log" 22 | "net/http" 23 | "os" 24 | 25 | "github.com/fatih/color" 26 | "github.com/hashicorp/go-cleanhttp" 27 | homedir "github.com/mitchellh/go-homedir" 28 | "github.com/spf13/cobra" 29 | ) 30 | 31 | var fileLocation string 32 | 33 | // createCmd represents the create command 34 | var createCmd = &cobra.Command{ 35 | Use: "create", 36 | Short: "Create configuration manifest", 37 | Long: `Create manifest containing the deisred system configuration. Usage: mcc manifest create -f [filename.json]`, 38 | 39 | Run: func(cmd *cobra.Command, args []string) { 40 | 41 | url, err := CheckMccTarget() 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | 46 | dir, err := homedir.Dir() 47 | if err != nil { 48 | log.Fatal(err) 49 | } 50 | 51 | fileLocation := fmt.Sprintf("%s/voyager-manifest.json", dir) 52 | 53 | // Read IP target from file 54 | _, err = os.Stat(fileLocation) 55 | if err != nil { 56 | color.Red("Cannot find voyager manifest file (expecting $HOME/voyager-manifest.json)\n") 57 | return 58 | } 59 | 60 | // Read in manifest file to json data object 61 | manifestFile, err := ioutil.ReadFile(fileLocation) 62 | if err != nil { 63 | color.Red(fmt.Sprintf("Cannot find manifest file: %s\n", fileLocation)) 64 | return 65 | 66 | } 67 | manifestBody := bytes.NewReader(manifestFile) 68 | 69 | // Send http GET request to IP target 70 | client := cleanhttp.DefaultClient() 71 | targetURL := fmt.Sprintf("%s://%s/manifest", url.Scheme, url.Host) 72 | req, err := http.NewRequest("POST", targetURL, manifestBody) 73 | if err != nil { 74 | log.Fatal(err) 75 | } 76 | resp, err := client.Do(req) 77 | 78 | if err != nil { 79 | color.Red("Error sending '/manifest' API call to Voyager at %s: %s\n", url.Host, err) 80 | return 81 | } 82 | defer resp.Body.Close() 83 | 84 | // Parse response 85 | // responseBytes, err := ioutil.ReadAll(res.Body) 86 | // if err != nil { 87 | // color.Red("Error reading response body: %s\n", err) 88 | // return 89 | // } 90 | 91 | if resp.StatusCode != 200 { 92 | color.Red("Server returned (%d)\n", resp.StatusCode) 93 | return 94 | } 95 | color.Green("Manifest file successfully uploaded\n") 96 | }, 97 | } 98 | 99 | func init() { 100 | manifestCmd.AddCommand(createCmd) 101 | createCmd.Flags().StringVarP(&fileLocation, "file", "f", "$HOME/voyager-manifest.json", "file location eg. $HOME/voyager-manifest.json") 102 | // Here you will define your flags and configuration settings. 103 | 104 | // Cobra supports Persistent Flags which will work for this command 105 | // and all subcommands, e.g.: 106 | // createCmd.PersistentFlags().String("foo", "", "A help for foo") 107 | 108 | // Cobra supports local flags which will only run when this command 109 | // is called directly, e.g.: 110 | // createCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") 111 | 112 | } 113 | -------------------------------------------------------------------------------- /cmd/commands_test.go: -------------------------------------------------------------------------------- 1 | package cmd_test 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | "net/url" 10 | "os" 11 | "os/exec" 12 | "runtime" 13 | 14 | homedir "github.com/mitchellh/go-homedir" 15 | . "github.com/onsi/ginkgo" 16 | . "github.com/onsi/gomega" 17 | "github.com/onsi/gomega/ghttp" 18 | "github.com/RackHD/voyager-cli/cmd" 19 | ) 20 | 21 | var _ = Describe("Commands", func() { 22 | var binLocation string 23 | var server *ghttp.Server 24 | var StateFile string 25 | 26 | BeforeEach(func() { 27 | binLocation = fmt.Sprintf("../bin/%s/mcc", runtime.GOOS) 28 | server = ghttp.NewServer() 29 | dir, err := homedir.Dir() 30 | Expect(err).ToNot(HaveOccurred()) 31 | StateFile = fmt.Sprintf("%s/.voyager", dir) 32 | }) 33 | 34 | AfterEach(func() { 35 | server.Close() 36 | os.Remove(StateFile) 37 | }) 38 | 39 | Describe("Test the commands", func() { 40 | Context("When calling 'target' with invalid url", func() { 41 | It("UNIT should check input with JSON Marshal and fail", func() { 42 | responseBytes := []byte("THIS SHOULD FAIL") 43 | expectedOutput := fmt.Sprintf("Invalid response body: %s\nexited with error", responseBytes) 44 | 45 | server.AppendHandlers( 46 | ghttp.CombineHandlers( 47 | ghttp.VerifyRequest("GET", "/info"), 48 | ghttp.RespondWith(http.StatusOK, responseBytes), 49 | ), 50 | ) 51 | 52 | // Set up command to test 53 | cmd := exec.Command(binLocation, "target", server.URL()) 54 | out, _ := cmd.StdoutPipe() 55 | cmd.Start() 56 | 57 | // Capture Standard Output to verify 58 | buf := new(bytes.Buffer) 59 | buf.ReadFrom(out) 60 | s := buf.String() 61 | 62 | // Verify output 63 | Expect(s).To(ContainSubstring(expectedOutput)) 64 | 65 | }) 66 | }) 67 | Context("call target with valid input", func() { 68 | It("INTEGRATION should set info for the target voyager", func() { 69 | ExpectedResponse := cmd.InfoResponse{Name: "voyager"} 70 | expectedResponseData, _ := json.Marshal(ExpectedResponse) 71 | expectedString := fmt.Sprintf("Target set to %s\n", server.URL()) 72 | server.AppendHandlers( 73 | ghttp.CombineHandlers( 74 | ghttp.VerifyRequest("GET", "/info"), 75 | ghttp.RespondWith(http.StatusOK, expectedResponseData), 76 | ), 77 | ) 78 | 79 | // Set up command to test 80 | cmd := exec.Command(binLocation, "target", server.URL()) 81 | out, _ := cmd.StdoutPipe() 82 | cmd.Start() 83 | 84 | // Capture Standard Output to verify 85 | buf := new(bytes.Buffer) 86 | buf.ReadFrom(out) 87 | s := buf.String() 88 | fmt.Printf(s) 89 | 90 | // Verify state file is created 91 | _, err := ioutil.ReadFile(StateFile) 92 | 93 | // Verify output 94 | Expect(s).To(Equal(expectedString)) 95 | Expect(err).ToNot(HaveOccurred()) 96 | Expect(server.ReceivedRequests()).To(HaveLen(1)) 97 | }) 98 | }) 99 | Context("Ater target has been set", func() { 100 | BeforeEach(func() { 101 | _, err := os.Stat(StateFile) 102 | Expect(os.IsNotExist(err)) 103 | urlObj, err := url.Parse(server.URL()) 104 | Expect(err).ToNot(HaveOccurred()) 105 | urlBytes, err := json.Marshal(urlObj) 106 | Expect(err).ToNot(HaveOccurred()) 107 | err = ioutil.WriteFile(StateFile, urlBytes, 0666) 108 | Expect(err).ToNot(HaveOccurred()) 109 | }) 110 | AfterEach(func() { 111 | _ = os.Remove(StateFile) 112 | }) 113 | It("INTEGRATION should display endpoint after target", func() { 114 | cmd := exec.Command(binLocation, "target") 115 | out, _ := cmd.StdoutPipe() 116 | cmd.Start() 117 | 118 | // Capture Standard Output to verify 119 | buf := new(bytes.Buffer) 120 | buf.ReadFrom(out) 121 | s := buf.String() 122 | 123 | Expect(s).To(Equal(fmt.Sprintf("Current target is %s\n", server.URL()))) 124 | }) 125 | }) 126 | Context("no target has been set", func() { 127 | It("INTEGRATION should display no target set", func() { 128 | cmd := exec.Command(binLocation, "target") 129 | out, _ := cmd.StdoutPipe() 130 | cmd.Start() 131 | 132 | buf := new(bytes.Buffer) 133 | buf.ReadFrom(out) 134 | s := buf.String() 135 | 136 | Expect(s).To(Equal(fmt.Sprintf("No target set.\n"))) 137 | }) 138 | }) 139 | }) 140 | }) 141 | -------------------------------------------------------------------------------- /cmd/get_nodes_test.go: -------------------------------------------------------------------------------- 1 | package cmd_test 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | "net/url" 10 | "os" 11 | "os/exec" 12 | "runtime" 13 | 14 | . "github.com/onsi/ginkgo" 15 | . "github.com/onsi/gomega" 16 | "github.com/onsi/gomega/ghttp" 17 | ) 18 | 19 | var _ = Describe("GetNodes", func() { 20 | var binLocation string 21 | 22 | BeforeEach(func() { 23 | binLocation = fmt.Sprintf("../bin/%s/mcc", runtime.GOOS) 24 | }) 25 | 26 | Context("When there is no statefile", func() { 27 | It("UNIT should print error", func() { 28 | cmd := exec.Command(binLocation, "nodes") 29 | out, _ := cmd.StdoutPipe() 30 | cmd.Start() 31 | 32 | buf := new(bytes.Buffer) 33 | buf.ReadFrom(out) 34 | Expect(buf.String()).To(Equal("Cannot find mcc config file (expecting $HOME/.voyager)\n")) 35 | }) 36 | }) 37 | 38 | Context("When there is a valid statefile", func() { 39 | Context("When the target URL is invalid", func() { 40 | It("UNIT should print error", func() { 41 | server := ghttp.NewServer() 42 | target, _ := url.Parse(server.URL()) 43 | target.Host = "0.0.0.1" 44 | targetb, err := json.Marshal(target) 45 | Expect(err).ToNot(HaveOccurred()) 46 | 47 | stateFile := os.Getenv("HOME") + "/.voyager" 48 | err = ioutil.WriteFile(stateFile, targetb, 0666) 49 | Expect(err).ToNot(HaveOccurred()) 50 | 51 | cmd := exec.Command(binLocation, "nodes") 52 | out, _ := cmd.StdoutPipe() 53 | cmd.Start() 54 | 55 | // Capture Standard Output to verify 56 | buf := new(bytes.Buffer) 57 | buf.ReadFrom(out) 58 | Expect(buf.String()).To(ContainSubstring("Error sending '/nodes' API call to Voyager at 0.0.0.1: Get http://0.0.0.1/nodes:")) 59 | os.Remove(stateFile) 60 | }) 61 | }) 62 | 63 | Context("When the target URL is valid", func() { 64 | var server *ghttp.Server 65 | var stateFile string 66 | 67 | BeforeEach(func() { 68 | server = ghttp.NewServer() 69 | 70 | target, _ := url.Parse(server.URL()) 71 | targetb, err := json.Marshal(target) 72 | Expect(err).ToNot(HaveOccurred()) 73 | 74 | stateFile = os.Getenv("HOME") + "/.voyager" 75 | err = ioutil.WriteFile(stateFile, targetb, 0666) 76 | Expect(err).ToNot(HaveOccurred()) 77 | }) 78 | 79 | AfterEach(func() { 80 | server.Close() 81 | os.Remove(stateFile) 82 | }) 83 | 84 | Context("When mcc sends get nodes to inventory service", func() { 85 | Context("When response is not empty", func() { 86 | It("UNIT receive a list of nodes information", func() { 87 | expectedResponse := `[{"ID":"UNIQUE_ID","Type":"compute","Status":"Added","IP":"1.2.3.4"},{"ID":"UNIQUE_ID1","Type":"compute","Status":"Added","IP":"2.3.4.5"}]` 88 | expectedString := `+------------+---------+--------+---------+ 89 | | ID | TYPE | STATUS | IP | 90 | +------------+---------+--------+---------+ 91 | | UNIQUE_ID | compute | Added | 1.2.3.4 | 92 | | UNIQUE_ID1 | compute | Added | 2.3.4.5 | 93 | +------------+---------+--------+---------+ 94 | ` 95 | server.AppendHandlers( 96 | ghttp.CombineHandlers( 97 | ghttp.VerifyRequest("GET", "/nodes"), 98 | ghttp.RespondWith(http.StatusOK, expectedResponse), 99 | ), 100 | ) 101 | 102 | cmd := exec.Command(binLocation, "nodes") 103 | out, _ := cmd.StdoutPipe() 104 | cmd.Start() 105 | 106 | buf := new(bytes.Buffer) 107 | buf.ReadFrom(out) 108 | Expect(server.ReceivedRequests()).To(HaveLen(1)) 109 | Expect(buf.String()).To(Equal(expectedString)) 110 | }) 111 | }) 112 | 113 | Context("When response is empty", func() { 114 | It("UNIT should show empty table", func() { 115 | ExpectedResponse := "" 116 | expectedString := `+----+------+--------+----+ 117 | | ID | TYPE | STATUS | IP | 118 | +----+------+--------+----+ 119 | +----+------+--------+----+ 120 | ` 121 | server.AppendHandlers( 122 | ghttp.CombineHandlers( 123 | ghttp.VerifyRequest("GET", "/nodes"), 124 | ghttp.RespondWith(http.StatusOK, ExpectedResponse), 125 | ), 126 | ) 127 | 128 | cmd := exec.Command(binLocation, "nodes") 129 | out, _ := cmd.StdoutPipe() 130 | cmd.Start() 131 | 132 | buf := new(bytes.Buffer) 133 | buf.ReadFrom(out) 134 | Expect(buf.String()).To(ContainSubstring(expectedString)) 135 | }) 136 | }) 137 | }) 138 | }) 139 | }) 140 | }) 141 | -------------------------------------------------------------------------------- /cmd/target.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2016 NAME HERE 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | "io/ioutil" 21 | "log" 22 | "net/http" 23 | "net/url" 24 | "os" 25 | 26 | "github.com/RackHD/voyager-houston/model" 27 | "github.com/mitchellh/go-homedir" 28 | 29 | "github.com/fatih/color" 30 | "github.com/spf13/cobra" 31 | ) 32 | 33 | // targetCmd represents the target command 34 | var targetCmd = &cobra.Command{ 35 | Use: "target", 36 | Short: "IP endpoint of a Voyager system to target", 37 | Long: `IP endpoint of a Voyager system to target. 38 | This command will attempt a call to the IP specified, and if successful, 39 | will store the IP for future use in the .voyager file 40 | 41 | Usage: mcc target http://: 42 | ex.: mcc target http://192.168.1.1:80`, 43 | 44 | Run: func(c *cobra.Command, args []string) { 45 | 46 | // Argument required 47 | if len(args) > 1 { 48 | fmt.Printf("Too Many Arguments.\n") 49 | return 50 | } else if len(args) < 1 { 51 | // Check and see if the endpoint has been set 52 | dir, err := homedir.Dir() 53 | 54 | if err != nil { 55 | log.Fatal(err) 56 | } 57 | fileLocation := fmt.Sprintf("%s/.voyager", dir) 58 | if _, err := os.Stat(fileLocation); err == nil { 59 | fileContent, err := ioutil.ReadFile(fileLocation) 60 | if err != nil { 61 | log.Fatal(err) 62 | } 63 | // Unmarshal data and print 64 | urlObject := url.URL{} 65 | err = json.Unmarshal(fileContent, &urlObject) 66 | if err != nil { 67 | log.Fatal(err) 68 | } 69 | fmt.Printf("Current target is ") 70 | color.Green("%s://%s\n", urlObject.Scheme, urlObject.Host) 71 | } else { 72 | color.Red("No target set.\n") 73 | } 74 | } else { 75 | // Parse and validate argument 76 | target, err := url.Parse(args[0]) 77 | if err != nil { 78 | color.Red("Could not convert arg to IP Address: %s\n", err) 79 | return 80 | } 81 | 82 | if target.Host == "" || target.Scheme == "" { 83 | fmt.Printf("Please enter a valid target url. ex: http://192.168.1.1:80\n") 84 | return 85 | } 86 | 87 | // Convert argument to REST call 88 | targetURL := fmt.Sprintf("%s://%s/info", target.Scheme, target.Host) 89 | 90 | // Send API call to validate that argument points to running Voyager instance 91 | res, err := http.Get(targetURL) 92 | 93 | // Error check the REST call 94 | if err != nil { 95 | fmt.Printf("Error sending '/info' API call to Voyager: %s\n", err) 96 | return 97 | } 98 | if res.StatusCode != 200 { 99 | fmt.Printf("Non-success status code returned:") 100 | color.Red("%d\n", res.StatusCode) 101 | return 102 | } 103 | 104 | respBytes, err := ioutil.ReadAll(res.Body) 105 | if err != nil { 106 | fmt.Printf("Error reading response body: %s\n", err) 107 | } 108 | 109 | var houston model.Houston 110 | err = json.Unmarshal(respBytes, &houston) 111 | if err != nil { 112 | fmt.Printf("Invalid response body: %s\nexited with error: %s", respBytes, err) 113 | return 114 | } 115 | 116 | color.Green("Target set to %s://%s\n", target.Scheme, target.Host) 117 | 118 | // Store target URL of valid Voyager endpoint 119 | targetb, err := json.Marshal(target) 120 | if err != nil { 121 | fmt.Printf("Could not marshal IP Address to JSON: %s\n", err) 122 | return 123 | } 124 | 125 | // Determine where to store state file 126 | dir, err := homedir.Dir() 127 | if err != nil { 128 | log.Fatal(err) 129 | } 130 | fileLocation := fmt.Sprintf("%s/.voyager", dir) 131 | err = ioutil.WriteFile(fileLocation, targetb, 0666) 132 | if err != nil { 133 | fmt.Printf("Error storing IP address to file: %s\n", err) 134 | return 135 | } 136 | } 137 | // Success 138 | }, 139 | } 140 | 141 | func init() { 142 | RootCmd.AddCommand(targetCmd) 143 | 144 | } 145 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------