Exemple #1
0
func (os *OpenStack) GetInstance(instanceID string) (*compute.Instance, error) {
	server, err := servers.Get(os.ComputeClient, instanceID).Extract()
	if err != nil {
		return nil, err
	} else {
		return os.serverToInstance(server), nil
	}
}
Exemple #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
}