Skip to content

Commit

Permalink
Add network-interfaces for Q3 (IBM-Cloud#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismirlia authored Sep 16, 2024
1 parent d4bae35 commit 3d21f55
Show file tree
Hide file tree
Showing 17 changed files with 4,430 additions and 0 deletions.
63 changes: 63 additions & 0 deletions clients/instance/ibm-pi-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/IBM-Cloud/power-go-client/helpers"

"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/networks"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_networks"
"github.com/IBM-Cloud/power-go-client/power/models"
)
Expand Down Expand Up @@ -196,3 +197,65 @@ func (f *IBMPINetworkClient) UpdatePort(id, networkPortID string, body *models.N
}
return resp.Payload, nil
}

// Create a network interface
func (f *IBMPINetworkClient) CreateNetworkInterface(id string, body *models.NetworkInterfaceCreate) (*models.NetworkInterface, error) {
params := networks.NewV1NetworksNetworkInterfacesPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithNetworkID(id).WithBody(body)
resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to create network interface for network %s with %w", id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to create network interface for network %s", id)
}
return resp.Payload, nil
}

// Get all Create a network interface
func (f *IBMPINetworkClient) GetAllNetworkInterfaces(id string) (*models.NetworkInterfaces, error) {
params := networks.NewV1NetworksNetworkInterfacesGetallParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithNetworkID(id)
resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesGetall(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get all network interfaces for network %s: %w", id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to get all network interfaces for network %s", id)
}
return resp.Payload, nil
}

// Get a network interface
func (f *IBMPINetworkClient) GetNetworkInterface(id, netIntID string) (*models.NetworkInterface, error) {
params := networks.NewV1NetworksNetworkInterfacesGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithNetworkID(id).WithNetworkInterfaceID(netIntID)
resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get network interace %s for network %s: %w", netIntID, id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to get network interface %s for network %s", netIntID, id)
}
return resp.Payload, nil
}

// Update a network interface
func (f *IBMPINetworkClient) UpdateNetworkInterface(id, netIntID string, body *models.NetworkInterfaceUpdate) (*models.NetworkInterface, error) {
params := networks.NewV1NetworksNetworkInterfacesPutParams().WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).WithNetworkID(id).WithNetworkInterfaceID(netIntID).WithBody(body)
resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesPut(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to update network interface %s and network %s with error %w", netIntID, id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to update network interface %s and network %s", netIntID, id)
}
return resp.Payload, nil
}

// Delete a network interface
func (f *IBMPINetworkClient) DeleteNetworkInterface(id, netIntID string) error {
params := networks.NewV1NetworksNetworkInterfacesDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).WithNetworkID(id).WithNetworkInterfaceID(netIntID)
_, err := f.session.Power.Networks.V1NetworksNetworkInterfacesDelete(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return fmt.Errorf("failed to delete network interface %s for network %s with error %w", netIntID, id, err)
}
return nil
}
270 changes: 270 additions & 0 deletions power/client/networks/networks_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d21f55

Please sign in to comment.