Skip to content

Commit

Permalink
fix: check if serverId is set before making requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmocanu-ionos committed Feb 22, 2024
1 parent 4ec1aeb commit 251d942
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/usage/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Available Options for the IONOS Cloud Docker Machine Driver:
| `--ionoscloud-template` | Ionos Cloud Template name (CUBES XS, CUBES S, etc.) |
| `--ionoscloud-server-availability-zone` | Ionos Cloud Server Availability Zone \(AUTO, ZONE\_1, ZONE\_2, ZONE\_3\) |
| `--ionoscloud-cores` | Ionos Cloud Server Cores \(2, 3, 4, 5, 6, etc.\) |
| `--ionoscloud-cpu-family` | Ionos Cloud Server CPU families \(AMD\_OPTERON,INTEL\_XEON, INTEL\_SKYLAKE\) |
| `--ionoscloud-cpu-family` | Ionos Cloud Server CPU families \(AMD\_OPTERON,INTEL\_XEON, INTEL\_SKYLAKE\,INTEL\_ICELAKE,AMD\_EPYC) |
| `--ionoscloud-ram` | Ionos Cloud Server Ram in MB \(1024, 2048, 3072, 4096, etc.\) |
| `--ionoscloud-volume-availability-zone` | Ionos Cloud Volume Availability Zone \(AUTO, ZONE\_1, ZONE\_2, ZONE\_3\) |
| `--ionoscloud-cloud-init` | The cloud-init configuration for the volume as multiline text |
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,12 @@ func (c *Client) WaitForNicIpChange(datacenterId, serverId, nicId string, timeou
initialIp = (*nicIps)[0]
}

ticker := time.NewTicker(2 * time.Second)
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
start := time.Now()

for range ticker.C {
if time.Since(start) > time.Second*time.Duration(timeout+5) {
if time.Since(start) > time.Second*time.Duration(timeout+15) {
break
}
nic, err = c.GetNic(datacenterId, serverId, nicId)
Expand Down
11 changes: 9 additions & 2 deletions ionoscloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: flagServerCpuFamily,
EnvVar: extflag.KebabCaseToEnvVarCase(flagServerCpuFamily),
Value: defaultCpuFamily,
Usage: "Ionos Cloud Server CPU families (AMD_OPTERON, INTEL_XEON, INTEL_SKYLAKE)",
Usage: "Ionos Cloud Server CPU families (AMD_OPTERON, INTEL_XEON, INTEL_SKYLAKE, INTEL_ICELAKE, AMD_EPYC)",
},
mcnflag.StringFlag{
Name: flagDatacenterId,
Expand Down Expand Up @@ -802,7 +802,11 @@ func (d *Driver) Create() (err error) {
if err != nil {
return fmt.Errorf("error getting server by id: %w", err)
}
d.VolumeId = *(*server.Entities.GetVolumes().Items)[0].GetId()
volumes, ok := server.Entities.GetVolumesOk()
if ok != true {
return fmt.Errorf("error getting server: d.ServerId is empty")
}
d.VolumeId = *(*volumes.Items)[0].GetId()
log.Debugf("Volume ID: %v", d.VolumeId)

// Reserve IP if needed
Expand Down Expand Up @@ -1084,6 +1088,9 @@ func (d *Driver) GetIP() (string, error) {

// GetState returns the state of the machine role instance.
func (d *Driver) GetState() (state.State, error) {
if d.ServerId == "" {
return state.None, fmt.Errorf("error getting server: d.ServerID is empty")
}
server, err := d.client().GetServer(d.DatacenterId, d.ServerId)
if err != nil {
return state.None, fmt.Errorf("error getting server: %w", err)
Expand Down

0 comments on commit 251d942

Please sign in to comment.