Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(serverprofile): add force param to serverprofile creation #403

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
akshith-gunasheelan marked this conversation as resolved.
Show resolved Hide resolved
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, ",")
}
FalcoSuessgott marked this conversation as resolved.
Show resolved Hide resolved

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
Loading