|
8 | 8 | "github.com/IBM-Cloud/power-go-client/helpers"
|
9 | 9 |
|
10 | 10 | "github.com/IBM-Cloud/power-go-client/ibmpisession"
|
| 11 | + "github.com/IBM-Cloud/power-go-client/power/client/networks" |
11 | 12 | "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_networks"
|
12 | 13 | "github.com/IBM-Cloud/power-go-client/power/models"
|
13 | 14 | )
|
@@ -196,3 +197,65 @@ func (f *IBMPINetworkClient) UpdatePort(id, networkPortID string, body *models.N
|
196 | 197 | }
|
197 | 198 | return resp.Payload, nil
|
198 | 199 | }
|
| 200 | + |
| 201 | +// Create a network interface |
| 202 | +func (f *IBMPINetworkClient) CreateNetworkInterface(id string, body *models.NetworkInterfaceCreate) (*models.NetworkInterface, error) { |
| 203 | + params := networks.NewV1NetworksNetworkInterfacesPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithNetworkID(id).WithBody(body) |
| 204 | + resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesPost(params, f.session.AuthInfo(f.cloudInstanceID)) |
| 205 | + if err != nil { |
| 206 | + return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to create network interface for network %s with %w", id, err)) |
| 207 | + } |
| 208 | + if resp == nil || resp.Payload == nil { |
| 209 | + return nil, fmt.Errorf("failed to create network interface for network %s", id) |
| 210 | + } |
| 211 | + return resp.Payload, nil |
| 212 | +} |
| 213 | + |
| 214 | +// Get all Create a network interface |
| 215 | +func (f *IBMPINetworkClient) GetAllNetworkInterfaces(id string) (*models.NetworkInterfaces, error) { |
| 216 | + params := networks.NewV1NetworksNetworkInterfacesGetallParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithNetworkID(id) |
| 217 | + resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesGetall(params, f.session.AuthInfo(f.cloudInstanceID)) |
| 218 | + if err != nil { |
| 219 | + return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get all network interfaces for network %s: %w", id, err)) |
| 220 | + } |
| 221 | + if resp == nil || resp.Payload == nil { |
| 222 | + return nil, fmt.Errorf("failed to get all network interfaces for network %s", id) |
| 223 | + } |
| 224 | + return resp.Payload, nil |
| 225 | +} |
| 226 | + |
| 227 | +// Get a network interface |
| 228 | +func (f *IBMPINetworkClient) GetNetworkInterface(id, netIntID string) (*models.NetworkInterface, error) { |
| 229 | + params := networks.NewV1NetworksNetworkInterfacesGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithNetworkID(id).WithNetworkInterfaceID(netIntID) |
| 230 | + resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesGet(params, f.session.AuthInfo(f.cloudInstanceID)) |
| 231 | + if err != nil { |
| 232 | + return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to get network interace %s for network %s: %w", netIntID, id, err)) |
| 233 | + } |
| 234 | + if resp == nil || resp.Payload == nil { |
| 235 | + return nil, fmt.Errorf("failed to get network interface %s for network %s", netIntID, id) |
| 236 | + } |
| 237 | + return resp.Payload, nil |
| 238 | +} |
| 239 | + |
| 240 | +// Update a network interface |
| 241 | +func (f *IBMPINetworkClient) UpdateNetworkInterface(id, netIntID string, body *models.NetworkInterfaceUpdate) (*models.NetworkInterface, error) { |
| 242 | + params := networks.NewV1NetworksNetworkInterfacesPutParams().WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).WithNetworkID(id).WithNetworkInterfaceID(netIntID).WithBody(body) |
| 243 | + resp, err := f.session.Power.Networks.V1NetworksNetworkInterfacesPut(params, f.session.AuthInfo(f.cloudInstanceID)) |
| 244 | + if err != nil { |
| 245 | + return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to update network interface %s and network %s with error %w", netIntID, id, err)) |
| 246 | + } |
| 247 | + if resp == nil || resp.Payload == nil { |
| 248 | + return nil, fmt.Errorf("failed to update network interface %s and network %s", netIntID, id) |
| 249 | + } |
| 250 | + return resp.Payload, nil |
| 251 | +} |
| 252 | + |
| 253 | +// Delete a network interface |
| 254 | +func (f *IBMPINetworkClient) DeleteNetworkInterface(id, netIntID string) error { |
| 255 | + params := networks.NewV1NetworksNetworkInterfacesDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).WithNetworkID(id).WithNetworkInterfaceID(netIntID) |
| 256 | + _, err := f.session.Power.Networks.V1NetworksNetworkInterfacesDelete(params, f.session.AuthInfo(f.cloudInstanceID)) |
| 257 | + if err != nil { |
| 258 | + return fmt.Errorf("failed to delete network interface %s for network %s with error %w", netIntID, id, err) |
| 259 | + } |
| 260 | + return nil |
| 261 | +} |
0 commit comments