2022-11-06 22:54:17 +01:00
/* -------------------------------------------------------------------------- */
2023-01-09 12:23:19 +01:00
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
2022-11-06 22:54:17 +01: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 BACKUPS_INCREMENTS_H_
# define BACKUPS_INCREMENTS_H_
# include <string>
# include "ExtendedAttribute.h"
# include "NebulaUtil.h"
/**
* The Image INCREMENT attribute
2023-02-07 10:39:48 +01:00
*
* < INCREMENT >
* < ID > Unique ID within this backup increment
* < TYPE > Of the backup FULL | INCREMENT
* < PARENT_ID > ID of the parent increment ( backing file )
* < SOURCE > Reference in the backup system
* < SIZE > Size of this increment
* < DATE > When this backup was taken ( epoch )
2022-11-06 22:54:17 +01:00
*/
class Increment : public ExtendedAttribute
{
public :
Increment ( VectorAttribute * va , int id ) : ExtendedAttribute ( va , id ) { } ;
~ Increment ( ) = default ;
enum Type
{
FULL = 0 , /** < Full backup*/
INCREMENT = 1 , /** < Forward increment */
} ;
2023-02-07 10:39:48 +01:00
/* ---------------------------------------------------------------------- */
/* Functions to get/set increment attributes */
/* ---------------------------------------------------------------------- */
2022-11-06 22:54:17 +01:00
long long size ( ) const
{
long long sz = 0 ;
vector_value ( " SIZE " , sz ) ;
return sz ;
}
2023-02-07 10:39:48 +01:00
void size ( const std : : string & sz )
{
replace ( " SIZE " , sz ) ;
}
std : : string source ( ) const
{
return vector_value ( " SOURCE " ) ;
}
void source ( const std : : string & src )
{
replace ( " SOURCE " , src ) ;
}
2022-11-06 22:54:17 +01:00
int id ( ) const
{
return get_id ( ) ;
}
2023-02-07 10:39:48 +01:00
void parent_id ( int id )
{
replace ( " PARENT_ID " , id ) ;
}
void backup_type ( Type t )
{
switch ( t )
{
case FULL :
replace ( " TYPE " , " FULL " ) ;
break ;
case INCREMENT :
replace ( " TYPE " , " INCREMENT " ) ;
break ;
}
}
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 13:35:29 +01:00
Type backup_type ( ) const
2022-11-06 22:54:17 +01:00
{
std : : string stype = vector_value ( " TYPE " ) ;
one_util : : toupper ( stype ) ;
if ( stype = = " FULL " )
{
return FULL ;
}
else if ( stype = = " INCREMENT " )
{
return INCREMENT ;
}
return FULL ;
}
} ;
/**
* Set of INCREMENTS ( indexed by ID )
*/
class IncrementSet : public ExtendedAttributeSet
{
public :
IncrementSet ( ) : ExtendedAttributeSet ( false ) { } ;
~ IncrementSet ( ) = default ;
void init ( Template * tmpl )
{
std : : vector < VectorAttribute * > incs ;
tmpl - > get ( " INCREMENT " , incs ) ;
init_attribute_map ( " ID " , incs ) ;
} ;
/* ---------------------------------------------------------------------- */
/* Increment interface */
/* ---------------------------------------------------------------------- */
2023-02-07 10:39:48 +01:00
/**
* Creates a new increment in the set
* @ param source internal representation for the backup driver of the increment
* @ param sz in MB of the increment
* @ param type FULL ( first increment in the chain ) or INCREMENT
*
* @ return Pointer to the new attribute
*/
2023-01-31 13:46:09 +01:00
VectorAttribute * new_increment ( const std : : string & source , long long sz ,
2022-11-06 22:54:17 +01:00
Increment : : Type type ) ;
Increment * last_increment ( )
{
return static_cast < Increment * > ( last_attribute ( ) ) ;
}
2023-02-07 10:39:48 +01:00
Increment * get_increment ( int id ) const
{
return static_cast < Increment * > ( get_attribute ( id ) ) ;
}
Increment * delete_increment ( int id )
{
return static_cast < Increment * > ( delete_attribute ( id ) ) ;
}
/**
* @ return Number of increments in the chain
*/
unsigned int total ( )
{
return size ( ) ;
}
/**
* @ return Total size of the backup ( adding all increments ) , in MB
*/
2022-11-06 22:54:17 +01:00
long long total_size ( ) ;
/* ---------------------------------------------------------------------- */
/* Iterators */
/* ---------------------------------------------------------------------- */
class IncIterator : public AttributeIterator
{
public :
IncIterator ( ) : AttributeIterator ( ) { } ;
IncIterator ( const AttributeIterator & dit ) : AttributeIterator ( dit ) { } ;
virtual ~ IncIterator ( ) { } ;
Increment * operator * ( ) const
{
return static_cast < Increment * > ( map_it - > second ) ;
}
} ;
IncIterator begin ( )
{
IncIterator it ( ExtendedAttributeSet : : begin ( ) ) ;
return it ;
}
IncIterator end ( )
{
IncIterator it ( ExtendedAttributeSet : : end ( ) ) ;
return it ;
}
typedef class IncIterator inc_iterator ;
private :
2023-02-07 12:33:31 +01:00
ExtendedAttribute * attribute_factory ( VectorAttribute * va , int id ) const override
2022-11-06 22:54:17 +01:00
{
return new Increment ( va , id ) ;
} ;
} ;
/**
* This class represents a generic set of references ( links ) for Image objects
* The data model is as follows
* < BACKUP_INCREMENTS >
* < INCREMENT >
* < ID > Unique ID within this backup increment
* < TYPE > Of the backup FULL | INCREMENT
* < PARENT_ID > ID of the parent increment ( backing file )
* < SOURCE > Reference in the backup system
* < SIZE > Size of this increment
* < DATE > When this backup was taken ( epoch )
*/
class BackupIncrements
{
public :
BackupIncrements ( ) : _template ( false , ' = ' , " BACKUP_INCREMENTS " ) { } ;
~ BackupIncrements ( ) = default ;
/* ---------------------------------------------------------------------- */
/* XML from/to methods for DB persistency */
/* ---------------------------------------------------------------------- */
int from_xml_node ( const xmlNodePtr node ) ;
std : : string & to_xml ( std : : string & xml ) const
{
return _template . to_xml ( xml ) ;
}
/* ---------------------------------------------------------------------- */
/* Increments interface */
/* ---------------------------------------------------------------------- */
2023-01-31 13:46:09 +01:00
int add_increment ( const std : : string & source , long long size , Increment : : Type type ) ;
2022-11-06 22:54:17 +01:00
int last_increment_id ( ) ;
2023-02-07 10:39:48 +01:00
/**
* @ return Total size of the backup ( adding all increments ) , in MB
*/
2022-11-06 22:54:17 +01:00
long long total_size ( )
{
return increments . total_size ( ) ;
}
2023-02-07 10:39:48 +01:00
/**
* Update the sources of the increments after a merge operation .
*
* @ param chain string with format 0 : source0 , . . . N : sourceN Number of increments
* can be less than the current number .
*/
int update_increments ( const std : : string & incs , const std : : string & sz ) ;
/**
* @ return Number of increments in the chain
*/
unsigned int total ( )
{
return increments . total ( ) ;
}
2022-11-06 22:54:17 +01:00
private :
/**
* Text representation of the increments
*/
Template _template ;
IncrementSet increments ;
} ;
# endif /*BACKUPS_H_*/