/* -------------------------------------------------------------------------- */ /* Copyright 2002-2019, 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 "VirtualMachineTemplate.h" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ std::map > VirtualMachineTemplate::restricted; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ int VirtualMachineTemplate::replace_disk_image(int target_id, const string& target_name, const string& target_uname, const string& new_name, const string& new_uname) { int num_disks; int tmp_id; string tmp_name; string tmp_uname; vector disks; VectorAttribute * disk = 0; num_disks = get("DISK", disks); for(int i=0; ivector_value("IMAGE_ID", tmp_id) == 0) //DISK has IMAGE_ID { if (tmp_id == target_id) { break; } } else //IMAGE and IMAGE_UNAME { tmp_name = disk->vector_value("IMAGE"); tmp_uname = disk->vector_value("IMAGE_UNAME"); bool uname = tmp_uname.empty() || tmp_uname == target_uname; if ( tmp_name == target_name && uname ) { break; } } disk = 0; } if ( disk == 0 ) { return -1; } disk->remove("IMAGE_ID"); disk->replace("IMAGE", new_name); disk->replace("IMAGE_UNAME", new_uname); return 0; } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ string& VirtualMachineTemplate::to_xml_short(string& xml) const { ostringstream oss; string labels; string schd_rank, schd_ds_rank; string schd_req, schd_ds_req; string user_prio; vector attrs; if (attributes.empty()) { oss << ""; } else { oss << ""; /* ------------------------------------------------------------------ */ /* Attributes required by Sunstone */ /* - LABELS */ /* ------------------------------------------------------------------ */ if (get("LABELS", labels)) { oss << "" << one_util::escape_xml(labels) << ""; } /* ------------------------------------------------------------------ */ /* Attributes required by Scheduler */ /* - SCHED_RANK (RANK - deprecated) */ /* - SCHED_DS_RANK */ /* - SCHED_REQUIREMENTS */ /* - SCHED_DS_REQUIREMENTS */ /* */ /* - SCHED_ACTION */ /* - PUBLIC_CLOUD */ /* ------------------------------------------------------------------ */ if (get("SCHED_RANK", schd_rank)) { oss << "" << one_util::escape_xml(schd_rank) << ""; } if (get("SCHED_DS_RANK", schd_ds_rank)) { oss << "" << one_util::escape_xml(schd_ds_rank) << ""; } if (get("SCHED_REQUIREMENTS", schd_req)) { oss << "" << one_util::escape_xml(schd_req) << ""; } if (get("SCHED_DS_REQUIREMENTS", schd_ds_req)) { oss << "" << one_util::escape_xml(schd_ds_req) << ""; } if (get("USER_PRIORITY", user_prio)) { oss << "" << one_util::escape_xml(user_prio) << ""; } if ( get("PUBLIC_CLOUD", attrs) > 0 ) { vector::const_iterator it; for (it = attrs.begin(); it != attrs.end(); it++) { (*it)->to_xml(oss); } } attrs.clear(); if ( get("SCHED_ACTION", attrs) > 0 ) { vector::const_iterator it; for (it = attrs.begin(); it != attrs.end(); it++) { (*it)->to_xml(oss); } } oss << ""; } xml = oss.str(); return xml; }