Skip to content

Commit

Permalink
Update NSG and NAG types (#452)
Browse files Browse the repository at this point in the history
* Change NSG and NAG response types

* Fix deletes
  • Loading branch information
Alexander-Kita authored Aug 26, 2024
1 parent 81afc73 commit 5d12ac1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
13 changes: 5 additions & 8 deletions clients/instance/ibm-pi-network-address-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (f *IBMPINetworkAddressGroupClient) Delete(id string) error {
}

// Add a member to a Network Address Group
func (f *IBMPINetworkAddressGroupClient) AddMember(id string, body *models.NetworkAddressGroupAddMember) (*models.NetworkAddressGroup, error) {
func (f *IBMPINetworkAddressGroupClient) AddMember(id string, body *models.NetworkAddressGroupAddMember) (*models.NetworkAddressGroupMember, error) {
params := network_address_groups.NewV1NetworkAddressGroupsMembersPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithNetworkAddressGroupID(id)
resp, err := f.session.Power.NetworkAddressGroups.V1NetworkAddressGroupsMembersPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
Expand All @@ -103,15 +103,12 @@ func (f *IBMPINetworkAddressGroupClient) AddMember(id string, body *models.Netwo
}

// Delete the member from a Network Address Group
func (f *IBMPINetworkAddressGroupClient) DeleteMember(id, memberId string) (*models.NetworkAddressGroup, error) {
func (f *IBMPINetworkAddressGroupClient) DeleteMember(id, memberId string) error {
params := network_address_groups.NewV1NetworkAddressGroupsMembersDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).WithNetworkAddressGroupID(id).WithNetworkAddressGroupMemberID(memberId)
resp, err := f.session.Power.NetworkAddressGroups.V1NetworkAddressGroupsMembersDelete(params, f.session.AuthInfo(f.cloudInstanceID))
_, err := f.session.Power.NetworkAddressGroups.V1NetworkAddressGroupsMembersDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete member %s from network address group %s: %w", memberId, id, err))
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete member %s from network address group %s: %w", memberId, id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to delete member %s from network address group %s", memberId, id)
}
return resp.Payload, nil

return nil
}
26 changes: 10 additions & 16 deletions clients/instance/ibm-pi-network-security-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (f *IBMPINetworkSecurityGroupClient) Delete(id string) error {
}

// Add a member to a network security group
func (f *IBMPINetworkSecurityGroupClient) AddMember(id string, body *models.NetworkSecurityGroupAddMember) (*models.NetworkSecurityGroup, error) {
func (f *IBMPINetworkSecurityGroupClient) AddMember(id string, body *models.NetworkSecurityGroupAddMember) (*models.NetworkSecurityGroupMember, error) {
params := network_security_groups.NewV1NetworkSecurityGroupsMembersPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithNetworkSecurityGroupID(id).WithBody(body)
resp, err := f.session.Power.NetworkSecurityGroups.V1NetworkSecurityGroupsMembersPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
Expand All @@ -101,20 +101,17 @@ func (f *IBMPINetworkSecurityGroupClient) AddMember(id string, body *models.Netw
}

// Deleta a member from a network securti group
func (f *IBMPINetworkSecurityGroupClient) DeleteMember(id, memberId string) (*models.NetworkSecurityGroup, error) {
func (f *IBMPINetworkSecurityGroupClient) DeleteMember(id, memberId string) error {
params := network_security_groups.NewV1NetworkSecurityGroupsMembersDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).WithNetworkSecurityGroupID(id).WithNetworkSecurityGroupMemberID(memberId)
resp, err := f.session.Power.NetworkSecurityGroups.V1NetworkSecurityGroupsMembersDelete(params, f.session.AuthInfo(f.cloudInstanceID))
_, err := f.session.Power.NetworkSecurityGroups.V1NetworkSecurityGroupsMembersDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete member %s from network security group %s: %w", memberId, id, err))
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete member %s from network security group %s: %w", memberId, id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to delete member %s from network security group %s", memberId, id)
}
return resp.Payload, nil
return nil
}

// Add a rule to a network security group
func (f *IBMPINetworkSecurityGroupClient) AddRule(id string, body *models.NetworkSecurityGroupAddRule) (*models.NetworkSecurityGroup, error) {
func (f *IBMPINetworkSecurityGroupClient) AddRule(id string, body *models.NetworkSecurityGroupAddRule) (*models.NetworkSecurityGroupRule, error) {
params := network_security_groups.NewV1NetworkSecurityGroupsRulesPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithNetworkSecurityGroupID(id).WithBody(body)
resp, err := f.session.Power.NetworkSecurityGroups.V1NetworkSecurityGroupsRulesPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
Expand All @@ -127,16 +124,13 @@ func (f *IBMPINetworkSecurityGroupClient) AddRule(id string, body *models.Networ
}

// Delete a rule from a network security group
func (f *IBMPINetworkSecurityGroupClient) DeleteRule(id, ruleId string) (*models.NetworkSecurityGroup, error) {
func (f *IBMPINetworkSecurityGroupClient) DeleteRule(id, ruleId string) error {
params := network_security_groups.NewV1NetworkSecurityGroupsRulesDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).WithNetworkSecurityGroupID(id).WithNetworkSecurityGroupRuleID(ruleId)
resp, err := f.session.Power.NetworkSecurityGroups.V1NetworkSecurityGroupsRulesDelete(params, f.session.AuthInfo(f.cloudInstanceID))
_, err := f.session.Power.NetworkSecurityGroups.V1NetworkSecurityGroupsRulesDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete rule %s from network security group %s: %w", ruleId, id, err))
return ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to delete rule %s from network security group %s: %w", ruleId, id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to delete rule %s from network security group %s", ruleId, id)
}
return resp.Payload, nil
return nil
}

// Action on a network security group
Expand Down

0 comments on commit 5d12ac1

Please sign in to comment.