Skip to content

Commit

Permalink
Merge pull request #49 from tdomnesc/equinix-metro-list
Browse files Browse the repository at this point in the history
METAL-1061: equinix list of metros
  • Loading branch information
openshift-merge-bot[bot] authored Jun 25, 2024
2 parents 4052f74 + 350c253 commit 7ec3aed
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions pkg/providers/equinix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ var client *packngo.Client
var eqOnce sync.Once

type equinixProviderConfig struct {
ProjectID string `json:"projectid"` //project id in equinix
Token string `json:"token"` //token for authentication
Metro string `json:"metro"` //server location
Plan string `json:"plan"` //server size
OS string `json:"os"` //OS to install
ProjectID string `json:"projectid"` //project id in equinix
Token string `json:"token"` //token for authentication
Metros []string `json:"metros"` //server location
Plan string `json:"plan"` //server size
OS string `json:"os"` //OS to install
}

type equinixProvider struct {
Expand All @@ -34,7 +34,7 @@ func EquinixProviderFactory(providerInfo string, secretData map[string][]byte) (
config := equinixProviderConfig{
ProjectID: "",
Token: "",
Metro: "da",
Metros: []string{"da", "ny", "sv"},
Plan: "c3.small.x86",
OS: "rocky_8",
}
Expand Down Expand Up @@ -79,22 +79,26 @@ func (p *equinixProvider) Acquire(poolSize int, poolName string, poolType string
uniqueId := strings.Replace(uuid.New().String(), "-", "", -1)
resourceName := fmt.Sprintf("%s-%s", hostPrefix, uniqueId)

cr := packngo.DeviceCreateRequest{
Hostname: resourceName,
Metro: p.config.Metro,
Plan: p.config.Plan,
OS: p.config.OS,
ProjectID: p.config.ProjectID,
Tags: []string{poolName},
}
for _, metro := range p.config.Metros {
cr := packngo.DeviceCreateRequest{
Hostname: resourceName,
Metro: metro,
Plan: p.config.Plan,
OS: p.config.OS,
ProjectID: p.config.ProjectID,
Tags: []string{poolName},
}

device, _, err := p.client.Devices.Create(&cr)
if err != nil {
return resource, fmt.Errorf("error creating device: %w", err)
device, _, err := p.client.Devices.Create(&cr)
if err != nil {
continue
}

resource.Id = device.ID
return resource, nil
}

resource.Id = device.ID
return resource, nil
return resource, fmt.Errorf("error creating device: %w", err)
}

func (p *equinixProvider) AcquireCompleted(id string) (bool, Resource, error) {
Expand Down

0 comments on commit 7ec3aed

Please sign in to comment.