Skip to content

Commit

Permalink
Add additional information to DC list & get (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim Zhylinski committed Jul 21, 2016
1 parent 5fd2087 commit 9e9d3e2
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 28 deletions.
27 changes: 27 additions & 0 deletions commands/datacenter_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package commands

import (
"github.com/centurylinkcloud/clc-go-cli/base"
"github.com/centurylinkcloud/clc-go-cli/models/datacenter"
)

type DatacenterGet struct {
CommandBase
}

func NewDatacenterGet(info CommandExcInfo) *DatacenterGet {
dcGet := DatacenterGet{}
dcGet.ExcInfo = info
dcGet.Input = &datacenter.GetReq{}
return &dcGet
}

func (dcGet *DatacenterGet) Execute(cn base.Connection) error {
var err error

input := dcGet.Input.(*datacenter.GetReq)
dcGet.Output, err = datacenter.Get(cn, input.DataCenter, input.WithComputeLimits.Set,
input.WithNetworkLimits.Set, input.WithAvailableOvfs.Set, input.WithLoadBalancers.Set)

return err
}
27 changes: 27 additions & 0 deletions commands/datacenter_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package commands

import (
"github.com/centurylinkcloud/clc-go-cli/base"
"github.com/centurylinkcloud/clc-go-cli/models/datacenter"
)

type DatacenterList struct {
CommandBase
}

func NewDatacenterList(info CommandExcInfo) *DatacenterList {
dcList := DatacenterList{}
dcList.ExcInfo = info
dcList.Input = &datacenter.ListReq{}
return &dcList
}

func (dcList *DatacenterList) Execute(cn base.Connection) error {
var err error

input := dcList.Input.(*datacenter.ListReq)
dcList.Output, err = datacenter.All(cn, input.WithComputeLimits.Set,
input.WithNetworkLimits.Set, input.WithAvailableOvfs.Set, input.WithLoadBalancers.Set)

return err
}
46 changes: 36 additions & 10 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1317,18 +1317,32 @@ func init() {
},
})

registerCommandBase(&datacenter.ListReq{}, &[]datacenter.ListRes{}, commands.CommandExcInfo{
Verb: "GET",
Url: "https://api.ctl.io/v2/datacenters/{accountAlias}",
registerCustomCommand(commands.NewDatacenterList(commands.CommandExcInfo{
Resource: "data-center",
Command: "list",
Help: help.Command{
Brief: []string{"Gets the list of data centers that a given account has access to."},
Arguments: []help.Argument{
{
"--with-compute-limits",
[]string{"Get compute limits data"},
},
{
"--with-network-limits",
[]string{"Get network limits data"},
},
{
"--with-available-ovfs",
[]string{"Get available servers for import"},
},
{
"--with-load-balancers",
[]string{"Get load balancers"},
},
},
},
})
registerCommandBase(&datacenter.GetReq{}, &datacenter.GetRes{}, commands.CommandExcInfo{
Verb: "GET",
Url: "https://api.ctl.io/v2/datacenters/{accountAlias}/{DataCenter}?groupLinks={GroupLinks}",
}))
registerCustomCommand(commands.NewDatacenterGet(commands.CommandExcInfo{
Resource: "data-center",
Command: "get",
Help: help.Command{
Expand All @@ -1339,12 +1353,24 @@ func init() {
[]string{"Required. Short string representing the data center you are querying."},
},
{
"--group-links",
[]string{"Required. Determine whether link collections are returned for each group."},
"--with-compute-limits",
[]string{"Get compute limits data"},
},
{
"--with-network-limits",
[]string{"Get network limits data"},
},
{
"--with-available-ovfs",
[]string{"Get available servers for import"},
},
{
"--with-load-balancers",
[]string{"Get load balancers"},
},
},
},
})
}))
registerCommandBase(&datacenter.GetDCReq{}, &datacenter.GetDCRes{}, commands.CommandExcInfo{
Verb: "GET",
Url: "https://api.ctl.io/v2/datacenters/{accountAlias}/{DataCenter}/deploymentCapabilities",
Expand Down
52 changes: 41 additions & 11 deletions models/datacenter/get.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
package datacenter

import (
"fmt"
"github.com/centurylinkcloud/clc-go-cli/base"
"github.com/centurylinkcloud/clc-go-cli/models"
)

type GetReq struct {
DataCenter string `valid:"required" URIParam:"yes"`
GroupLinks string `valid:"required" URIParam:"yes"`
DataCenter string `valid:"required"`
WithComputeLimits base.NilField
WithNetworkLimits base.NilField
WithAvailableOvfs base.NilField
WithLoadBalancers base.NilField
}

type GetRes struct {
Id string
Name string
Links []models.LinkEntity
Id string
Name string
ComputeLimits *DcComputeLimits `json:",omitempty"`
NetworkLimits *DcNetworkLimits `json:",omitempty"`
AvailableOVFs *[]DcAvailableOVF `json:",omitempty"`
LoadBalancers *[]DcLoadBalancer `json:",omitempty"`
Links models.Links
}

func (r *GetReq) Validate() error {
if r.GroupLinks != "false" && r.GroupLinks != "true" {
return fmt.Errorf("group-links value must be either true or false.")
}
return nil
type DcComputeLimits struct {
Cpu DcResourceLimit
MemoryGB DcResourceLimit
StorageGB DcResourceLimit
}

type DcNetworkLimits struct {
Networks DcResourceLimit
}

type DcResourceLimit struct {
Value int
Inherited bool
}

type DcAvailableOVF struct {
Id string
Name string
StorageSizeGB int
CpuCount int
MemorySizeMB int
}

type DcLoadBalancer struct {
Name string
Description string
IpAddress string
Status string
}
15 changes: 8 additions & 7 deletions models/datacenter/list.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package datacenter

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

type ListReq struct{}

type ListRes struct {
Id string
Name string
Links []models.LinkEntity
type ListReq struct {
WithComputeLimits base.NilField
WithNetworkLimits base.NilField
WithAvailableOvfs base.NilField
WithLoadBalancers base.NilField
}

type ListRes GetRes
Loading

0 comments on commit 9e9d3e2

Please sign in to comment.