Example #1
0
func (cs *CloudStack) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	details, err := cs.client.GetVirtualMachine(vm.Identification)
	if err != nil {
		return nil, err
	}

	status := details.State
	if status == "Running" {
		status = "Online"
	} else if status == "Stopped" {
		status = "Offline"
	}

	info := lobster.VmInfo{
		Status:       status,
		LoginDetails: "password: "******"password", "unknown"),
	}

	for _, nic := range details.Nics {
		if ipaddr.IsPrivate(nic.Addr) {
			info.PrivateIp = nic.Addr
		} else {
			info.Ip = nic.Addr
		}
	}

	return &info, nil
}
Example #2
0
func (this *OpenStack) VmInfo(vm *lobster.VirtualMachine) (*lobster.VmInfo, error) {
	server, err := servers.Get(this.ComputeClient, vm.Identification).Extract()
	if err != nil {
		return nil, err
	}

	status := server.Status
	if status == "ACTIVE" {
		status = "Online"
	} else if status == "SHUTOFF" {
		status = "Offline"
	}

	info := lobster.VmInfo{
		Status:       status,
		Hostname:     server.Name,
		LoginDetails: "password: "******"password", "unknown"),
	}

	servers.ListAddresses(this.ComputeClient, vm.Identification).EachPage(func(page pagination.Page) (bool, error) {
		addresses, err := servers.ExtractAddresses(page)
		if err != nil {
			return false, err
		}

		for _, networkAddresses := range addresses {
			for _, addr := range networkAddresses {
				if ipaddr.IsPrivate(addr.Address) {
					info.PrivateIp = addr.Address
				} else {
					info.Ip = addr.Address
				}
			}
		}
		return true, nil
	})

	return &info, nil
}