diff --git a/pkg/stackit/network.go b/pkg/stackit/network.go index e1fff2b..3ac6ca4 100644 --- a/pkg/stackit/network.go +++ b/pkg/stackit/network.go @@ -32,5 +32,13 @@ func (s *Stackit) createNetwork(ctx context.Context, projectId string, networkNa } func (s *Stackit) deleteNetwork(ctx context.Context, projectId string, networkId string) error { - return s.client.DeleteNetworkExecute(ctx, projectId, networkId) + err := s.client.DeleteNetworkExecute(ctx, projectId, networkId) + if err != nil { + return err + } + _, err = wait.DeleteNetworkWaitHandler(ctx, s.client, projectId, networkId).WaitWithContext(ctx) + if err != nil { + return err + } + return nil } diff --git a/pkg/stackit/stackit.go b/pkg/stackit/stackit.go index f2103e6..8dfc996 100644 --- a/pkg/stackit/stackit.go +++ b/pkg/stackit/stackit.go @@ -80,11 +80,8 @@ func (s *Stackit) Status(ctx context.Context, projectId, machineName string) (cl if server == nil { return client.StatusNotFound, nil } - if server.GetPowerStatus() == nil { - return client.StatusNotFound, nil - } - return statusFromPowerStateString(*server.GetPowerStatus()), nil + return statusFromPowerStateString(server.GetPowerStatus()), nil } func (s *Stackit) Start(ctx context.Context, projectId, machineName string) error { @@ -149,15 +146,11 @@ func (s *Stackit) Delete(ctx context.Context, projectId, machineName string) err } networkId := nics[0].NetworkId - err = s.client.DeleteNetwork(ctx, projectId, *networkId).Execute() + err = s.deleteNetwork(ctx, projectId, *networkId) if err != nil { log.Default.Errorf("failed to delete network") gotError = true } - _, err = wait.DeleteNetworkWaitHandler(ctx, s.client, projectId, *networkId).WaitWithContext(ctx) - if err != nil { - log.Default.Errorf("error while waiting for network deletion") - } for _, id := range *nics[0].SecurityGroups { name, err := s.getSecurityGroupNameByID(ctx, projectId, id) @@ -227,7 +220,7 @@ func (s *Stackit) Create(ctx context.Context, options *options.Options, publicKe NetworkId: network.NetworkId, }, }, - UserData: &userdata, + UserData: userdata, } server, err := s.client.CreateServer(ctx, options.ProjectID).CreateServerPayload(createServerPayload).Execute() @@ -286,10 +279,10 @@ func (s *Stackit) Create(ctx context.Context, options *options.Options, publicKe return nil } -func generateUserData(publicKey string) (string, error) { +func generateUserData(publicKey string) (*[]byte, error) { t, err := template.New("cloud-config.yaml").ParseFS(cloudConfigFS, "cloud-config.yaml") if err != nil { - return "", err + return nil, err } output := new(bytes.Buffer) @@ -297,25 +290,12 @@ func generateUserData(publicKey string) (string, error) { "PublicKey": publicKey, "Username": SSHUserName, }); err != nil { - return "", err - } - - return base64.StdEncoding.EncodeToString(output.Bytes()), nil -} - -func (s *Stackit) createVolume(ctx context.Context, projectId, volumeName, volumeAvailabilityZone string, volumeSize int64) (string, error) { - createVolumePayload := iaas.CreateVolumePayload{ - Name: &volumeName, - AvailabilityZone: &volumeAvailabilityZone, - Size: &volumeSize, - } - - volume, err := s.client.CreateVolume(ctx, projectId).CreateVolumePayload(createVolumePayload).Execute() - if err != nil { - return "", err + return nil, err } - return *volume.Id, nil + encodedUserData := base64.StdEncoding.EncodeToString(output.Bytes()) + byteArray := []byte(encodedUserData) + return &byteArray, nil } func (s *Stackit) getServerByName(ctx context.Context, projectId, serverName string) (*iaas.Server, error) {