Skip to content

Commit

Permalink
Merge branch 'master' into default-data-center
Browse files Browse the repository at this point in the history
  • Loading branch information
ldmberman committed Sep 3, 2015
2 parents 7c1af7d + 055b3d1 commit 6d64453
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
6 changes: 3 additions & 3 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
},
{
"--source-server-id",
[]string{"Required. ID of the server to use a source."},
[]string{"Required. ID of the server to use a source. May be the ID of a template, or when cloning, an existing server ID."},
},
{
"--is-managed-os",
Expand Down Expand Up @@ -156,14 +156,14 @@ func init() {
{
"--configuration-id",
[]string{
"Specifies the identifier for the specific configuration type of bare metal server to deploy.",
"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.",
},
},
{
"--os-type",
[]string{
"Specifies the OS to provision with the bare metal server. Currently, the only supported OS types",
"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.",
"Ignored for standard and hyperscale servers.",
},
Expand Down
58 changes: 40 additions & 18 deletions models/server/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,39 @@ import (
"time"
)

const (
timeFormat = "2006-01-02 15:04:05"
)

type CreateReq struct {
Name string `valid:"required"`
Description string `json:"omitempty"`
Description string `json:",omitempty"`
GroupId string
GroupName string `json:"omitempty"`
GroupName string `json:",omitempty"`
SourceServerId string
TemplateId string
TemplateName string `json:"omitempty"`
IsManagedOS bool `json:"omitempty"`
PrimaryDns string `json:"omitempty"`
SecondaryDns string `json:"omitempty"`
NetworkId string `json:"omitempty"`
IpAddress string `json:"omitempty"`
RootPassword string `json:"omitempty"`
SourceServerPassword string `json:"omitempty"`
TemplateName string `json:",omitempty"`
IsManagedOS bool `json:",omitempty"`
PrimaryDns string `json:",omitempty"`
SecondaryDns string `json:",omitempty"`
NetworkId string `json:",omitempty"`
IpAddress string `json:",omitempty"`
RootPassword string `json:",omitempty"`
SourceServerPassword string `json:",omitempty"`
Cpu int64 `valid:"required"`
CpuAutoscalePolicyId string `json:"omitempty"`
CpuAutoscalePolicyId string `json:",omitempty"`
MemoryGB int64 `valid:"required"`
Type string `valid:"required" oneOf:"standard,hyperscale,bareMetal"`
StorageType string `json:"omitempty" oneOf:"standard,premium,hyperscale"`
AntiAffinityPolicyId string `json:"omitempty"`
AntiAffinityPolicyName string `json:"omitempty"`
CustomFields []CustomFieldDef `json:"omitempty"`
AdditionalDisks []AddDiskRequest `json:"omitempty"`
Ttl time.Time `json:"omitempty"`
Packages []PackageDef `json:"omitempty"`
StorageType string `json:",omitempty" oneOf:"standard,premium,hyperscale"`
AntiAffinityPolicyId string `json:",omitempty"`
AntiAffinityPolicyName string `json:",omitempty"`
CustomFields []CustomFieldDef `json:",omitempty"`
AdditionalDisks []AddDiskRequest `json:",omitempty"`
Ttl time.Time `json:"-"`
TtlString string `json:"Ttl,omitempty"`
Packages []PackageDef `json:",omitempty"`
ConfigurationId string `json:",omitempty"`
OsType string `json:",omitempty"`
}

func (c *CreateReq) Validate() error {
Expand All @@ -49,14 +56,29 @@ func (c *CreateReq) Validate() error {
return fmt.Errorf("Exactly one parameter from the following: group-id, group-name must be specified.")
}

if c.Type == "bareMetal" {
if c.ConfigurationId == "" {
return fmt.Errorf("ConfigurationId: required for bare metal servers.")
}
if c.OsType == "" {
return fmt.Errorf("OsType: required for bare metal servers.")
}
}

return nil
}

func (c *CreateReq) ApplyDefaultBehaviour() error {
if c.TemplateId != "" {
c.SourceServerId = c.TemplateId
}

zeroTime := time.Time{}
if c.Ttl != zeroTime {
c.TtlString = c.Ttl.Format(timeFormat)
}
return nil

//TODO: implement searching templates by name
//TODO: implement searching groups by names
}
12 changes: 6 additions & 6 deletions models/server/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package server

type Import struct {
Name string `valid:"required"`
Description string `json:"omitempty"`
Description string `json:",omitempty"`
GroupId string `valid:"required"`
PrimaryDns string `json:"omitempty"`
SecondaryDns string `json:"omitempty"`
NetworkId string `json:"omitempty"`
PrimaryDns string `json:",omitempty"`
SecondaryDns string `json:",omitempty"`
NetworkId string `json:",omitempty"`
RootPassword string `valid:"required"`
Cpu int64 `valid:"required"`
MemoryGB int64 `valid:"required"`
Type string `valid:"required" oneOf:"standard,hyperscale"`
StorageType string `json:"omitempty" oneOf:"standard,premium,hyperscale"`
CustomFields []CustomFieldDef `json:"omitempty"`
StorageType string `json:",omitempty" oneOf:"standard,premium,hyperscale"`
CustomFields []CustomFieldDef `json:",omitempty"`
OvfId string `valid:"required"`
OvfOsType string `valid:"required"`
}

0 comments on commit 6d64453

Please sign in to comment.