Example #1
0
func FindResidentHost(state multistep.StateBag, instance *xsclient.VM, uuid string) (err error) {

	ui := state.Get("ui").(packer.Ui)

	domid, err := instance.GetDomainId()
	if err != nil {
		ui.Error(fmt.Sprintf("Unable to get domid of VM with UUID '%s': %s", uuid, err.Error()))
		return err
	}
	state.Put("domid", domid)

	// we are connected to a given host, but that might not be where the VM is running
	host, err := instance.GetResidentOn()
	if err != nil {
		ui.Error(fmt.Sprintf("Unable to determine what host the VM is running on: %s", err.Error()))
		return err
	}

	hostAddress, err := host.GetAddress()
	if err != nil {
		ui.Error(fmt.Sprintf("Unable to determine the IP of the host: %s", err.Error()))
		return err
	}

	ui.Message(fmt.Sprintf("VM '%s' is running on host with address '%s'", uuid, hostAddress))

	config := state.Get("commonconfig").(CommonConfig)
	config.HostIp = hostAddress
	state.Put("commonconfig", config)

	return nil

}
Example #2
0
func (self *stepSnapshotInstance) removeInstance(instance *xsclient.VM, ui packer.Ui) (err error) {

	if instance != nil {
		uuid, _ := instance.GetUuid()
		ui.Message(fmt.Sprintf("Removing instance '%s'", uuid))
		_ = instance.HardShutdown() // redundant, just in case

		vdis, err := instance.GetDisks()
		if err != nil {
			return err
		}

		for _, vdi := range vdis {
			vdi_uuid, _ := vdi.GetUuid()

			ui.Message(fmt.Sprintf("Destroying vdi '%s'", vdi_uuid))
			err = vdi.Destroy()
			if err != nil {
				return err
			}
		}

		ui.Message(fmt.Sprintf("Destroying instance '%s'", uuid))
		err = instance.Destroy()
		if err != nil {
			return err
		}
	}

	return nil

}