In step 1, we call the create() method to launch the defined instance. If successful the guest will transition from shut off state to running as we can see in the output of the command in step 3. In step 2, we use the isActive() method, to check the status of the instance. An output of 1 indicates that the instance is running.
In step 4, we stop the instance using the destroy() method and confirm in step 5.
Finally in step 6, we delete the instance using the undefine() method and list all defined instances with the listDefinedDomains() call.