Skip to content

Commit

Permalink
add ability to parse user template
Browse files Browse the repository at this point in the history
  • Loading branch information
si-mm committed Mar 4, 2024
1 parent ad365fd commit 448bd1d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cloud/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ type OS struct {
DiskBus string
}

// UserTemplate is the API payload based on the legacy xmlrpc backend.
type UserTemplate struct {
Description string
VCenterCCRRef string
VCenterDSRef string
VCenterInstanceID string
Error string
Hypervisor string
Info string
Logo string
SchedRequirements string
SchedDSRequirements string
SnapshotSchedule string
}

// History is the API payload based on the legacy xmlrpc backend.
type History struct {
ID int `json:"id" yaml:"id"`
Expand Down Expand Up @@ -262,6 +277,8 @@ type Disk struct {
TmMAD string
TmMADSystem string
Type string
VCenterDSRef string
VCenterInstanceID string
}

// Graphics is the API payload based on the legacy xmlrpc backend.
Expand Down
39 changes: 39 additions & 0 deletions cloud/instance/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,45 @@ func ParseTemplate(m map[string]any) (*Template, error) { // nolint:gocognit
return &dst, nil
}

// ParseUserTemplate return a structured Template based on the given map.
//
//nolint:gocritic
func ParseUserTemplate(m map[string]any) (*UserTemplate, error) { // nolint:gocognit
var dst UserTemplate

for key, value := range m {
switch v := value.(type) {
case string:
switch key {
case "SCHED_REQUIREMENTS":
dst.SchedRequirements = v
case "SCHED_DS_REQUIREMENTS":
dst.SchedDSRequirements = v
case "LOGO":
dst.Logo = v
case "INFO":
dst.Info = v
case "ERROR":
dst.Error = v
case "VCENTER_CCR_REF":
dst.VCenterCCRRef = v
case "VCENTER_DS_REF":
dst.VCenterDSRef = v
case "VCENTER_INSTANCE_ID":
dst.VCenterInstanceID = v
case "SNAPSHOT_SCHEDULE":
dst.SnapshotSchedule = v
case "HYPERVISOR":
dst.Hypervisor = v
case "DESCRIPTION":
dst.Description = v
}
}
}

return &dst, nil
}

func newInstanceContext(m map[string]any) (*Context, error) {
var dst Context

Expand Down
5 changes: 5 additions & 0 deletions cloud/payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ func (i *Instance) ParseTemplate() (*instance.Template, error) {
return instance.ParseTemplate(i.Template)
}

// ParseUserTemplate returns a structured subset of the nested key x value pair map.
func (i *Instance) ParseUserTemplate() (*instance.UserTemplate, error) {
return instance.ParseUserTemplate(i.UserTemplate)
}

// ParseTemplate returns a structured subset of the nested key x value pair map.
func (c *Cluster) ParseTemplate() (*ClusterTemplate, error) {
var t ClusterTemplate
Expand Down

0 comments on commit 448bd1d

Please sign in to comment.