diff --git a/provider.go b/provider.go index 4895121..1c08db6 100644 --- a/provider.go +++ b/provider.go @@ -223,27 +223,30 @@ func (g *InstanceGroup) ConnectInfo(ctx context.Context, instanceID string) (pro return provider.ConnectInfo{}, fmt.Errorf("Server not found %s: %w", node.PhysicalID, os.ErrNotExist) } - // g.log.Info("srv", "srv", srv) + // g.log.Debug("Server info", "srv", srv) if srv.Status != "ACTIVE" { return provider.ConnectInfo{}, fmt.Errorf("instance status is not active: %s", srv.Status) } ipAddr := srv.AccessIPv4 if ipAddr == "" { - addrs, err := extractAddresses(srv) + netAddrs, err := extractAddresses(srv) if err != nil { return provider.ConnectInfo{}, err } // TODO: detect internal (tenant) and external networks - for net, addr := range addrs { - ipAddr = addr.Address - g.log.Debug("Use address", "network", net, "ip_address", ipAddr) + for net, addrs := range netAddrs { + for _, addr := range addrs { + ipAddr = addr.Address + g.log.Debug("Use address", "network", net, "ip_address", ipAddr) + } } } info := provider.ConnectInfo{ ConnectorConfig: g.settings.ConnectorConfig, + ID: instanceID, InternalAddr: ipAddr, ExternalAddr: ipAddr, } @@ -252,6 +255,9 @@ func (g *InstanceGroup) ConnectInfo(ctx context.Context, instanceID string) (pro // TODO: get from image meta info.OS = "linux" info.Arch = "amd64" + info.Protocol = provider.ProtocolSSH + + // g.log.Debug("Info", "info", info) return info, nil } diff --git a/utils.go b/utils.go index adf4f79..d80dab0 100644 --- a/utils.go +++ b/utils.go @@ -42,24 +42,31 @@ type Address struct { Type string `json:"OS-EXT-IPS:type,omitempty"` } -func extractAddresses(srv *servers.Server) (map[string]Address, error) { - ret := make(map[string]Address, len(srv.Addresses)) +func extractAddresses(srv *servers.Server) (map[string][]Address, error) { + ret := make(map[string][]Address, len(srv.Addresses)) - for k, iv := range srv.Addresses { - var out Address + for net, isv := range srv.Addresses { + ism := isv.([]interface{}) + items := make([]Address, 0, len(ism)) - cfg := &mapstructure.DecoderConfig{ - Metadata: nil, - Result: &out, - TagName: "json", - } - decoder, _ := mapstructure.NewDecoder(cfg) - err := decoder.Decode(iv) - if err != nil { - return nil, err + for _, iv := range ism { + var out Address + + cfg := &mapstructure.DecoderConfig{ + Metadata: nil, + Result: &out, + TagName: "json", + } + decoder, _ := mapstructure.NewDecoder(cfg) + err := decoder.Decode(iv) + if err != nil { + return nil, err + } + + items = append(items, out) } - ret[k] = out + ret[net] = items } return ret, nil