From db21a75a3ca7abeb54cdff2bdab055e5acd3861c Mon Sep 17 00:00:00 2001 From: Pierre Lafievre Date: Thu, 7 Sep 2023 15:09:22 +0200 Subject: [PATCH] F #6311: manage marketplace state --- .../goca/schemas/marketplace/marketplace.go | 1 + .../go/src/goca/schemas/marketplace/state.go | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/oca/go/src/goca/schemas/marketplace/state.go diff --git a/src/oca/go/src/goca/schemas/marketplace/marketplace.go b/src/oca/go/src/goca/schemas/marketplace/marketplace.go index 0074ed6fa6e..8d367e6acf5 100644 --- a/src/oca/go/src/goca/schemas/marketplace/marketplace.go +++ b/src/oca/go/src/goca/schemas/marketplace/marketplace.go @@ -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"` } diff --git a/src/oca/go/src/goca/schemas/marketplace/state.go b/src/oca/go/src/goca/schemas/marketplace/state.go new file mode 100644 index 00000000000..a526d729aa3 --- /dev/null +++ b/src/oca/go/src/goca/schemas/marketplace/state.go @@ -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 and returns the ImageState +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 +}