Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You have "virtual_machine" as object of VirtualMachine in class in base.py
 
a. 
from marvin.cloudstackAPI import stopVirtualMachine

cmd = stopVirtualMachine.stopVirtualMachineCmd()

 cmd.id = virtual_machine.id

apiclient.stopVirtualMachine(cmd)

OR
 

b.

virtual_machine.delete(apiclient)

 

Second way (b) is simpler and should be preferred because

  • Has lesser number of lines
  • Less ambiguous
  • Makes use of existing code
  • Easier to maintain

 

There was an instance when after stopping the VM, the virtual machine state was asserted to be Stopped by listing the VM explicitly, after calling stop() method. This code was in many test cases and to remove the redundant code, verifications steps were made as a common part of stop() method. This was a huge boost in terms of maintenance of code and removing duplicate lines. For availing such advantages, always prefer method (b).

This is possible when you have an object of the base library class. In case you don't have the object, then you can use method (a).

 

...