Skip to content

Commit

Permalink
Merge of development for release (#83)
Browse files Browse the repository at this point in the history
New features/functionality:

* [#60] Webhook functionality added to the CLI.
* [#76] Project changed to use semantic versioning. See http://semver.org/ for further details.
* Added a get baremetal capabilities command. 
* Added a version command to return build version, build date and git commit hash, os and Go version
* Changed the integration tests to use 'go test' instead of a seperate executable. The tests utilise the new subtest functionality in go 1.7.
* API file generation now has been separated out into a different command line.

Bug fixes:

* [#55] Remove premium storage type as its deprecated. The --storage-type command line option has been removed completely for server create, server import.
* [#64] Listing cross DC policies didn't filter as expected.
* [#67] Getting server details doesn't return IsManaged or IsManagdBackup
* [#69] Updating the server disks fails.
* [#70] Integration tests where failing due to multiple issues.
* [#75] Creating bare metal servers shouldn't require CPU, MemoryGB or template. Additionally the configuration-id and os-type parameters should indicate how to get the allowed values.

Resolves #55, #60, #64, #67, #69, #70, #75, #76

Signed-off-by: Richard Case <[email protected]>
  • Loading branch information
richardcase authored Nov 2, 2016
1 parent f83d789 commit 399b738
Show file tree
Hide file tree
Showing 42 changed files with 707 additions and 376 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ out/*
*.swp
.DS_Store
release/*
.vscode/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ instructions below may not work properly on Windows.
* If you want to make an executable, simply run `./scripts/build`. The binary will appear in the `./out` folder.
* The integration tests can be running `./run_integration_tests`.
* The API file can be regenerated by running `./scripts/generate_api`.
### Building the releases
Generally, any Linux/Darwin machine should work for building the releases. A Darwin machine is required though if you want to build a `MacOS .pkg`.
Expand Down
5 changes: 5 additions & 0 deletions base/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package base

var BuildVersion = "built-from-source"
var BuildGitCommit = "No git commit provided"
var BuildDate = "No build date supplied"
6 changes: 2 additions & 4 deletions base/constants.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package base

const (
VERSION = "built-from-source"
)

var (
URL = "https://api.ctl.io"
CTL_URL = "http://www.ctl.io"
PROJ_URL = "https://github.com/CenturyLinkCloud/clc-go-cli"
TIME_FORMAT = "2006-01-02 15:04:05"
SERVER_TIME_FORMAT = "2006-01-02T15:04:05Z"
TIME_FORMAT_REPR = "YYYY-MM-DD hh:mm:ss"
Expand Down
36 changes: 36 additions & 0 deletions cmd/genapi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"flag"
"os"

integration "github.com/centurylinkcloud/clc-go-cli/integration_tests"
)

func main() {
logger := integration.NewLogger()

var apiPath = flag.String("api-path", "", "The path to the API file")
flag.Parse()

if *apiPath == "" {
logger.Logf("ERROR: The api-path command line argument must be specified.")
os.Exit(-1)
}

parser := integration.NewParser(logger)

apiDef, err := parser.ParseApi()
if err != nil {
logger.Logf("Error while parsing API definition: %v", err)
os.Exit(-2)
}

err = integration.StoreApi(apiDef, *apiPath)
if err != nil {
logger.Logf("Error while storing API definition: %v", err)
os.Exit(-3)
}

os.Exit(0)
}
48 changes: 48 additions & 0 deletions commands/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package commands

import (
"fmt"
"runtime"

"github.com/centurylinkcloud/clc-go-cli/base"
)

var banner = `
-------------------------------------------------------------
_____ __ __ _ __
/ ___/___ ___ / /_ __ __ ____ __ __ / / (_)___ / /__
/ /__ / -_)/ _ \/ __// // // __// // // /__ / // _ \ / '_/
\___/ \__//_//_/\__/ \_,_//_/ \_, //____//_//_//_//_/\_\
/___/
-------------------------------------------------------------
`

type Version struct {
CommandBase
}

func NewVersion(info CommandExcInfo) *Version {
v := Version{}
v.ExcInfo = info
return &v
}

func (v *Version) IsOffline() bool {
return true
}

func (v *Version) ExecuteOffline() (string, error) {
fmt.Printf("%s", banner)
fmt.Printf("CenturyLink Cloud CLI (Version %s)\n", base.BuildVersion)
fmt.Printf("%s\n", base.PROJ_URL)
fmt.Printf("\n")
fmt.Printf("Go Version: %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
fmt.Printf("Built on: %s\n", base.BuildDate)
fmt.Printf("Git Commit: %s\n", base.BuildGitCommit)
fmt.Printf("\n")
fmt.Printf("For more information on CenturyLink Cloud visit: %s\n", base.CTL_URL)

return "", nil
}
2 changes: 1 addition & 1 deletion connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
const OriginalBaseUrl = "https://api.ctl.io/"

var (
userAgent = fmt.Sprintf("clc-go-cli-%s-%s", base.VERSION, runtime.GOOS)
userAgent = fmt.Sprintf("clc-go-cli-%s-%s", base.BuildVersion, runtime.GOOS)
//this made a variable instead of a constant for testing purpoises
BaseUrl = OriginalBaseUrl
)
Expand Down
140 changes: 118 additions & 22 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/centurylinkcloud/clc-go-cli/models/ospatch"
"github.com/centurylinkcloud/clc-go-cli/models/server"
"github.com/centurylinkcloud/clc-go-cli/models/vpn"
"github.com/centurylinkcloud/clc-go-cli/models/webhook"
)

var AllCommands []base.Command = make([]base.Command, 0)
Expand Down Expand Up @@ -157,15 +158,6 @@ func init() {
"--type",
[]string{"Required. Whether to create a standard, hyperscale, or bareMetal server."},
},
{
"--storage-type",
[]string{
"For standard servers, whether to use standard or premium storage.",
"If not provided, will default to premium storage.",
"For hyperscale servers, storage type must be hyperscale.",
"Ignored for bare metal servers.",
},
},
{
"--anti-affinity-policy-id",
[]string{
Expand Down Expand Up @@ -202,14 +194,15 @@ func init() {
"--configuration-id",
[]string{
"Only required for bare metal servers. Specifies the identifier for the specific configuration type of bare metal server to deploy.",
"Ignored for standard and hyperscale servers.",
"The list of valid bare metal configuration id's can be found by calling the 'clc data-center get-baremetal-capabilities' command.",
"Ignored for standard and hyperscale servers. ",
},
},
{
"--os-type",
[]string{
"Only required for bare metal servers. Specifies the OS to provision with the bare metal server. Currently, the only supported OS types",
"are redHat6_64Bit, centOS6_64Bit, windows2012R2Standard_64Bit.",
"Only required for bare metal servers. Specifies the OS to provision with the bare metal server. The list of valid operating",
"systems can be found by calling the 'clc data-center get-baremetal-capabilities' command.",
"Ignored for standard and hyperscale servers.",
},
},
Expand Down Expand Up @@ -791,13 +784,6 @@ func init() {
"--type",
[]string{"Required. Whether to create standard or hyperscale server"},
},
{
"--storage-type",
[]string{
"For standard servers, whether to use standard or premium storage. If not provided, will default to premium storage.",
"For hyperscale servers, storage type must be hyperscale.",
},
},
{
"--custom-fields",
[]string{
Expand Down Expand Up @@ -1380,7 +1366,25 @@ func init() {
Brief: []string{
"Gets the list of capabilities that a specific data center supports for a given account,",
"including the deployable networks, OS templates, and whether features like",
"premium storage and shared load balancer configuration are available.",
"bare metal servers and shared load balancer configuration are available.",
},
Arguments: []help.Argument{
{
"--data-center",
[]string{"Required. Short string representing the data center you are querying."},
},
},
},
})
registerCommandBase(&datacenter.GetBMCapReq{}, &datacenter.GetBMCapRes{}, commands.CommandExcInfo{
Verb: "GET",
Url: "https://api.ctl.io/v2/datacenters/{accountAlias}/{DataCenter}/bareMetalCapabilities",
Resource: "data-center",
Command: "get-baremetal-capabilities",
Help: help.Command{
Brief: []string{
"Gets the list of bare metal capabilities that a specific data center supports for a given account,",
"including the list of configuration types and the list of supported operating systems.",
},
Arguments: []help.Argument{
{
Expand Down Expand Up @@ -1473,7 +1477,7 @@ func init() {
},
},
})
registerCommandBase(&network.CreateReq{}, &models.LinkEntity{}, commands.CommandExcInfo{
registerCommandBase(&network.CreateReq{}, &models.Status{}, commands.CommandExcInfo{
Verb: "POST",
Url: "https://api.ctl.io/v2-experimental/networks/{accountAlias}/{DataCenter}/claim",
Resource: "network",
Expand Down Expand Up @@ -1939,7 +1943,7 @@ func init() {
})
registerCommandBase(&crossdc_firewall.ListReq{}, &[]crossdc_firewall.Entity{}, commands.CommandExcInfo{
Verb: "GET",
Url: "https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{DataCenter}?destinationAccount={DestinationAccountAlias}",
Url: "https://api.ctl.io/v2-experimental/crossDcFirewallPolicies/{accountAlias}/{DataCenter}?destinationAccountId={DestinationAccountAlias}",
Resource: "crossdc-firewall-policy",
Command: "list",
Help: help.Command{
Expand Down Expand Up @@ -2435,6 +2439,13 @@ func init() {
AccountAgnostic: true,
},
}))
registerCustomCommand(commands.NewVersion(commands.CommandExcInfo{
Resource: "version",
Help: help.Command{
Brief: []string{"Shows version information about the cli."},
AccountAgnostic: true,
},
}))
registerCustomCommand(commands.NewLogin(commands.CommandExcInfo{
Resource: "login",
Help: help.Command{
Expand Down Expand Up @@ -3737,6 +3748,91 @@ func init() {
},
},
})
registerCommandBase(nil, &webhook.ListRes{}, commands.CommandExcInfo{
Verb: "GET",
Url: "https://api.ctl.io/v2/webhooks/{accountAlias}",
Resource: "webhook",
Command: "list",
Help: help.Command{
Brief: []string{"Gets a list of the webhooks configured for a given account."},
},
})
registerCommandBase(&webhook.DeleteReq{}, new(string), commands.CommandExcInfo{
Verb: "DELETE",
Url: "https://api.ctl.io/v2/webhooks/{accountAlias}/{Event}/configuration",
Resource: "webhook",
Command: "delete",
Help: help.Command{
Brief: []string{"Deletes a given alert policy by ID."},
Arguments: []help.Argument{
{
"--event",
[]string{"Required. Name of the event for which the webhook will be deleted."},
},
},
},
})
registerCommandBase(&webhook.DeleteTargetURIReq{}, new(string), commands.CommandExcInfo{
Verb: "DELETE",
Url: "https://api.ctl.io/v2/webhooks/{accountAlias}/{Event}/configuration/targetUris?targetUri={TargetUri}",
Resource: "webhook",
Command: "delete-targeturi",
Help: help.Command{
Brief: []string{"Deletes a target URI from a webhook."},
Arguments: []help.Argument{
{
"--event",
[]string{"Required. Name of the event for which the target URI will be deleted."},
},
{
"--target-uri",
[]string{"The URI of the target to remove from the webhook."},
},
},
},
})
registerCommandBase(&webhook.AddTargetURIReq{}, new(string), commands.CommandExcInfo{
Verb: "POST",
Url: "https://api.ctl.io/v2/webhooks/{accountAlias}/{Event}/configuration/targetUris",
Resource: "webhook",
Command: "add-targeturi",
Help: help.Command{
Brief: []string{"Add a target uri to the webhook for a specified event."},
Arguments: []help.Argument{
{
"--event",
[]string{"Required. Name of the event for which the target URI will be added."},
},
{
"--target-uri",
[]string{"Required. A uri that will be called when the event occurs."},
},
},
},
})
registerCommandBase(&webhook.UpdateReq{}, new(string), commands.CommandExcInfo{
Verb: "PUT",
Url: "https://api.ctl.io/v2/webhooks/{accountAlias}/{Event}/configuration",
Resource: "webhook",
Command: "update",
Help: help.Command{
Brief: []string{"Change the configuration of a webhook for a specific event."},
Arguments: []help.Argument{
{
"--event",
[]string{"Required. Name of the event for which to update the webhook."},
},
{
"--recursive",
[]string{"Required. If true, the webhook is called when the event occurs in sub-accounts."},
},
{
"--target-uri",
[]string{"A uri that will be called when the event occurs."},
},
},
},
})
}

func registerCommandBase(inputModel interface{}, outputModel interface{}, info commands.CommandExcInfo) {
Expand Down
Loading

0 comments on commit 399b738

Please sign in to comment.