2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2024-07-29 15:25:20 +03:00
/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */
2008-06-17 20:27:32 +04: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 ATTRIBUTE_H_
# define ATTRIBUTE_H_
# include <string>
# include <map>
# include <sstream>
2009-03-06 15:10:15 +03:00
# include <algorithm>
2008-06-17 20:27:32 +04:00
2016-03-03 14:32:36 +03:00
# include "NebulaUtil.h"
2008-06-17 20:27:32 +04:00
/**
* Attribute base class for name - value pairs . This class provides a generic
2009-03-06 15:10:15 +03:00
* interface to implement
2008-06-17 20:27:32 +04:00
*/
class Attribute
{
public :
2023-03-08 17:52:20 +03:00
Attribute ( const std : : string & aname )
: attribute_name ( aname )
2008-06-17 20:27:32 +04:00
{
2023-03-08 17:52:20 +03:00
one_util : : toupper ( attribute_name ) ;
2011-05-08 04:13:37 +04:00
// FIX Attribute name if it does not conform XML element
// naming conventions
int size = attribute_name . size ( ) ;
2017-06-15 18:06:43 +03:00
if ( ( size > 0 & & ! ( isalpha ( aname [ 0 ] ) | | aname [ 0 ] = = ' _ ' ) ) | |
2011-05-08 04:13:37 +04:00
( size > = 3 & & ( aname [ 0 ] = = ' X ' & & aname [ 1 ] = = ' M ' & & aname [ 2 ] = = ' L ' ) ) )
{
2024-06-03 12:40:24 +03:00
attribute_name . insert ( 0 , " ONE_ " ) ;
2011-05-08 04:13:37 +04:00
}
2008-06-17 20:27:32 +04:00
} ;
2024-06-03 12:40:24 +03:00
virtual ~ Attribute ( ) { } ;
2008-06-17 20:27:32 +04:00
enum AttributeType
{
SIMPLE = 0 ,
VECTOR = 1
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Gets the name of the attribute .
* @ return the attribute name
*/
2020-07-02 23:42:10 +03:00
const std : : string & name ( ) const
2008-06-17 20:27:32 +04:00
{
return attribute_name ;
} ;
/**
2020-09-15 12:16:00 +03:00
* Marshall the attribute in a single string .
* @ return a string holding the attribute value .
2008-06-17 20:27:32 +04:00
*/
2020-09-15 12:16:00 +03:00
virtual std : : string marshall ( const char * _sep = 0 ) const = 0 ;
2009-03-06 15:10:15 +03:00
2009-01-26 21:25:15 +03:00
/**
2023-09-14 16:36:26 +03:00
* Write the attribute using a simple XML format .
2009-01-26 21:25:15 +03:00
*/
2019-01-30 02:10:18 +03:00
virtual void to_xml ( std : : ostringstream & s ) const = 0 ;
virtual void to_json ( std : : ostringstream & s ) const = 0 ;
2024-01-08 15:56:40 +03:00
virtual 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 = 0 ;
2024-01-08 15:56:40 +03:00
2008-06-17 20:27:32 +04:00
/**
* Builds a new attribute from a string .
*/
2020-07-02 23:42:10 +03:00
virtual void unmarshall ( const std : : string & sattr , const char * _sep = 0 ) = 0 ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Returns the attribute 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
virtual AttributeType type ( ) const = 0 ;
2008-06-17 20:27:32 +04:00
2011-04-11 01:55:49 +04:00
/**
* Clones the current attribute
*/
virtual Attribute * clone ( ) const = 0 ;
2008-06-17 20:27:32 +04:00
2019-09-16 16:51:38 +03:00
/**
* Encrypt all secret attributes
*/
2020-07-02 23:42:10 +03:00
virtual void encrypt ( const std : : string & one_key , const std : : set < std : : string > & eas ) { } ;
2019-09-16 16:51:38 +03:00
/**
* Decrypt all secret attributes
*/
2020-07-02 23:42:10 +03:00
virtual void decrypt ( const std : : string & one_key , const std : : set < std : : string > & eas ) { } ;
2019-09-16 16:51:38 +03:00
2011-04-11 01:55:49 +04:00
protected :
2019-09-16 16:51:38 +03:00
2008-06-17 20:27:32 +04:00
/**
* The attribute name .
*/
2020-07-02 23:42:10 +03:00
std : : string attribute_name ;
2023-03-08 17:52:20 +03:00
static const std : : string EMPTY_ATTRIBUTE ;
2008-06-17 20:27:32 +04:00
} ;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/**
2009-03-06 15:10:15 +03:00
* The SingleAttribute class represents a simple attribute in the form
* NAME = VALUE .
2008-06-17 20:27:32 +04:00
*/
class SingleAttribute : public Attribute
{
public :
2023-01-31 15:46:09 +03:00
SingleAttribute ( const std : : string & name )
: Attribute ( name )
{ }
2008-06-17 20:27:32 +04:00
2023-01-31 15:46:09 +03:00
SingleAttribute ( const std : : string & name , const std : : string & value )
: Attribute ( name )
, attribute_value ( value )
{ }
2009-03-06 15:10:15 +03:00
2023-01-31 15:46:09 +03:00
SingleAttribute ( const SingleAttribute & sa )
: Attribute ( sa . attribute_name )
, attribute_value ( sa . attribute_value )
{ }
2011-04-11 01:55:49 +04:00
2024-06-03 12:40:24 +03:00
~ SingleAttribute ( ) { } ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Returns the attribute value , a string .
*/
2020-07-02 23:42:10 +03:00
const std : : string & value ( ) const
2008-06-17 20:27:32 +04:00
{
return attribute_value ;
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
2020-09-15 12:16:00 +03:00
* Marshall the attribute in a single string .
* @ return a string holding the attribute value .
2009-03-06 15:10:15 +03:00
*/
2020-09-15 12:16:00 +03:00
std : : string marshall ( const char * _sep = 0 ) const override
2008-06-17 20:27:32 +04:00
{
2020-09-15 12:16:00 +03:00
return attribute_value ;
2008-06-17 20:27:32 +04:00
} ;
2009-03-06 15:10:15 +03:00
2009-01-26 21:25:15 +03:00
/**
* Write the attribute using a simple XML format :
2009-03-06 15:10:15 +03:00
*
* < attribute_name > attribute_value < / attribute_name >
*
2019-01-30 02:10:18 +03:00
* @ paran s the stream to write the attribute .
2024-01-08 15:56:40 +03:00
*
* NOTE : For Simple attributes hidden are in the form { " PORT " . { } }
* A hidden attribute is rendered as * * *
2009-01-26 21:25:15 +03:00
*/
2020-03-04 18:05:57 +03:00
void to_xml ( std : : ostringstream & s ) const override
2009-01-26 21:25:15 +03:00
{
2019-01-30 02:10:18 +03:00
s < < " < " < < attribute_name < < " > " < < one_util : : escape_xml ( attribute_value )
< < " </ " < < attribute_name < < " > " ;
2009-03-06 15:10:15 +03:00
2019-01-30 02:10:18 +03:00
}
2009-03-06 15:10:15 +03:00
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
{
s < < " < " < < attribute_name < < " > " ;
if ( hidden . find ( attribute_name ) ! = hidden . end ( ) )
{
2024-06-03 12:40:24 +03:00
s < < " *** " ;
2024-01-08 15:56:40 +03:00
}
else
{
2024-06-03 12:40:24 +03:00
s < < one_util : : escape_xml ( attribute_value ) ;
2024-01-08 15:56:40 +03:00
}
s < < " </ " < < attribute_name < < " > " ;
}
2020-03-04 18:05:57 +03:00
void to_json ( std : : ostringstream & s ) const override
2019-01-30 02:10:18 +03:00
{
2019-09-16 16:51:38 +03:00
one_util : : escape_json ( attribute_value , s ) ;
2019-01-30 02:10:18 +03:00
}
2008-06-17 20:27:32 +04:00
/**
* Builds a new attribute from a string .
2009-03-06 15:10:15 +03:00
*/
2020-07-02 23:42:10 +03:00
void unmarshall ( const std : : string & sattr , const char * _sep = 0 ) override
2008-06-17 20:27:32 +04:00
{
attribute_value = sattr ;
} ;
2008-11-13 19:21:17 +03:00
/**
* Replaces the attribute value from a string .
*/
2020-07-02 23:42:10 +03:00
void replace ( const std : : string & sattr )
2008-11-13 19:21:17 +03:00
{
attribute_value = sattr ;
} ;
2008-06-17 20:27:32 +04:00
/**
* Returns the attribute type
2009-03-06 15:10:15 +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
AttributeType type ( ) const override
2008-06-17 20:27:32 +04:00
{
return SIMPLE ;
} ;
2009-03-06 15:10:15 +03:00
2011-04-11 01:55:49 +04:00
/**
* Clones the current attribute
*/
2020-03-04 18:05:57 +03:00
Attribute * clone ( ) const override
2011-04-11 01:55:49 +04:00
{
2012-12-24 05:41:17 +04:00
return new SingleAttribute ( * this ) ;
2011-04-11 01:55:49 +04:00
} ;
2019-09-16 16:51:38 +03:00
/**
* Encrypt all secret attributes
*/
2020-07-02 23:42:10 +03:00
void encrypt ( const std : : string & one_key ,
const std : : set < std : : string > & eas ) override ;
2019-09-16 16:51:38 +03:00
/**
* Decrypt all secret attributes
*/
2020-07-02 23:42:10 +03:00
void decrypt ( const std : : string & one_key ,
const std : : set < std : : string > & eas ) override ;
2019-09-16 16:51:38 +03:00
2008-06-17 20:27:32 +04:00
private :
2020-07-02 23:42:10 +03:00
std : : string attribute_value ;
2008-06-17 20:27:32 +04:00
} ;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/**
2009-03-06 15:10:15 +03:00
* The VectorAttribute class represents an array attribute in the form
* NAME = [ VAL_NAME_1 = VAL_VALUE_1 , . . . , VAL_NAME_N = VAL_VALUE_N ] .
2008-06-17 20:27:32 +04:00
*/
class VectorAttribute : public Attribute
{
public :
2023-01-31 15:46:09 +03:00
VectorAttribute ( const std : : string & name )
: Attribute ( name )
{ }
2008-06-17 20:27:32 +04:00
2020-07-02 23:42:10 +03:00
VectorAttribute ( const std : : string & name ,
2024-06-03 12:40:24 +03:00
const std : : map < std : : string , std : : string > & value )
2023-01-31 15:46:09 +03:00
: Attribute ( name )
, attribute_value ( value )
{ }
2023-03-08 17:52:20 +03:00
VectorAttribute ( const VectorAttribute & va ) = default ;
2023-01-31 15:46:09 +03:00
VectorAttribute ( const VectorAttribute * va )
: Attribute ( va - > attribute_name )
, attribute_value ( va - > attribute_value )
{ }
2016-03-01 14:09:15 +03:00
2023-03-08 17:52:20 +03:00
VectorAttribute & operator = ( const VectorAttribute & va ) = default ;
2024-06-03 12:40:24 +03:00
~ VectorAttribute ( ) { } ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Returns the attribute value , a string .
*/
2024-06-03 12:40:24 +03:00
const std : : map < std : : string , std : : string > & value ( ) const
2008-06-17 20:27:32 +04:00
{
return attribute_value ;
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
2012-06-02 04:58:46 +04:00
* Returns the string value
* @ param name of the attribute
2008-06-17 20:27:32 +04:00
*
2023-03-08 17:52:20 +03:00
* @ return copy of the value of the attribute if found , empty otherwise
*
* @ note Non const version must return copy , as subsequent call to replace or remove
* may change the value
*/
std : : string vector_value ( const std : : string & name ) ;
/**
* Returns the string value
* @ param name of the attribute
*
* @ return reference of the value of the attribute if found , empty otherwise
*
* @ note It ' s safe to return reference here , as we are using
* the const object , which can ' t change the value
2008-06-17 20:27:32 +04:00
*/
2023-03-08 17:52:20 +03:00
const std : : string & vector_value ( const std : : string & name ) const ;
2009-03-06 15:10:15 +03:00
2015-02-18 14:16:16 +03:00
/**
2016-02-04 15:10:42 +03:00
* Returns the value of the given element of the VectorAttribute
2012-12-24 05:41:17 +04:00
*
2016-02-04 15:10:42 +03:00
* @ param name of the attribute
* @ param value , not set if the element is not found of has invalid type
2012-03-06 21:44:22 +04:00
*
* @ return 0 on success , - 1 otherwise
*/
2016-02-04 15:10:42 +03:00
template < typename T >
2020-07-02 23:42:10 +03:00
int vector_value ( const std : : string & name , T & value ) const
2016-02-04 15:10:42 +03:00
{
2020-07-02 23:42:10 +03:00
auto it = attribute_value . find ( name ) ;
2014-05-02 16:11:36 +04:00
2016-02-04 15:10:42 +03:00
if ( it = = attribute_value . end ( ) )
{
return - 1 ;
}
2013-10-17 14:35:19 +04:00
2016-02-04 15:10:42 +03:00
if ( it - > second . empty ( ) )
{
return - 1 ;
}
2021-06-24 11:52:46 +03:00
if ( std : : is_unsigned < T > : : value )
{
// Do not accept negative values for unsigned
if ( one_util : : trim ( it - > second ) [ 0 ] = = ' - ' )
{
return - 1 ;
}
}
2020-07-02 23:42:10 +03:00
std : : istringstream iss ( it - > second ) ;
2016-02-04 15:10:42 +03:00
iss > > value ;
if ( iss . fail ( ) | | ! iss . eof ( ) )
{
return - 1 ;
}
return 0 ;
}
2020-03-04 18:05:57 +03:00
/**
* Returns the value of the given element of the VectorAttribute .
* If element is invalid , returns default value
*
* @ param name of the attribute
* @ param value always set , if element is invalid set default_value
* @ param default_value used if element is invalid
*/
template < typename T >
2020-07-02 23:42:10 +03:00
void vector_value ( const std : : string & name ,
T & value ,
const T & default_value ) const
2020-03-04 18:05:57 +03:00
{
if ( vector_value ( name , value ) ! = 0 )
{
value = default_value ;
}
}
2020-07-02 23:42:10 +03:00
int vector_value ( const std : : string & name , std : : string & value ) const ;
2016-02-04 15:10:42 +03:00
2020-07-02 23:42:10 +03:00
int vector_value ( const std : : string & name , bool & value ) const ;
2012-07-16 19:15:22 +04:00
2012-05-29 02:36:13 +04:00
/**
2016-04-19 17:22:37 +03:00
* Returns the value of the given element of the VectorAttribute
2012-05-29 02:36:13 +04:00
*
* @ param name Name of the attribute
2012-07-16 19:15:22 +04:00
* @ param value Integer value , if an error occurred the string returned is
2016-02-04 15:10:42 +03:00
* empty and value is not set
2012-05-29 02:36:13 +04:00
*
* @ return the value in string form on success , " " otherwise
*/
2016-02-04 15:10:42 +03:00
template < typename T >
2023-03-08 17:52:20 +03:00
const std : : string & vector_value_str ( const std : : string & name , T & value ) const
2016-02-04 15:10:42 +03:00
{
2020-07-02 23:42:10 +03:00
auto it = attribute_value . find ( name ) ;
2016-02-04 15:10:42 +03:00
if ( it = = attribute_value . end ( ) )
{
2023-03-08 17:52:20 +03:00
return EMPTY_ATTRIBUTE ;
2016-02-04 15:10:42 +03:00
}
if ( it - > second . empty ( ) )
{
2023-03-08 17:52:20 +03:00
return EMPTY_ATTRIBUTE ;
2016-02-04 15:10:42 +03:00
}
2020-07-02 23:42:10 +03:00
std : : istringstream iss ( it - > second ) ;
2016-02-04 15:10:42 +03:00
iss > > value ;
if ( iss . fail ( ) | | ! iss . eof ( ) )
{
2023-03-08 17:52:20 +03:00
return EMPTY_ATTRIBUTE ;
2016-02-04 15:10:42 +03:00
}
return it - > second ;
}
2012-07-16 20:28:58 +04:00
2008-06-17 20:27:32 +04:00
/**
* Marshall the attribute in a single string . The string MUST be freed
2009-03-06 15:10:15 +03:00
* by the calling function . The string is in the form :
2008-06-17 20:27:32 +04:00
* " VAL_NAME_1=VAL_VALUE_1,...,VAL_NAME_N=VAL_VALUE_N " .
* @ return a string ( allocated in the heap ) holding the attribute value .
2009-03-06 15:10:15 +03:00
*/
2020-09-15 12:16:00 +03:00
std : : string marshall ( const char * _sep = 0 ) const override ;
2009-03-06 15:10:15 +03:00
2009-01-26 21:25:15 +03:00
/**
* Write the attribute using a simple XML format :
2009-03-06 15:10:15 +03:00
*
2009-01-26 21:25:15 +03:00
* < attribute_name >
* < val_name_1 > val_value_1 < / val_name_1 >
* . . .
* < val_name_n > val_value_n < / val_name_n >
2009-03-06 15:10:15 +03:00
* < / attribute_name >
2024-01-08 15:56:40 +03:00
*
* NOTE : For Vector attributes hidden are in the form { " DB " , { " USER " , " PASSWD " } }
* A hidden attribute is rendered as * * *
2009-01-26 21:25:15 +03:00
*/
2020-03-04 18:05:57 +03:00
void to_xml ( std : : ostringstream & s ) const override ;
2008-06-17 20:27:32 +04:00
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
2020-03-04 18:05:57 +03:00
void to_json ( std : : ostringstream & s ) const override ;
2019-01-30 02:10:18 +03:00
2008-06-17 20:27:32 +04:00
/**
* Builds a new attribute from a string of the form :
* " VAL_NAME_1=VAL_VALUE_1,...,VAL_NAME_N=VAL_VALUE_N " .
2009-03-06 15:10:15 +03:00
*/
2020-07-02 23:42:10 +03:00
void unmarshall ( const std : : string & sattr , const char * _sep = 0 ) override ;
2008-11-13 19:21:17 +03:00
/**
* Replace the value of the given attribute with the provided map
*/
2024-06-03 12:40:24 +03:00
void replace ( const std : : map < std : : string , std : : string > & attr ) ;
2008-11-13 19:21:17 +03:00
2014-07-10 18:24:25 +04:00
/**
* The attributes from vattr will be copied to this vector
* @ param attr Vector attribute to merge
* @ param replace True to replace existing values , false to copy values
* only if they don ' t exist in this vector attribute
*/
2023-09-14 16:36:26 +03:00
void merge ( const VectorAttribute * vattr , bool replace ) ;
2014-07-10 18:24:25 +04:00
2009-04-04 03:34:33 +04:00
/**
* Replace the value of the given vector attribute
*/
2016-02-04 15:10:42 +03:00
template < typename T >
2023-03-08 17:52:20 +03:00
void replace ( const std : : string & name , const T & value )
2013-10-17 14:35:19 +04:00
{
2020-07-02 23:42:10 +03:00
std : : ostringstream oss ;
2013-10-17 14:35:19 +04:00
oss < < value ;
replace ( name , oss . str ( ) ) ;
}
2020-07-02 23:42:10 +03:00
void replace ( const std : : string & name , bool value )
2013-01-18 02:14:34 +04:00
{
if ( value = = true )
{
2016-02-04 15:10:42 +03:00
replace ( name , " YES " ) ;
2013-01-18 02:14:34 +04:00
}
else
{
2016-02-04 15:10:42 +03:00
replace ( name , " NO " ) ;
2013-01-18 02:14:34 +04:00
}
}
2020-07-02 23:42:10 +03:00
void replace ( const std : : string & name , const std : : string & value ) ;
2016-02-04 15:10:42 +03:00
2012-06-13 20:42:42 +04:00
/**
2020-10-16 13:33:20 +03:00
* Removes the given attribute from the vector
* @ param name of the attribute
2012-06-13 20:42:42 +04:00
*/
2020-07-02 23:42:10 +03:00
void remove ( const std : : string & name ) ;
2012-06-13 20:42:42 +04:00
2008-06-17 20:27:32 +04:00
/**
* Returns the attribute type
2009-03-06 15:10:15 +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
AttributeType type ( ) const override
2008-06-17 20:27:32 +04:00
{
return VECTOR ;
} ;
2011-04-11 01:55:49 +04:00
/**
* Clones the current attribute
*/
2020-03-04 18:05:57 +03:00
VectorAttribute * clone ( ) const override
2011-04-11 01:55:49 +04:00
{
2012-12-24 05:41:17 +04:00
return new VectorAttribute ( * this ) ;
2011-04-11 01:55:49 +04:00
} ;
2014-05-08 17:48:16 +04:00
/**
* Clear the vector attribute values
*/
void clear ( )
{
attribute_value . clear ( ) ;
}
2018-03-26 19:58:04 +03:00
/**
* @ return true if the vector attribute contains no values
*/
2020-09-25 13:08:42 +03:00
bool empty ( ) const
2018-03-26 19:58:04 +03:00
{
return attribute_value . empty ( ) ;
}
2019-09-16 16:51:38 +03:00
/**
* Encrypt all secret attributes
*/
2020-07-02 23:42:10 +03:00
void encrypt ( const std : : string & one_key ,
const std : : set < std : : string > & eas ) override ;
2019-09-16 16:51:38 +03:00
/**
* Decrypt all secret attributes
*/
2020-07-02 23:42:10 +03:00
void decrypt ( const std : : string & one_key ,
const std : : set < std : : string > & eas ) override ;
2019-09-16 16:51:38 +03:00
2008-06-17 20:27:32 +04:00
private :
2009-03-06 15:10:15 +03:00
2015-07-01 22:15:40 +03:00
static const char * magic_sep ;
2009-03-06 15:10:15 +03:00
2015-07-01 22:15:40 +03:00
static const int magic_sep_size ;
2008-06-17 20:27:32 +04:00
2024-06-03 12:40:24 +03:00
std : : map < std : : string , std : : string > attribute_value ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*ATTRIBUTE_H_*/