diff --git a/init.go b/init.go index fe54e41..a9b5717 100644 --- a/init.go +++ b/init.go @@ -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", @@ -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.", }, diff --git a/models/server/create.go b/models/server/create.go index 8a8c594..b05e75a 100644 --- a/models/server/create.go +++ b/models/server/create.go @@ -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 { @@ -49,6 +56,15 @@ 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 } @@ -56,7 +72,13 @@ 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 } diff --git a/models/server/import.go b/models/server/import.go index 1e03a0a..008a7be 100644 --- a/models/server/import.go +++ b/models/server/import.go @@ -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"` }