Skip to content

Commit

Permalink
F #6311: manage marketplace appliance state
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Lafievre <[email protected]>
  • Loading branch information
treywelsh committed Sep 7, 2023
1 parent 387d779 commit 3ca354f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type MarketPlaceApp struct {
AppTemplate64 string `xml:"APPTEMPLATE64,omitempty"`
MarketPlaceID *int `xml:"MARKETPLACE_ID,omitempty"`
MarketPlace string `xml:"MARKETPLACE,omitempty"`
State int `xml:"STATE,omitempty"`
StateRaw int `xml:"STATE,omitempty"`
Type int `xml:"TYPE,omitempty"`
Template dyn.Template `xml:"TEMPLATE"`
}
67 changes: 67 additions & 0 deletions src/oca/go/src/goca/schemas/marketplaceapp/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/*--------------------------------------------------------------------------- */

package marketplaceapp

import (
"fmt"
)

// State is the state of an OpenNebula marketplace
type State int

const (
Init State = iota
Ready
Locked
Error
Disabled
)

func (s State) isValid() bool {
if s >= Init && s <= Disabled {
return true
}
return false
}

func (s State) String() string {
return [...]string{
"INIT",
"READY",
"LOCKED",
"ERROR",
"DISABLED",
}[s]
}

// State looks up the state of the marketplace and returns the ImageState
func (app *MarketPlaceApp) State() (State, error) {
state := State(app.StateRaw)
if !state.isValid() {
return -1, fmt.Errorf("Marketplace appliance State: this state value is not currently handled: %d\n", app.StateRaw)
}
return state, nil
}

// StateString returns the state in string format
func (app *MarketPlaceApp) StateString() (string, error) {
state := State(app.StateRaw)
if !state.isValid() {
return "", fmt.Errorf("Marketplace appliance StateString: this state value is not currently handled: %d\n", app.StateRaw)
}
return state.String(), nil
}

0 comments on commit 3ca354f

Please sign in to comment.