Use s4u::Host::create_vm instead.
Workaround to keep it working meanwhile.
#ifndef DOXYGEN
friend kernel::resource::VirtualMachineImpl; // calls signals from Impl
+ friend kernel::resource::HostImpl; // call private constructor
+ VirtualMachine(kernel::resource::VirtualMachineImpl* impl);
#endif
public:
- explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount, size_t ramsize);
+ XBT_ATTRIB_DEPRECATED_v336("Please use s4u::Host::create_vm") explicit VirtualMachine(const std::string& name,
+ Host* physical_host,
+ int core_amount,
+ size_t ramsize = 1024);
#ifndef DOXYGEN
// No copy/move
VirtualMachineImpl::VirtualMachineImpl(const std::string& name, s4u::VirtualMachine* piface,
simgrid::s4u::Host* host_PM, int core_amount, size_t ramsize)
- : HostImpl(name), piface_(piface), physical_host_(host_PM), core_amount_(core_amount), ramsize_(ramsize)
+ : VirtualMachineImpl(name, host_PM, core_amount, ramsize)
+{
+ set_piface(piface);
+}
+
+VirtualMachineImpl::VirtualMachineImpl(const std::string& name, simgrid::s4u::Host* host_PM, int core_amount,
+ size_t ramsize)
+ : HostImpl(name), physical_host_(host_PM), core_amount_(core_amount), ramsize_(ramsize)
{
- /* Register this VM to the list of all VMs */
- allVms_.push_back(piface);
/* We create cpu_action corresponding to a VM process on the host operating system. */
/* TODO: we have to periodically input GUESTOS_NOISE to the system? how ?
* The value for GUESTOS_NOISE corresponds to the cost of the global action associated to the VM. It corresponds to
XBT_VERB("Create VM(%s)@PM(%s)", name.c_str(), physical_host_->get_cname());
}
+void VirtualMachineImpl::set_piface(s4u::VirtualMachine* piface)
+{
+ xbt_assert(not piface_, "Pointer to interface already configured for this VM (%s)", get_cname());
+ piface_ = piface;
+ /* Register this VM to the list of all VMs */
+ allVms_.push_back(piface);
+}
+
/** @brief A physical host does not disappear in the current SimGrid code, but a VM may disappear during a simulation */
void VirtualMachineImpl::vm_destroy()
{
explicit VirtualMachineImpl(const std::string& name, s4u::VirtualMachine* piface, s4u::Host* host, int core_amount,
size_t ramsize);
+ explicit VirtualMachineImpl(const std::string& name, simgrid::s4u::Host* host_PM, int core_amount, size_t ramsize);
+ void set_piface(s4u::VirtualMachine* piface);
void start();
void suspend(const actor::ActorImpl* issuer);
void seal() override;
private:
- s4u::VirtualMachine* piface_;
+ s4u::VirtualMachine* piface_ = nullptr;
Action* action_ = nullptr;
unsigned int active_execs_ = 0;
s4u::Host* physical_host_;
VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host, int core_amount, size_t ramsize)
: Host(new kernel::resource::VirtualMachineImpl(name, this, physical_host, core_amount, ramsize))
, pimpl_vm_(dynamic_cast<kernel::resource::VirtualMachineImpl*>(Host::get_impl()))
+{
+ physical_host->get_impl()->create_vm(name, this);
+}
+
+VirtualMachine::VirtualMachine(kernel::resource::VirtualMachineImpl* impl)
+ : Host(impl), pimpl_vm_(dynamic_cast<kernel::resource::VirtualMachineImpl*>(Host::get_impl()))
{
}
s4u::VirtualMachine* HostImpl::create_vm(const std::string& name, int core_amount, size_t ramsize)
{
- auto* vm = new s4u::VirtualMachine(name, get_iface(), core_amount, ramsize);
+ auto* host_vm = new kernel::resource::VirtualMachineImpl(name, get_iface(), core_amount, ramsize);
+ auto* vm = new s4u::VirtualMachine(host_vm);
+ host_vm->set_piface(vm);
+ return create_vm(name, vm);
+}
+
+s4u::VirtualMachine* HostImpl::create_vm(const std::string& name, s4u::VirtualMachine* vm)
+{
vms_[name] = vm->get_vm_impl();
// Create a VCPU for this VM
for (unsigned long i = 0; i < get_iface()->get_pstate_count(); i++)
speeds.push_back(get_iface()->get_pstate_speed(i));
- auto* cpu = englobing_zone_->get_cpu_vm_model()->create_cpu(vm, speeds)->set_core_count(core_amount);
+ auto* cpu =
+ englobing_zone_->get_cpu_vm_model()->create_cpu(vm, speeds)->set_core_count(vm->get_vm_impl()->get_core_amount());
if (get_iface()->get_pstate() != 0)
cpu->set_pstate(get_iface()->get_pstate());
std::vector<s4u::Disk*> get_disks() const;
s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
s4u::VirtualMachine* create_vm(const std::string& name, int core_amount, size_t ramsize = 1024);
+ s4u::VirtualMachine* create_vm(const std::string& name, s4u::VirtualMachine* vm);
void destroy_vm(const std::string& name);
void add_disk(const s4u::Disk* disk);
void remove_disk(const std::string& name);