Files
one/src/pool/ObjectCollection.cc
T
865908de1c 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:06:49 +01:00

203 lines
5.2 KiB
C++

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2022, 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. */
/* -------------------------------------------------------------------------- */
#include "ObjectCollection.h"
#include "ObjectXML.h"
#include <algorithm>
using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ObjectCollection::from_xml_node(const xmlNodePtr node)
{
istringstream iss;
int id;
int rc = 0;
ostringstream oss;
vector<string> ids;
ObjectXML oxml(node);
oss << "/" << collection_name << "/ID";
oxml.xpaths(ids, oss.str().c_str());
for (auto id_str : ids)
{
iss.clear();
iss.str(id_str);
iss >> dec >> id;
if ( iss.fail() )
{
rc = -1;
break;
}
else
{
collection_set.insert(id);
}
}
return rc;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ObjectCollection::from_xml(const ObjectXML* xml, const string& xpath_prefix)
{
int rc;
vector<xmlNodePtr> content;
ostringstream oss;
xml->get_nodes(xpath_prefix + collection_name, content);
if (content.empty())
{
return -1;
}
rc = from_xml_node(content[0]);
xml->free_nodes(content);
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string& ObjectCollection::to_xml(string& xml) const
{
ostringstream oss;
oss << "<" << collection_name << ">";
for (auto id : collection_set)
{
oss << "<ID>" << id << "</ID>";
}
oss << "</" << collection_name << ">";
xml = oss.str();
return xml;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ObjectCollection::add(int id)
{
auto ret = collection_set.insert(id);
if( !ret.second )
{
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ObjectCollection::del(int id)
{
if( collection_set.erase(id) != 1 )
{
return -1;
}
return 0;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ObjectCollection::pop(int& elem)
{
if (collection_set.empty())
{
return -1;
}
auto it = collection_set.begin();
elem = *it;
collection_set.erase(it);
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ObjectCollection& ObjectCollection::operator<<(const ObjectCollection& r)
{
for (auto id : r.collection_set)
{
collection_set.insert(id);
}
return *this;
}
ObjectCollection& ObjectCollection::operator<<(const std::set<int>& r)
{
for (const auto& id : r)
{
collection_set.insert(id);
}
return *this;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ObjectCollection& ObjectCollection::operator-=(const ObjectCollection& r)
{
std::set<int> diff;
std::set_difference(collection_set.cbegin(), collection_set.cend(),
r.collection_set.cbegin(), r.collection_set.cend(),
std::inserter(diff, diff.end()));
collection_set.swap(diff);
return *this;
}
ObjectCollection& ObjectCollection::operator-=(const std::set<int>& r)
{
std::set<int> diff;
std::set_difference(collection_set.cbegin(), collection_set.cend(),
r.cbegin(), r.cend(), std::inserter(diff, diff.end()));
collection_set.swap(diff);
return *this;
}