1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-07 17:17:41 +03:00
one/include/ExtendedAttribute.h

299 lines
9.3 KiB
C
Raw Normal View History

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2024, 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. */
/* -------------------------------------------------------------------------- */
#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);
}
std::string vector_value(const std::string& name)
{
return va->vector_value(name);
}
const std::string& vector_value(const std::string& name) const
{
return const_cast<const VectorAttribute*>(va)->vector_value(name);
}
template<typename T>
void replace(const std::string& name, const T& value)
{
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 */
/* ---------------------------------------------------------------------- */
std::string marshall(const char * _sep = 0) const override
{
return va->marshall(_sep);
};
void to_xml(std::ostringstream& s) const override
{
return va->to_xml(s);
};
void to_json(std::ostringstream& s) const override
{
return va->to_json(s);
};
void to_xml(std::ostringstream& s,
const std::map<std::string, std::set<std::string>> &hidden) const override
{
return va->to_xml(s, hidden);
}
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):
Attribute(_va->name()), va(_va), id(-1) {};
ExtendedAttribute(VectorAttribute *_va, int _id):
Attribute(_va->name()), va(_va), id(_id) {};
virtual ~ExtendedAttribute() {};
/* ---------------------------------------------------------------------- */
/* Attribute Interface */
/* ---------------------------------------------------------------------- */
void unmarshall(const std::string& sattr, const char * _sep = 0) override
{
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
{
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
}
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
{
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
}
/* ---------------------------------------------------------------------- */
/* 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
*/
ExtendedAttributeSet(bool _dispose):dispose(_dispose) {};
virtual ~ExtendedAttributeSet();
/* ---------------------------------------------------------------------- */
/* Method to access attributes */
/* ---------------------------------------------------------------------- */
/**
F #5516: Incremental backups for qcow2 disk images - Adds new configuration attribute MODE: FULL or INCREMENTAL for BACKUP_CONFIG. FULL backups uses a differen backup image. - INCREMENTAL backup information is together with the backup image. Example: <BACKUP_INCREMENTS> <INCREMENT> <DATE><![CDATA[1667770552]]></DATE> <ID><![CDATA[0]]></ID> <PARENT_ID><![CDATA[-1]]></PARENT_ID> <SIZE><![CDATA[172]]></SIZE> <SOURCE><![CDATA[bb828060]]></SOURCE> <TYPE><![CDATA[FULL]]></TYPE> </INCREMENT> <INCREMENT> <DATE><![CDATA[1667770604]]></DATE> <ID><![CDATA[1]]></ID> <PARENT_ID><![CDATA[0]]></PARENT_ID> <SIZE><![CDATA[1]]></SIZE> <SOURCE><![CDATA[ca0de5f6]]></SOURCE> <TYPE><![CDATA[INCREMENT]]></TYPE> </INCREMENT> <INCREMENT> <DATE><![CDATA[1667770700]]></DATE> <ID><![CDATA[2]]></ID> <PARENT_ID><![CDATA[1]]></PARENT_ID> <SIZE><![CDATA[39]]></SIZE> <SOURCE><![CDATA[e9897d6a]]></SOURCE> <TYPE><![CDATA[INCREMENT]]></TYPE> </INCREMENT> </BACKUP_INCREMENTS> This information only appears on incremental backups - Internal BACKUP_CONFIG data includes information about the current active backup and the last increment id. - Backup operation includes a new parameter: reset. This "closes" the current active incremental chain and creates a new FULL backup. - Backup drivers store backups with increment index (0 = FULL) e.g. disk.0.0. - Incremental backups are only allowed for VMs using all disks in qcow2 format. - Backup configuration cannot be changed while doing a VM backup. - Downloader strings includes backup chains <inc_id>:<backup_ref>,... - Restic downloader has been updated to support backup chains. Disk images are rebased across increments.
2022-11-07 00:54:17 +03:00
* @return attribute by id or nullptr if not found
*/
ExtendedAttribute * get_attribute(int id) const;
F #5516: Incremental backups for qcow2 disk images - Adds new configuration attribute MODE: FULL or INCREMENTAL for BACKUP_CONFIG. FULL backups uses a differen backup image. - INCREMENTAL backup information is together with the backup image. Example: <BACKUP_INCREMENTS> <INCREMENT> <DATE><![CDATA[1667770552]]></DATE> <ID><![CDATA[0]]></ID> <PARENT_ID><![CDATA[-1]]></PARENT_ID> <SIZE><![CDATA[172]]></SIZE> <SOURCE><![CDATA[bb828060]]></SOURCE> <TYPE><![CDATA[FULL]]></TYPE> </INCREMENT> <INCREMENT> <DATE><![CDATA[1667770604]]></DATE> <ID><![CDATA[1]]></ID> <PARENT_ID><![CDATA[0]]></PARENT_ID> <SIZE><![CDATA[1]]></SIZE> <SOURCE><![CDATA[ca0de5f6]]></SOURCE> <TYPE><![CDATA[INCREMENT]]></TYPE> </INCREMENT> <INCREMENT> <DATE><![CDATA[1667770700]]></DATE> <ID><![CDATA[2]]></ID> <PARENT_ID><![CDATA[1]]></PARENT_ID> <SIZE><![CDATA[39]]></SIZE> <SOURCE><![CDATA[e9897d6a]]></SOURCE> <TYPE><![CDATA[INCREMENT]]></TYPE> </INCREMENT> </BACKUP_INCREMENTS> This information only appears on incremental backups - Internal BACKUP_CONFIG data includes information about the current active backup and the last increment id. - Backup operation includes a new parameter: reset. This "closes" the current active incremental chain and creates a new FULL backup. - Backup drivers store backups with increment index (0 = FULL) e.g. disk.0.0. - Incremental backups are only allowed for VMs using all disks in qcow2 format. - Backup configuration cannot be changed while doing a VM backup. - Downloader strings includes backup chains <inc_id>:<backup_ref>,... - Restic downloader has been updated to support backup chains. Disk images are rebased across increments.
2022-11-07 00:54:17 +03:00
/**
* @return last_attribute or nullptr if empty set
*/
ExtendedAttribute * last_attribute() const;
/* ---------------------------------------------------------------------- */
/* 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;
}
AttributeIterator() {};
AttributeIterator(const AttributeIterator& ait):map_it(ait.map_it) {};
AttributeIterator(const std::map<int,
ExtendedAttribute *>::iterator& _map_it):map_it(_map_it) {};
virtual ~AttributeIterator() {};
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
*/
void add_attribute(ExtendedAttribute * a, int id)
{
a_set.insert(std::make_pair(id, a));
}
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);
/**
* 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,
std::vector<VectorAttribute *>& vas);
/**
* Abstract method to create the VirtualMachineAttributes for this set
*/
virtual ExtendedAttribute * attribute_factory(VectorAttribute * va,
int id) const = 0;
/**
* @return the number of elements in the set
*/
unsigned int size()
{
return a_set.size();
}
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/**
* 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_*/