コード例 #1
0
ファイル: opennebula.go プロジェクト: pkdevbox/machine
func (d *Driver) Kill() error {
	vm, err := goca.NewVMFromName(d.MachineName)
	if err != nil {
		return err
	}

	err = vm.PowerOffHard()
	if err != nil {
		return err
	}

	return nil
}
コード例 #2
0
ファイル: opennebula.go プロジェクト: pkdevbox/machine
func (d *Driver) Restart() error {
	vm, err := goca.NewVMFromName(d.MachineName)
	if err != nil {
		return err
	}

	err = vm.Reboot()
	if err != nil {
		return err
	}

	return nil
}
コード例 #3
0
ファイル: opennebula.go プロジェクト: pkdevbox/machine
func (d *Driver) Remove() error {
	vm, err := goca.NewVMFromName(d.MachineName)
	if err != nil {
		return err
	}

	err = vm.ShutdownHard()
	if err != nil {
		return err
	}

	return nil
}
コード例 #4
0
ファイル: onego.go プロジェクト: jmelis/onego
func GetVM(idArg string) (*goca.VM, error) {
	if m, _ := regexp.MatchString("^\\d+$", idArg); m {
		id, err := strconv.Atoi(idArg)
		if err != nil {
			return nil, err
		}

		return goca.NewVM(uint(id)), nil
	} else {
		if vm, err := goca.NewVMFromName(idArg); err == nil {
			return vm, nil
		} else {
			return nil, err
		}
	}
}
コード例 #5
0
ファイル: opennebula.go プロジェクト: pkdevbox/machine
func (d *Driver) GetIP() (string, error) {
	vm, err := goca.NewVMFromName(d.MachineName)
	if err != nil {
		return "", err
	}

	err = vm.Info()
	if err != nil {
		return "", err
	}

	if ip, ok := vm.XPath("/VM/TEMPLATE/NIC/IP"); ok {
		d.IPAddress = ip
	}

	if d.IPAddress == "" {
		return "", fmt.Errorf("IP address is not set")
	}

	return d.IPAddress, nil
}
コード例 #6
0
ファイル: opennebula.go プロジェクト: pkdevbox/machine
func (d *Driver) Start() error {
	vm, err := goca.NewVMFromName(d.MachineName)
	if err != nil {
		return err
	}

	vm.Resume()

	s := state.None
	for retry := 0; retry < 50 && s != state.Running; retry++ {
		s, err = d.GetState()
		if err != nil {
			return err
		}

		switch s {
		case state.Running:
		case state.Error:
			return errors.New("VM in error state")
		default:
			time.Sleep(2 * time.Second)
		}
	}

	if d.IPAddress == "" {
		if d.IPAddress, err = d.GetIP(); err != nil {
			return err
		}
	}

	log.Infof("Waiting for SSH...")
	// Wait for SSH over NAT to be available before returning to user
	if err := drivers.WaitForSSH(d); err != nil {
		return err
	}

	return nil
}
コード例 #7
0
ファイル: opennebula.go プロジェクト: pkdevbox/machine
func (d *Driver) GetState() (state.State, error) {
	vm, err := goca.NewVMFromName(d.MachineName)
	if err != nil {
		return state.None, err
	}

	err = vm.Info()
	if err != nil {
		return state.None, err
	}

	vm_state, lcm_state, err := vm.StateString()
	if err != nil {
		return state.None, err
	}

	switch vm_state {
	case "INIT", "PENDING", "HOLD":
		return state.Starting, nil
	case "ACTIVE":
		switch lcm_state {
		case "RUNNING",
			"DISK_SNAPSHOT",
			"DISK_SNAPSHOT_REVERT",
			"DISK_SNAPSHOT_DELETE",
			"HOTPLUG",
			"HOTPLUG_SNAPSHOT",
			"HOTPLUG_NIC",
			"HOTPLUG_SAVEAS":
			return state.Running, nil
		case "PROLOG",
			"BOOT",
			"MIGRATE",
			"PROLOG_MIGRATE",
			"PROLOG_RESUME",
			"CLEANUP_RESUBMIT",
			"BOOT_UNKNOWN",
			"BOOT_POWEROFF",
			"BOOT_SUSPENDED",
			"BOOT_STOPPED",
			"PROLOG_UNDEPLOY",
			"BOOT_UNDEPLOY",
			"BOOT_MIGRATE",
			"PROLOG_MIGRATE_SUSPEND",
			"SAVE_MIGRATE":
			return state.Starting, nil
		case "HOTPLUG_SAVEAS_POWEROFF",
			"DISK_SNAPSHOT_POWEROFF",
			"DISK_SNAPSHOT_REVERT_POWEROFF",
			"DISK_SNAPSHOT_DELETE_POWEROFF",
			"HOTPLUG_PROLOG_POWEROFF",
			"HOTPLUG_EPILOG_POWEROFF",
			"PROLOG_MIGRATE_POWEROFF",
			"SAVE_STOP":
			return state.Stopped, nil
		case "HOTPLUG_SAVEAS_SUSPENDED",
			"DISK_SNAPSHOT_SUSPENDED",
			"DISK_SNAPSHOT_REVERT_SUSPENDED",
			"DISK_SNAPSHOT_DELETE_SUSPENDED":
			return state.Saved, nil
		case "EPILOG_STOP",
			"EPILOG",
			"SHUTDOWN_UNDEPLOY",
			"EPILOG_UNDEPLOY",
			"SAVE_SUSPEND",
			"SHUTDOWN",
			"SHUTDOWN_POWEROFF",
			"CANCEL",
			"CLEANUP_DELETE":
			return state.Stopping, nil
		case "UNKNOWN",
			"FAILURE",
			"BOOT_FAILURE",
			"BOOT_MIGRATE_FAILURE",
			"PROLOG_MIGRATE_FAILURE",
			"PROLOG_FAILURE",
			"EPILOG_FAILURE",
			"EPILOG_STOP_FAILURE",
			"EPILOG_UNDEPLOY_FAILURE",
			"PROLOG_MIGRATE_POWEROFF_FAILURE",
			"PROLOG_MIGRATE_SUSPEND_FAILURE",
			"BOOT_UNDEPLOY_FAILURE",
			"BOOT_STOPPED_FAILURE",
			"PROLOG_RESUME_FAILURE",
			"PROLOG_UNDEPLOY_FAILURE":
			return state.Error, nil
		}
	case "POWEROFF", "UNDEPLOYED":
		return state.Stopped, nil
	case "STOPPED", "SUSPENDED":
		return state.Saved, nil
	case "DONE", "FAILED":
		return state.Error, nil
	}

	return state.Error, nil
}