Skip to content

Commit

Permalink
Merge pull request #403 from FalcoSuessgott/server_profile_force
Browse files Browse the repository at this point in the history
feat(serverprofile): add force param to serverprofile creation
  • Loading branch information
akshith-gunasheelan authored Nov 9, 2023
2 parents 3ca3677 + c0c1883 commit 30a3fb8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
8 changes: 6 additions & 2 deletions examples/server_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func main() {
server_hardware = config.ServerProfileConfig.ServerHardwareName
scopeName = "SP-Scope"
spt_name = config.ServerProfileConfig.OvTemplatestring

// you can optionally ignore certain warnings when creatig a server profile
// omit flag parameter in SubmitNewProfile() or CreateProfileFromTemplate() for default value (none)
ignoreFlags = []ov.ForceFlag{ov.ForceIgnoreServerHealth}
)
ovc := ClientOV.NewOVClient(
config.OVCred.UserName,
Expand Down Expand Up @@ -52,7 +56,7 @@ func main() {
InitialScopeUris: *initialScopeUris,
}

err = ovc.SubmitNewProfile(server_profile_create_map)
err = ovc.SubmitNewProfile(server_profile_create_map, ignoreFlags...)
if err != nil {
fmt.Println("Server Profile Create Failed: ", err)
} else {
Expand All @@ -76,7 +80,7 @@ func main() {
if err != nil {
fmt.Println("Failed to fetch server hardware name: ", err)
} else {
err = ovc.CreateProfileFromTemplate(sp_by_spt, spt, serverName)
err = ovc.CreateProfileFromTemplate(sp_by_spt, spt, serverName, ignoreFlags...)
if err != nil {
fmt.Println("Server Profile Create Failed: ", err)
} else {
Expand Down
55 changes: 51 additions & 4 deletions ov/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,44 @@ import (
"fmt"
"os"
"reflect"
"strings"

"github.com/HewlettPackard/oneview-golang/rest"
"github.com/HewlettPackard/oneview-golang/utils"
"github.com/docker/machine/libmachine/log"
)

type ForceFlag int

const (
// ForceIgnoreSANWarnings When provided, the operation will ignore warnings for non-critical issues detected in the SAN storage configuration.
ForceIgnoreSANWarnings ForceFlag = iota

// ForceIgnoreServerHealth When provided, the operation will ignore the check to verify that the selected server's health is OK.
ForceIgnoreServerHealth

// ForceIgnoreLSWarnings When provided, the operation will ignore the validation warnings from local storage.
ForceIgnoreLSWarnings

// ForceIgnoreAll When provided, all warnings will be ignored.
ForceIgnoreAll

// ForceIgnoreNone When provided, none of the warnings will be ignored.
ForceIgnoreNone
)

func (f ForceFlag) String() string {
forceFlagMap := map[ForceFlag]string{
ForceIgnoreSANWarnings: "ignoreSANWarnings",
ForceIgnoreServerHealth: "ignoreServerHealth",
ForceIgnoreLSWarnings: "ignoreLSWarnings",
ForceIgnoreAll: "all",
ForceIgnoreNone: "none",
}

return forceFlagMap[f]
}

// FirmwareOption structure for firware settings
type FirmwareOption struct {
ComplianceControl string `json:"complianceControl,omitempty"` // complianceControl
Expand Down Expand Up @@ -395,12 +427,16 @@ func (c *OVClient) GetAvailableServers(ServerHardwareUri string) (bool, error) {
}

// SubmitNewProfile - submit new profile template
func (c *OVClient) SubmitNewProfile(p ServerProfile) (err error) {
func (c *OVClient) SubmitNewProfile(p ServerProfile, ignoreFlags ...ForceFlag) (err error) {
log.Infof("Initializing creation of server profile for %s.", p.Name)
var (
uri = "/rest/server-profiles"
server ServerHardware
t *Task
// if no warning flags has been provided, use default value:
forceFlags = map[string]interface{}{
"force": ForceIgnoreNone,
}
)
// refresh login
c.RefreshLogin()
Expand Down Expand Up @@ -449,7 +485,18 @@ func (c *OVClient) SubmitNewProfile(p ServerProfile) (err error) {
p.ManagementProcessor = mp
}

data, err := c.RestAPICall(rest.POST, uri, p)
// append force flags comma separated
if len(ignoreFlags) > 0 {
var flags []string

for _, i := range ignoreFlags {
flags = append(flags, i.String())
}

forceFlags["force"] = strings.Join(flags, ",")
}

data, err := c.RestAPICall(rest.POST, uri, p, forceFlags)
if err != nil {
t.TaskIsDone = true
log.Errorf("Error submitting new profile request: %s", err)
Expand All @@ -472,7 +519,7 @@ func (c *OVClient) SubmitNewProfile(p ServerProfile) (err error) {
}

// create profile from template
func (c *OVClient) CreateProfileFromTemplate(name string, template ServerProfile, blade ServerHardware) error {
func (c *OVClient) CreateProfileFromTemplate(name string, template ServerProfile, blade ServerHardware, ignoreFlags ...ForceFlag) error {
log.Debugf("TEMPLATE : %+v\n", template)
var (
new_template ServerProfile
Expand Down Expand Up @@ -513,7 +560,7 @@ func (c *OVClient) CreateProfileFromTemplate(name string, template ServerProfile
new_template.Name = name
log.Debugf("new_template -> %+v", new_template)

err = c.SubmitNewProfile(new_template)
err = c.SubmitNewProfile(new_template, ignoreFlags...)
return err
}

Expand Down

0 comments on commit 30a3fb8

Please sign in to comment.