Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the way VMs are created.
[simgrid.git] / teshsuite / s4u / vm-live-migration / vm-live-migration.cpp
index b5b78b2..11fd36a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team.
+/* Copyright (c) 2007-2021. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -19,9 +19,10 @@ static void task_executor()
   simgrid::s4u::this_actor::sleep_for(3); // Breaks everything
 
   ptr->wait();
-  XBT_INFO("Task done. It's running on %s@%s that runs at %.0ef/s. host2 runs at %.0ef/s", ptr->get_host()->get_cname(),
-           dynamic_cast<simgrid::s4u::VirtualMachine*>(ptr->get_host())->get_pm()->get_cname(),
-           ptr->get_host()->get_speed(), simgrid::s4u::Host::by_name("host2")->get_speed());
+  const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(ptr->get_host());
+  xbt_assert(vm != nullptr, "Hey, I expected to run on a VM");
+  XBT_INFO("Task done. It's running on %s@%s that runs at %.0ef/s. host2 runs at %.0ef/s", vm->get_cname(),
+           vm->get_pm()->get_cname(), vm->get_speed(), simgrid::s4u::Host::by_name("host2")->get_speed());
 }
 
 int main(int argc, char* argv[])
@@ -35,14 +36,14 @@ int main(int argc, char* argv[])
   xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]);
 
   e.load_platform(argv[1]);
-  auto* pm = simgrid::s4u::Host::by_name("host1");
-  auto* vm = new simgrid::s4u::VirtualMachine("VM0", pm, 1 /*nCores*/);
+  auto* pm = e.host_by_name("host1");
+  auto* vm = pm->create_vm("VM0", 1 /*nCores*/);
   vm->set_ramsize(1250000000)->start();
   simgrid::s4u::Actor::create("executor", vm, task_executor);
 
   simgrid::s4u::Actor::create("migration", pm, [vm]() {
     XBT_INFO("%s migration started", vm->get_cname());
-    auto* old = vm->get_pm();
+    const auto* old = vm->get_pm();
 
     sg_vm_migrate(vm, simgrid::s4u::Host::by_name("host2"));