[Tutor] Another OO modeling question

jamie hu jamiehu17 at yandex.com
Tue Dec 22 17:06:11 EST 2015


   *
   *
   I am trying to write down class and object definition for a Virtual
   Machine type. For example, I would like to create a Virtual Machine
   (object) that can have actions like launch, terminate, stop, add_disk,
   remove_disk etc..
   *
   My confusion here is that VirtualMachine object doesn't exist until it is
   actually launched successfully. So should the launch method be part of
   VirtualMachine class or some other VirtualMachineConfigurator class?
   Should*VirtualMachineConfigurator.launch() return VirtualMachine object or
   some string like vmid that can be used to create*VirtualMachine object??
   *
   Any help on modeling such objects would be helpful.
   *
   *
   Example class blueprint that I've been thinking:
   *
   class VirtualMachineConfigurator():
   * def __init__(self,memory,vcpu,network,base_image):
   * * * self.memory = memory
   * * * self.vcpu = vcpu
   * * * self.network = network
   * * * self.base_image = base_image
   *
   def launch(self)
   * """ Launches Virtual Machine and returns VirtualMachine object """
   * try:
   * * vm = hypervisor_conn.launch_vm(self.memory, self.vcpu, self.network,
   self.base_image)
   * * return vm
   * except Exception as e:
   * * raise e
   *
   *
   class VirtualMachine():
   * def __init__(self, vmid):
   * * self.vmid = vmid
   *
   * def stop(self):
   * * """ Stops VM"""
   * **
   * def attach_disk(self):
   *
   *
   --
   Thanks,
   Jamie


More information about the Tutor mailing list