Skip to content

Commit d608165

Browse files
committed
add associated resource id information in the disassociate command
1 parent 035d4e0 commit d608165

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

internal/cmd/beta/public-ip/associate/associate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
5555
return err
5656
}
5757

58-
publicIpLabel, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
58+
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
5959
if err != nil {
6060
p.Debug(print.ErrorLevel, "get public IP: %v", err)
6161
publicIpLabel = model.PublicIpId

internal/cmd/beta/public-ip/delete/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
5353
return err
5454
}
5555

56-
publicIpLabel, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
56+
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
5757
if err != nil {
5858
p.Debug(print.ErrorLevel, "get public IP: %v", err)
5959
publicIpLabel = model.PublicIpId

internal/cmd/beta/public-ip/disassociate/disassociate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ func NewCmd(p *print.Printer) *cobra.Command {
5151
return err
5252
}
5353

54-
publicIpLabel, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
54+
publicIpLabel, associatedResourceId, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
5555
if err != nil {
5656
p.Debug(print.ErrorLevel, "get public IP: %v", err)
5757
publicIpLabel = model.PublicIpId
5858
}
5959

6060
if !model.AssumeYes {
61-
prompt := fmt.Sprintf("Are you sure you want to disassociate public IP %q from the associated resource?", publicIpLabel)
61+
prompt := fmt.Sprintf("Are you sure you want to disassociate public IP %q from the associated resource %q?", publicIpLabel, associatedResourceId)
6262
err = p.PromptForConfirmation(prompt)
6363
if err != nil {
6464
return err
@@ -72,7 +72,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7272
return fmt.Errorf("disassociate public IP: %w", err)
7373
}
7474

75-
p.Outputf("Disassociated public IP %q from the associated resource.\n", publicIpLabel)
75+
p.Outputf("Disassociated public IP %q from the associated resource %q.\n", publicIpLabel, associatedResourceId)
7676
return nil
7777
},
7878
}

internal/cmd/beta/public-ip/update/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
6161
return err
6262
}
6363

64-
publicIpLabel, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
64+
publicIpLabel, _, err := iaasUtils.GetPublicIP(ctx, apiClient, model.ProjectId, model.PublicIpId)
6565
if err != nil {
6666
p.Debug(print.ErrorLevel, "get public IP: %v", err)
6767
publicIpLabel = model.PublicIpId

internal/pkg/services/iaas/utils/utils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ type IaaSClient interface {
1717
GetNetworkAreaRangeExecute(ctx context.Context, organizationId, areaId, networkRangeId string) (*iaas.NetworkRange, error)
1818
}
1919

20-
func GetPublicIP(ctx context.Context, apiClient IaaSClient, projectId, publicIpId string) (string, error) {
20+
func GetPublicIP(ctx context.Context, apiClient IaaSClient, projectId, publicIpId string) (string, string, error) {
2121
resp, err := apiClient.GetPublicIPExecute(ctx, projectId, publicIpId)
2222
if err != nil {
23-
return "", fmt.Errorf("get public ip: %w", err)
23+
return "", "", fmt.Errorf("get public ip: %w", err)
2424
}
25-
return *resp.Ip, nil
25+
associatedResourceId := ""
26+
if resp.GetNetworkInterface() != nil {
27+
associatedResourceId = *resp.GetNetworkInterface()
28+
}
29+
return *resp.Ip, associatedResourceId, nil
2630
}
2731

2832
func GetServerName(ctx context.Context, apiClient IaaSClient, projectId, serverId string) (string, error) {

internal/pkg/services/iaas/utils/utils_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func TestGetPublicIp(t *testing.T) {
9191
name: "base",
9292
args: args{
9393
getPublicIpResp: &iaas.PublicIp{
94-
Ip: utils.Ptr("1.2.3.4"),
94+
Ip: utils.Ptr("1.2.3.4"),
95+
NetworkInterface: iaas.NewNullableString(utils.Ptr("1.2.3.4")),
9596
},
9697
},
9798
want: "1.2.3.4",
@@ -110,7 +111,7 @@ func TestGetPublicIp(t *testing.T) {
110111
GetPublicIpFails: tt.args.getPublicIpFails,
111112
GetPublicIpResp: tt.args.getPublicIpResp,
112113
}
113-
got, err := GetPublicIP(context.Background(), m, "", "")
114+
got, _, err := GetPublicIP(context.Background(), m, "", "")
114115
if (err != nil) != tt.wantErr {
115116
t.Errorf("GetPublicIP() error = %v, wantErr %v", err, tt.wantErr)
116117
return

0 commit comments

Comments
 (0)