Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics (indentation, codefactor.io).
[simgrid.git] / src / s4u / s4u_Host.cpp
index 9c0ab22..35357f8 100644 (file)
@@ -373,6 +373,12 @@ VirtualMachine* Host::create_vm(const std::string& name, int core_amount, size_t
       [this, &name, core_amount, ramsize] { return this->pimpl_->create_vm(name, core_amount, ramsize); });
 }
 
+VirtualMachine* Host::vm_by_name_or_null(const std::string& name)
+{
+  simgrid::kernel::resource::VirtualMachineImpl* vm = this->pimpl_->get_vm_by_name_or_null(name);
+  return vm ? vm->get_iface() : nullptr;
+}
+
 ExecPtr Host::exec_init(double flops) const
 {
   return this_actor::exec_init(flops);
@@ -442,6 +448,12 @@ sg_host_t sg_host_by_name(const char* name)
   return simgrid::s4u::Host::by_name_or_null(name);
 }
 
+/** @brief Retrieve a VM running on a given host from its name, or return NULL if no VM matches*/
+sg_vm_t sg_vm_by_name(sg_host_t host, const char* name)
+{
+  return host->vm_by_name_or_null(name);
+}
+
 // ========= Layering madness ==============*
 
 // ========== User data Layer ==========
@@ -570,8 +582,8 @@ xbt_dict_t sg_host_get_properties(const_sg_host_t host)
 
   if (props == nullptr)
     return nullptr;
-  for (auto const& elm : *props) {
-    xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()));
+  for (auto const& [key, value] : *props) {
+    xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str()));
   }
   return as_dict;
 }
@@ -655,8 +667,8 @@ void sg_host_dump(const_sg_host_t host) // XBT_ATTRIB_DEPRECATED_v335
 
   if (not props->empty()) {
     XBT_INFO("  - properties:");
-    for (auto const& elm : *props) {
-      XBT_INFO("    %s->%s", elm.first.c_str(), elm.second.c_str());
+    for (auto const& [key, value] : *props) {
+      XBT_INFO("    %s->%s", key.c_str(), value.c_str());
     }
   }
 }