2017-04-10 19:41:43 +03:00
/* -------------------------------------------------------------------------- */
2024-07-29 15:25:20 +03:00
/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */
2017-04-10 19:41:43 +03:00
/* */
/* 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. */
/* -------------------------------------------------------------------------- */
# ifndef EXTENDED_ATTRIBUTE_H_
# define EXTENDED_ATTRIBUTE_H_
# include <vector>
# include <map>
# include "Attribute.h"
# include "Template.h"
/**
* This class represents a generic attribute , it exposes the basic
* VectorAttribute interface and can be decorated with functionality
* for an specific class .
*
* The attribute operates directly on the OriginalTemplate attribute . IT
* IS NOT CLONED OR COPIED
*/
class ExtendedAttribute : public Attribute
{
public :
VectorAttribute * vector_attribute ( )
{
return va ;
}
/* ---------------------------------------------------------------------- */
/* VectorAttribute Interface */
/* ---------------------------------------------------------------------- */
template < typename T >
int vector_value ( const std : : string & name , T & value ) const
{
return va - > vector_value ( name , value ) ;
}
2023-03-08 17:52:20 +03:00
std : : string vector_value ( const std : : string & name )
2017-04-10 19:41:43 +03:00
{
return va - > vector_value ( name ) ;
}
2023-03-08 17:52:20 +03:00
const std : : string & vector_value ( const std : : string & name ) const
{
return const_cast < const VectorAttribute * > ( va ) - > vector_value ( name ) ;
}
2017-04-10 19:41:43 +03:00
template < typename T >
2023-03-08 17:52:20 +03:00
void replace ( const std : : string & name , const T & value )
2017-04-10 19:41:43 +03:00
{
va - > replace ( name , value ) ;
}
void remove ( const std : : string & name )
{
va - > remove ( name ) ;
}
void merge ( VectorAttribute * vattr , bool replace )
{
va - > merge ( vattr , replace ) ;
}
/* ---------------------------------------------------------------------- */
/* Attribute Interface */
/* ---------------------------------------------------------------------- */
2023-02-07 10:50:30 +03:00
std : : string marshall ( const char * _sep = 0 ) const override
2017-04-10 19:41:43 +03:00
{
return va - > marshall ( _sep ) ;
} ;
2023-02-07 10:50:30 +03:00
void to_xml ( std : : ostringstream & s ) const override
2017-04-10 19:41:43 +03:00
{
2019-01-30 02:10:18 +03:00
return va - > to_xml ( s ) ;
} ;
2023-02-07 10:50:30 +03:00
void to_json ( std : : ostringstream & s ) const override
2019-01-30 02:10:18 +03:00
{
return va - > to_json ( s ) ;
} ;
2024-01-08 15:56:40 +03:00
void to_xml ( std : : ostringstream & s ,
2024-06-03 12:40:24 +03:00
const std : : map < std : : string , std : : set < std : : string > > & hidden ) const override
2024-01-08 15:56:40 +03:00
{
return va - > to_xml ( s , hidden ) ;
}
2021-06-15 11:22:26 +03:00
protected :
/**
* Creates the attribute with a reference to a VectorAttribute . The object
* is shared and WILL BE modified through this interface .
* @ param va pointer to the VectorAttribute .
*/
ExtendedAttribute ( VectorAttribute * _va ) :
2024-06-03 12:40:24 +03:00
Attribute ( _va - > name ( ) ) , va ( _va ) , id ( - 1 ) { } ;
2021-06-15 11:22:26 +03:00
ExtendedAttribute ( VectorAttribute * _va , int _id ) :
2024-06-03 12:40:24 +03:00
Attribute ( _va - > name ( ) ) , va ( _va ) , id ( _id ) { } ;
2021-06-15 11:22:26 +03:00
2024-06-03 12:40:24 +03:00
virtual ~ ExtendedAttribute ( ) { } ;
2021-06-15 11:22:26 +03:00
/* ---------------------------------------------------------------------- */
/* Attribute Interface */
/* ---------------------------------------------------------------------- */
2023-02-07 10:50:30 +03:00
void unmarshall ( const std : : string & sattr , const char * _sep = 0 ) override
2017-04-10 19:41:43 +03:00
{
va - > unmarshall ( sattr , _sep ) ;
}
F #5989: Live update of Virtual Network attributes
co-authored-by: Pavel Czerný <pczerny@opennebula.systems>
co-authored-by: Frederick Borges <fborges@opennebula.io>
co-authored-by: Christian González <cgonzalez@opennebula.io>
* VNET updates trigger a driver action on running VMs with NICs in the
network.
* VNET includes a sets with VM status: updated, outdated, error and
updating. With VMs in each state.
* VNET flags error situations with a new state UPDATE_FAILURE.
* The same procedure is applied when an AR is updated (only VMs in that
AR are updated).
* A new options in the one.vn.recover API call enable to recover or
retry this VM update operations.
* The following attributes can be live-updated per VNET driver:
- PHYDEV (novlan, vlan, ovs driver)
- MTU (vlan, ovs driver)
- VLAN_ID (vlan, ovs driver)
- QINQ_TYPE (ovs driver)
- CVLANS (ovs driver)
- VLAN_TAGGED_ID (ovs driver)
- OUTER_VLAN_ID (ovs driver)
- INBOUND_AVG_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_KB (SG, ovs driver + KVM)
- OUTBOUND_AVG_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_KB (SG, ovs driver + KVM)
* New API call one.vm.updatenic, allows to update individual NICs
without the need of detach/attach (only QoS supported).
* Update operations for: 802.1Q, bridge, fw, ovswitch, ovswitch_vxlan
and vxlan network drivers.
* VNET attributes (old values) stored in VNET_UPDATE to allow
implementation of update operations. The attribute is removed after a
successful update.
* Updates to CLI onevnet (--retry option) / onevm (nicupdate command)
* XSD files updated to reflect the new data model
* Ruby and JAVA bindings updated: new VNET state and recover option, new
VM API call.
* Suntone and Fireedge implementation (lease status, recover option, new
states)
TODO: Virtual Functions does not support this functionality
iii
2022-11-16 15:35:29 +03:00
AttributeType type ( ) const override
2017-04-10 19:41:43 +03:00
{
return va - > type ( ) ;
F #5989: Live update of Virtual Network attributes
co-authored-by: Pavel Czerný <pczerny@opennebula.systems>
co-authored-by: Frederick Borges <fborges@opennebula.io>
co-authored-by: Christian González <cgonzalez@opennebula.io>
* VNET updates trigger a driver action on running VMs with NICs in the
network.
* VNET includes a sets with VM status: updated, outdated, error and
updating. With VMs in each state.
* VNET flags error situations with a new state UPDATE_FAILURE.
* The same procedure is applied when an AR is updated (only VMs in that
AR are updated).
* A new options in the one.vn.recover API call enable to recover or
retry this VM update operations.
* The following attributes can be live-updated per VNET driver:
- PHYDEV (novlan, vlan, ovs driver)
- MTU (vlan, ovs driver)
- VLAN_ID (vlan, ovs driver)
- QINQ_TYPE (ovs driver)
- CVLANS (ovs driver)
- VLAN_TAGGED_ID (ovs driver)
- OUTER_VLAN_ID (ovs driver)
- INBOUND_AVG_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_KB (SG, ovs driver + KVM)
- OUTBOUND_AVG_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_KB (SG, ovs driver + KVM)
* New API call one.vm.updatenic, allows to update individual NICs
without the need of detach/attach (only QoS supported).
* Update operations for: 802.1Q, bridge, fw, ovswitch, ovswitch_vxlan
and vxlan network drivers.
* VNET attributes (old values) stored in VNET_UPDATE to allow
implementation of update operations. The attribute is removed after a
successful update.
* Updates to CLI onevnet (--retry option) / onevm (nicupdate command)
* XSD files updated to reflect the new data model
* Ruby and JAVA bindings updated: new VNET state and recover option, new
VM API call.
* Suntone and Fireedge implementation (lease status, recover option, new
states)
TODO: Virtual Functions does not support this functionality
iii
2022-11-16 15:35:29 +03:00
}
2017-04-10 19:41:43 +03:00
F #5989: Live update of Virtual Network attributes
co-authored-by: Pavel Czerný <pczerny@opennebula.systems>
co-authored-by: Frederick Borges <fborges@opennebula.io>
co-authored-by: Christian González <cgonzalez@opennebula.io>
* VNET updates trigger a driver action on running VMs with NICs in the
network.
* VNET includes a sets with VM status: updated, outdated, error and
updating. With VMs in each state.
* VNET flags error situations with a new state UPDATE_FAILURE.
* The same procedure is applied when an AR is updated (only VMs in that
AR are updated).
* A new options in the one.vn.recover API call enable to recover or
retry this VM update operations.
* The following attributes can be live-updated per VNET driver:
- PHYDEV (novlan, vlan, ovs driver)
- MTU (vlan, ovs driver)
- VLAN_ID (vlan, ovs driver)
- QINQ_TYPE (ovs driver)
- CVLANS (ovs driver)
- VLAN_TAGGED_ID (ovs driver)
- OUTER_VLAN_ID (ovs driver)
- INBOUND_AVG_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_KB (SG, ovs driver + KVM)
- OUTBOUND_AVG_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_KB (SG, ovs driver + KVM)
* New API call one.vm.updatenic, allows to update individual NICs
without the need of detach/attach (only QoS supported).
* Update operations for: 802.1Q, bridge, fw, ovswitch, ovswitch_vxlan
and vxlan network drivers.
* VNET attributes (old values) stored in VNET_UPDATE to allow
implementation of update operations. The attribute is removed after a
successful update.
* Updates to CLI onevnet (--retry option) / onevm (nicupdate command)
* XSD files updated to reflect the new data model
* Ruby and JAVA bindings updated: new VNET state and recover option, new
VM API call.
* Suntone and Fireedge implementation (lease status, recover option, new
states)
TODO: Virtual Functions does not support this functionality
iii
2022-11-16 15:35:29 +03:00
Attribute * clone ( ) const override
2017-04-10 19:41:43 +03:00
{
return va - > clone ( ) ;
F #5989: Live update of Virtual Network attributes
co-authored-by: Pavel Czerný <pczerny@opennebula.systems>
co-authored-by: Frederick Borges <fborges@opennebula.io>
co-authored-by: Christian González <cgonzalez@opennebula.io>
* VNET updates trigger a driver action on running VMs with NICs in the
network.
* VNET includes a sets with VM status: updated, outdated, error and
updating. With VMs in each state.
* VNET flags error situations with a new state UPDATE_FAILURE.
* The same procedure is applied when an AR is updated (only VMs in that
AR are updated).
* A new options in the one.vn.recover API call enable to recover or
retry this VM update operations.
* The following attributes can be live-updated per VNET driver:
- PHYDEV (novlan, vlan, ovs driver)
- MTU (vlan, ovs driver)
- VLAN_ID (vlan, ovs driver)
- QINQ_TYPE (ovs driver)
- CVLANS (ovs driver)
- VLAN_TAGGED_ID (ovs driver)
- OUTER_VLAN_ID (ovs driver)
- INBOUND_AVG_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_BW (SG, ovs driver + KVM)
- INBOUND_PEAK_KB (SG, ovs driver + KVM)
- OUTBOUND_AVG_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_BW (SG, ovs driver + KVM)
- OUTBOUND_PEAK_KB (SG, ovs driver + KVM)
* New API call one.vm.updatenic, allows to update individual NICs
without the need of detach/attach (only QoS supported).
* Update operations for: 802.1Q, bridge, fw, ovswitch, ovswitch_vxlan
and vxlan network drivers.
* VNET attributes (old values) stored in VNET_UPDATE to allow
implementation of update operations. The attribute is removed after a
successful update.
* Updates to CLI onevnet (--retry option) / onevm (nicupdate command)
* XSD files updated to reflect the new data model
* Ruby and JAVA bindings updated: new VNET state and recover option, new
VM API call.
* Suntone and Fireedge implementation (lease status, recover option, new
states)
TODO: Virtual Functions does not support this functionality
iii
2022-11-16 15:35:29 +03:00
}
2017-04-10 19:41:43 +03:00
/* ---------------------------------------------------------------------- */
/* ExtendedAttribute Interface */
/* ---------------------------------------------------------------------- */
int get_id ( ) const
{
return id ;
}
private :
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
friend class ExtendedAttributeSet ;
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/**
* The associated VectorAttribute
*/
VectorAttribute * va ;
/**
* Set if the attribute can be addressed by an identifier , - 1 otherwise
*/
int id ;
} ;
/**
* This class represents a set of ExtendedAttributes it provides fast
* access to individual elements ( by ID ) and implement collective operations
*/
class ExtendedAttributeSet
{
protected :
/**
* Creates the ExtenededAttribute set
* @ param dispose elements upon set destruction
*/
2024-06-03 12:40:24 +03:00
ExtendedAttributeSet ( bool _dispose ) : dispose ( _dispose ) { } ;
2017-04-10 19:41:43 +03:00
virtual ~ ExtendedAttributeSet ( ) ;
/* ---------------------------------------------------------------------- */
/* Method to access attributes */
/* ---------------------------------------------------------------------- */
/**
2022-11-07 00:54:17 +03:00
* @ return attribute by id or nullptr if not found
2017-04-10 19:41:43 +03:00
*/
ExtendedAttribute * get_attribute ( int id ) const ;
2022-11-07 00:54:17 +03:00
/**
* @ return last_attribute or nullptr if empty set
*/
ExtendedAttribute * last_attribute ( ) const ;
2017-04-10 19:41:43 +03:00
/* ---------------------------------------------------------------------- */
/* Iterators */
/* ---------------------------------------------------------------------- */
/**
* Generic iterator for the set . Wraps the STL iterator for map , can be
* used to iterate over the attributes
*/
class AttributeIterator
{
public :
AttributeIterator & operator = ( const AttributeIterator & rhs )
{
map_it = rhs . map_it ;
return * this ;
}
AttributeIterator & operator + + ( )
{
+ + map_it ;
return * this ;
}
bool operator ! = ( const AttributeIterator & rhs )
{
return map_it ! = rhs . map_it ;
}
2024-06-03 12:40:24 +03:00
AttributeIterator ( ) { } ;
AttributeIterator ( const AttributeIterator & ait ) : map_it ( ait . map_it ) { } ;
2017-04-10 19:41:43 +03:00
AttributeIterator ( const std : : map < int ,
2024-06-03 12:40:24 +03:00
ExtendedAttribute * > : : iterator & _map_it ) : map_it ( _map_it ) { } ;
2017-04-10 19:41:43 +03:00
2024-06-03 12:40:24 +03:00
virtual ~ AttributeIterator ( ) { } ;
2017-04-10 19:41:43 +03:00
protected :
std : : map < int , ExtendedAttribute * > : : iterator map_it ;
} ;
AttributeIterator begin ( )
{
AttributeIterator it ( a_set . begin ( ) ) ;
return it ;
}
AttributeIterator end ( )
{
AttributeIterator it ( a_set . end ( ) ) ;
return it ;
}
typedef class AttributeIterator attribute_iterator ;
/* ---------------------------------------------------------------------- */
/* Attribute map interface */
/* ---------------------------------------------------------------------- */
/**
* Adds a new VirtualMachine attribute to the set
2017-04-13 19:31:14 +03:00
* @ param a the Extended attribute to add
* @ param id of the new attribute
2017-04-10 19:41:43 +03:00
*/
void add_attribute ( ExtendedAttribute * a , int id )
{
2020-07-02 23:42:10 +03:00
a_set . insert ( std : : make_pair ( id , a ) ) ;
2017-04-10 19:41:43 +03:00
}
2017-04-13 19:31:14 +03:00
/**
* Deletes an attribute from the set
* @ param id of the attribute
* @ return the attribute removed or 0 if not found
*/
ExtendedAttribute * delete_attribute ( int id ) ;
2017-04-10 19:41:43 +03:00
/**
* Init the attribute set from a vector
* @ param id_name with the ID of the attribute
* @ param auto_ids automatically generate ids for the attributes
* @ param vas vector of attribute to use
*/
void init_attribute_map ( const std : : string & id_name ,
2024-06-03 12:40:24 +03:00
std : : vector < VectorAttribute * > & vas ) ;
2017-04-10 19:41:43 +03:00
/**
* Abstract method to create the VirtualMachineAttributes for this set
*/
virtual ExtendedAttribute * attribute_factory ( VectorAttribute * va ,
2024-06-03 12:40:24 +03:00
int id ) const = 0 ;
2017-04-10 19:41:43 +03:00
2017-04-21 17:52:54 +03:00
/**
* @ return the number of elements in the set
*/
unsigned int size ( )
{
return a_set . size ( ) ;
}
2017-04-10 19:41:43 +03:00
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/**
* Map with the disk attributes
*/
std : : map < int , ExtendedAttribute * > a_set ;
/**
* Frees the VectorAttribute associated with each VirtualMachineAttribute
* upon object destruction
*/
bool dispose ;
} ;
# endif /*VIRTUAL_MACHINE_ATTRIBUTE_H_*/