Skip to content

Commit

Permalink
F #6311: manage marketplace 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 e013deb commit 36c1d88
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/oca/go/src/goca/schemas/marketplace/marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ type MarketPlace struct {
UsedMB int `xml:"USED_MB,omitempty"`
MarketPlaceAppsIDs shared.EntitiesID `xml:"MARKETPLACEAPPS,omitempty"`
Permissions *shared.Permissions `xml:"PERMISSIONS,omitempty"`
StateRaw int `xml:"STATE,omitempty"`
Template Template `xml:"TEMPLATE"`
}
61 changes: 61 additions & 0 deletions src/oca/go/src/goca/schemas/marketplace/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* -------------------------------------------------------------------------- */
/* 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 marketplace

import (
"fmt"
)

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

const (
Enabled State = iota
Disabled
)

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

func (s State) String() string {
return [...]string{
"ENABLED",
"DISABLED",
}[s]
}

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

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

0 comments on commit 36c1d88

Please sign in to comment.