mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
* F #2830: GOCA - fix: clean structs in Info call to prevent keeping old data * F #2830: GOCA - fix: remove struct shared parts as it imply more code complexity than needed
This commit is contained in:
parent
3c75f62317
commit
9b0a8cde85
@ -160,5 +160,6 @@ func (cluster *Cluster) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*cluster = Cluster{}
|
||||
return xml.Unmarshal([]byte(response.Body()), cluster)
|
||||
}
|
||||
|
@ -183,6 +183,7 @@ func (datastore *Datastore) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*datastore = Datastore{}
|
||||
return xml.Unmarshal([]byte(response.Body()), datastore)
|
||||
}
|
||||
|
||||
|
@ -7,24 +7,22 @@ import (
|
||||
|
||||
// GroupPool represents an OpenNebula GroupPool
|
||||
type GroupPool struct {
|
||||
Groups []groupBase `xml:"GROUP"`
|
||||
Quotas []quotas `xml:"QUOTAS"`
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
Groups []Group `xml:"GROUP"`
|
||||
Quotas []quotas `xml:"QUOTAS"`
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
}
|
||||
|
||||
// Group represents an OpenNebula Group
|
||||
type Group struct {
|
||||
groupBase
|
||||
quotasList
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
}
|
||||
|
||||
type groupBase struct {
|
||||
ID uint `xml:"ID"`
|
||||
Name string `xml:"NAME"`
|
||||
Users []int `xml:"USERS>ID"`
|
||||
Admins []int `xml:"ADMINS>ID"`
|
||||
Template groupTemplate `xml:"TEMPLATE"`
|
||||
|
||||
// Variable part between one.grouppool.info and one.group.info
|
||||
quotasList
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
}
|
||||
|
||||
type groupTemplate struct {
|
||||
@ -50,7 +48,7 @@ func NewGroupPool() (*GroupPool, error) {
|
||||
|
||||
// NewGroup finds a group object by ID. No connection to OpenNebula.
|
||||
func NewGroup(id uint) *Group {
|
||||
return &Group{groupBase: groupBase{ID: id}}
|
||||
return &Group{ID: id}
|
||||
}
|
||||
|
||||
// NewGroupFromName finds a group object by name. It connects to
|
||||
@ -104,6 +102,7 @@ func (group *Group) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*group = Group{}
|
||||
return xml.Unmarshal([]byte(response.Body()), group)
|
||||
}
|
||||
|
||||
|
@ -219,6 +219,7 @@ func (host *Host) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*host = Host{}
|
||||
return xml.Unmarshal([]byte(response.Body()), host)
|
||||
}
|
||||
|
||||
|
@ -193,6 +193,7 @@ func (image *Image) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*image = Image{}
|
||||
return xml.Unmarshal([]byte(response.Body()), image)
|
||||
}
|
||||
|
||||
|
@ -164,5 +164,6 @@ func (market *MarketPlace) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*market = MarketPlace{}
|
||||
return xml.Unmarshal([]byte(response.Body()), market)
|
||||
}
|
||||
|
@ -180,6 +180,7 @@ func (marketApp *MarketPlaceApp) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*marketApp = MarketPlaceApp{}
|
||||
return xml.Unmarshal([]byte(response.Body()), marketApp)
|
||||
}
|
||||
|
||||
|
@ -186,5 +186,6 @@ func (sg *SecurityGroup) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*sg = SecurityGroup{}
|
||||
return xml.Unmarshal([]byte(response.Body()), sg)
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ func (template *Template) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*template = Template{}
|
||||
return xml.Unmarshal([]byte(response.Body()), template)
|
||||
}
|
||||
|
||||
|
@ -7,20 +7,13 @@ import (
|
||||
|
||||
// UserPool represents an OpenNebula UserPool
|
||||
type UserPool struct {
|
||||
Users []userBase `xml:"USER"`
|
||||
Users []User `xml:"USER"`
|
||||
Quotas []quotas `xml:"QUOTAS"`
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
}
|
||||
|
||||
// User represents an OpenNebula user
|
||||
type User struct {
|
||||
userBase
|
||||
quotasList
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
}
|
||||
|
||||
// User represents an OpenNebula User
|
||||
type userBase struct {
|
||||
ID uint `xml:"ID"`
|
||||
GID int `xml:"GID"`
|
||||
GroupsID []int `xml:"GROUPS>ID"`
|
||||
@ -31,6 +24,10 @@ type userBase struct {
|
||||
Enabled int `xml:"ENABLED"`
|
||||
LoginTokens []loginToken `xml:"LOGIN_TOKEN"`
|
||||
Template userTemplate `xml:"TEMPLATE"`
|
||||
|
||||
// Variable part between one.userpool.info and one.user.info
|
||||
quotasList
|
||||
DefaultUserQuotas quotasList `xml:"DEFAULT_USER_QUOTAS"`
|
||||
}
|
||||
|
||||
type userTemplate struct {
|
||||
@ -62,7 +59,7 @@ func NewUserPool() (*UserPool, error) {
|
||||
|
||||
// NewUser finds a user object by ID. No connection to OpenNebula.
|
||||
func NewUser(id uint) *User {
|
||||
return &User{userBase: userBase{ID: id}}
|
||||
return &User{ID: id}
|
||||
}
|
||||
|
||||
// NewUserFromName finds a user object by name. It connects to
|
||||
@ -180,5 +177,6 @@ func (user *User) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*user = User{}
|
||||
return xml.Unmarshal([]byte(response.Body()), user)
|
||||
}
|
||||
|
@ -138,6 +138,7 @@ func (vdc *Vdc) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*vdc = Vdc{}
|
||||
return xml.Unmarshal([]byte(response.Body()), vdc)
|
||||
}
|
||||
|
||||
|
@ -7,18 +7,11 @@ import (
|
||||
|
||||
// VirtualNetworkPool represents an OpenNebula VirtualNetworkPool
|
||||
type VirtualNetworkPool struct {
|
||||
VirtualNetworks []virtualNetworkPoolBase `xml:"VNET"`
|
||||
VirtualNetworks []VirtualNetwork `xml:"VNET"`
|
||||
}
|
||||
|
||||
// VirtualNetwork represents an OpenNebula VirtualNetwork
|
||||
type VirtualNetwork struct {
|
||||
virtualNetworkBase
|
||||
Lock *Lock `xml:"LOCK"`
|
||||
ARs []virtualNetworkAR `xml:"AR_POOL>AR"`
|
||||
}
|
||||
|
||||
// VirtualNetworkBase represents common attributes for parts of VirtualNetworkPool and VirtualNetwork
|
||||
type virtualNetworkBase struct {
|
||||
ID uint `xml:"ID"`
|
||||
UID int `xml:"UID"`
|
||||
GID int `xml:"GID"`
|
||||
@ -39,47 +32,39 @@ type virtualNetworkBase struct {
|
||||
UsedLeases int `xml:"USED_LEASES"`
|
||||
VRouters []int `xml:"VROUTERS>ID"`
|
||||
Template virtualNetworkTemplate `xml:"TEMPLATE"`
|
||||
|
||||
// Variable parts between one.vnpool.info and one.vn.info
|
||||
ARs []virtualNetworkAR `xml:"AR_POOL>AR"`
|
||||
Lock *Lock `xml:"LOCK"`
|
||||
}
|
||||
|
||||
type virtualNetworkTemplate struct {
|
||||
Dynamic unmatchedTagsSlice `xml:",any"`
|
||||
}
|
||||
|
||||
// AR represent an Address Range
|
||||
type virtualNetworkPoolBase struct {
|
||||
virtualNetworkBase
|
||||
ARs []virtualNetworkARPool `xml:"AR_POOL>AR"`
|
||||
}
|
||||
|
||||
type virtualNetworkARBase struct {
|
||||
ARID string `xml:"AR_ID"`
|
||||
GlobalPrefix string `xml:"GLOBAL_PREFIX"` // minOccurs=0
|
||||
IP string `xml:"IP"` // minOccurs=0
|
||||
MAC string `xml:"MAC"`
|
||||
ParentNetworkARID string `xml:"PARENT_NETWORK_AR_ID"` // minOccurs=0
|
||||
Size int `xml:"SIZE"`
|
||||
Type string `xml:"TYPE"`
|
||||
ULAPrefix string `xml:"ULA_PREFIX"` // minOccurs=0
|
||||
VNMAD string `xml:"VN_MAD"` // minOccurs=0
|
||||
}
|
||||
|
||||
type virtualNetworkARPool struct {
|
||||
virtualNetworkARBase
|
||||
Allocated string `xml:ALLOCATED`
|
||||
}
|
||||
|
||||
type virtualNetworkAR struct {
|
||||
virtualNetworkARBase
|
||||
MACEnd string `xml:"MAC_END"`
|
||||
IPEnd string `xml:"IP_END"`
|
||||
IP6ULA string `xml:"IP6_ULA"`
|
||||
IP6ULAEnd string `xml:"IP6_ULA_END"`
|
||||
IP6Global string `xml:"IP6_GLOBAL"`
|
||||
IP6GlobalEnd string `xml:"IP6_GLOBAL_END"`
|
||||
IP6 string `xml:"IP6"`
|
||||
IP6End string `xml:"IP6_END"`
|
||||
UsedLeases string `xml:"USED_LEASES"`
|
||||
Leases []lease `xml:"LEASES>LEASE"`
|
||||
ARID string `xml:"AR_ID"`
|
||||
GlobalPrefix string `xml:"GLOBAL_PREFIX"` // minOccurs=0
|
||||
IP string `xml:"IP"` // minOccurs=0
|
||||
MAC string `xml:"MAC"`
|
||||
ParentNetworkARID string `xml:"PARENT_NETWORK_AR_ID"` // minOccurs=0
|
||||
Size int `xml:"SIZE"`
|
||||
Type string `xml:"TYPE"`
|
||||
ULAPrefix string `xml:"ULA_PREFIX"` // minOccurs=0
|
||||
VNMAD string `xml:"VN_MAD"` // minOccurs=0
|
||||
MACEnd string `xml:"MAC_END"`
|
||||
IPEnd string `xml:"IP_END"`
|
||||
IP6ULA string `xml:"IP6_ULA"`
|
||||
IP6ULAEnd string `xml:"IP6_ULA_END"`
|
||||
IP6Global string `xml:"IP6_GLOBAL"`
|
||||
IP6GlobalEnd string `xml:"IP6_GLOBAL_END"`
|
||||
IP6 string `xml:"IP6"`
|
||||
IP6End string `xml:"IP6_END"`
|
||||
UsedLeases string `xml:"USED_LEASES"`
|
||||
Leases []lease `xml:"LEASES>LEASE"`
|
||||
|
||||
// Not filled with Info
|
||||
Allocated string `xml:ALLOCATED`
|
||||
}
|
||||
|
||||
type lease struct {
|
||||
@ -132,7 +117,7 @@ func NewVirtualNetworkPool(args ...int) (*VirtualNetworkPool, error) {
|
||||
|
||||
// NewVirtualNetwork finds a virtualnetwork object by ID. No connection to OpenNebula.
|
||||
func NewVirtualNetwork(id uint) *VirtualNetwork {
|
||||
return &VirtualNetwork{virtualNetworkBase: virtualNetworkBase{ID: id}}
|
||||
return &VirtualNetwork{ID: id}
|
||||
}
|
||||
|
||||
// NewVirtualNetworkFromName finds a virtualnetwork object by name. It connects to
|
||||
@ -275,5 +260,6 @@ func (vn *VirtualNetwork) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*vn = VirtualNetwork{}
|
||||
return xml.Unmarshal([]byte(response.Body()), vn)
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ func (vr *VirtualRouter) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*vr = VirtualRouter{}
|
||||
return xml.Unmarshal([]byte(response.Body()), vr)
|
||||
}
|
||||
|
||||
|
@ -8,16 +8,11 @@ import (
|
||||
|
||||
// VMPool represents an OpenNebula Virtual Machine pool
|
||||
type VMPool struct {
|
||||
VMs []vmBase `xml:"VM"`
|
||||
VMs []VM `xml:"VM"`
|
||||
}
|
||||
|
||||
// VM represents an OpenNebula Virtual Machine
|
||||
type VM struct {
|
||||
vmBase
|
||||
LockInfos *Lock `xml:"LOCK"`
|
||||
}
|
||||
|
||||
type vmBase struct {
|
||||
ID uint `xml:"ID"`
|
||||
UID int `xml:"UID"`
|
||||
GID int `xml:"GID"`
|
||||
@ -34,10 +29,13 @@ type vmBase struct {
|
||||
STime int `xml:"STIME"`
|
||||
ETime int `xml:"ETIME"`
|
||||
DeployID string `xml:"DEPLOY_ID"`
|
||||
Monitoring vmMonitoring `xml:"MONITORING"`
|
||||
MonitoringInfos vmMonitoring `xml:"MONITORING"`
|
||||
Template vmTemplate `xml:"TEMPLATE"`
|
||||
UserTemplate *vmUserTemplate `xml:"USER_TEMPLATE"`
|
||||
HistoryRecords []vmHistoryRecord `xml:"HISTORY_RECORDS>HISTORY"`
|
||||
|
||||
// Not filled with NewUserPool call
|
||||
LockInfos *Lock `xml:"LOCK"`
|
||||
}
|
||||
|
||||
type vmMonitoring struct {
|
||||
@ -675,7 +673,7 @@ func CreateVM(template string, pending bool) (uint, error) {
|
||||
// NewVM finds an VM by ID returns a new VM object. At this stage no
|
||||
// connection to OpenNebula is performed.
|
||||
func NewVM(id uint) *VM {
|
||||
return &VM{vmBase: vmBase{ID: id}}
|
||||
return &VM{ID: id}
|
||||
}
|
||||
|
||||
// NewVMFromName finds the VM by name and returns a VM object. It connects to
|
||||
@ -708,7 +706,7 @@ func NewVMFromName(name string) (*VM, error) {
|
||||
}
|
||||
|
||||
// State returns the VMState and LCMState
|
||||
func (vm *vmBase) State() (VMState, LCMState, error) {
|
||||
func (vm *VM) State() (VMState, LCMState, error) {
|
||||
state := VMState(vm.StateRaw)
|
||||
if !state.isValid() {
|
||||
return -1, -1, fmt.Errorf("VM State: this state value is not currently handled: %d\n", vm.StateRaw)
|
||||
@ -721,7 +719,7 @@ func (vm *vmBase) State() (VMState, LCMState, error) {
|
||||
}
|
||||
|
||||
// StateString returns the VMState and LCMState as strings
|
||||
func (vm *vmBase) StateString() (string, string, error) {
|
||||
func (vm *VM) StateString() (string, string, error) {
|
||||
state := VMState(vm.StateRaw)
|
||||
if !state.isValid() {
|
||||
return "", "", fmt.Errorf("VM State: this state value is not currently handled: %d\n", vm.StateRaw)
|
||||
@ -745,6 +743,7 @@ func (vm *VM) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*vm = VM{}
|
||||
return xml.Unmarshal([]byte(response.Body()), vm)
|
||||
}
|
||||
|
||||
|
@ -114,6 +114,7 @@ func (vntemplate *VNTemplate) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*vntemplate = VNTemplate{}
|
||||
return xml.Unmarshal([]byte(response.Body()), vntemplate)
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,7 @@ func (zone *Zone) Info() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*zone = Zone{}
|
||||
return xml.Unmarshal([]byte(response.Body()), zone)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user