Esempio n. 1
0
func (os *OpenStack) serverToInstance(server *servers.Server) *compute.Instance {
	instance := &compute.Instance{
		ID:     server.ID,
		Name:   server.Name,
		Status: os.mapInstanceStatus(server.Status),
		IP:     server.AccessIPv4,
	}

	servers.ListAddresses(os.ComputeClient, server.ID).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 utils.IsPrivate(addr.Address) {
					if instance.PrivateIP == "" || (utils.GetIPVersion(addr.Address) == 4 && utils.GetIPVersion(instance.PrivateIP) != 4) {
						instance.PrivateIP = addr.Address
					}
				} else if instance.IP == "" || (utils.GetIPVersion(addr.Address) == 4 && utils.GetIPVersion(instance.IP) != 4) {
					instance.IP = addr.Address
				}
			}
		}
		return true, nil
	})

	return instance
}
Esempio n. 2
0
func (cs *CloudStack) vmToInstance(vm *api.VirtualMachine) *compute.Instance {
	instance := &compute.Instance{
		ID:     vm.ID,
		Name:   vm.Hostname,
		Status: cs.mapInstanceStatus(vm.State),
	}

	for _, nic := range vm.Nics {
		if utils.IsPrivate(nic.Addr) {
			instance.PrivateIP = nic.Addr
		} else {
			instance.IP = nic.Addr
		}
	}

	return instance
}
Esempio n. 3
0
func (gc *GoogleCompute) mapInstance(apiInstance *gcompute.Instance) *compute.Instance {
	instance := &compute.Instance{
		ID:     fmt.Sprintf("%s:%s", basename(apiInstance.Zone), apiInstance.Name),
		Name:   apiInstance.Name,
		Region: basename(apiInstance.Zone),
		Status: gc.mapInstanceStatus(apiInstance.Status),
	}

	for _, nic := range apiInstance.NetworkInterfaces {
		if utils.IsPrivate(nic.NetworkIP) {
			instance.PrivateIP = nic.NetworkIP
		} else {
			instance.IP = nic.NetworkIP
		}
	}

	return instance
}