Skip to content

Commit

Permalink
Added cidr param to dhcp
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Austin committed Jul 7, 2022
1 parent 97c5ba9 commit e9a2b36
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 203 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20220523145737-34645883de47
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20210705152127-41ca00fc9a62
github.com/IBM-Cloud/power-go-client v1.1.9
github.com/IBM-Cloud/power-go-client v1.1.10
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.2.3
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
12 changes: 3 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20220523145737-34645883de47/go.mod h1:tfN
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20210705152127-41ca00fc9a62 h1:MOkcr6qQGk4tY542ZJ1DggVh2WUP72EEyLB79llFVH8=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20210705152127-41ca00fc9a62/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.1.9 h1:NKG4lxQNe1HHANC+94mRqgogIkiAHo5COMNsqUGdNqg=
github.com/IBM-Cloud/power-go-client v1.1.9/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE=
github.com/IBM-Cloud/power-go-client v1.1.10 h1:NUGZwF5V0j2lFurA5LaigsYyOKDKwz4M0sCpm+YIbig=
github.com/IBM-Cloud/power-go-client v1.1.10/go.mod h1:Qfx0fNi+9hms+xu9Z6Euhu9088ByW6C/TCMLECTRWNE=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand All @@ -23,8 +23,6 @@ github.com/IBM/cloudant-go-sdk v0.0.43 h1:YxTy4RpAEezX32YIWnds76hrBREmO4u6IkBz1W
github.com/IBM/cloudant-go-sdk v0.0.43/go.mod h1:WeYrJPaHTw19943ndWnVfwMIlZ5z0XUM2uEXNBrwZ1M=
github.com/IBM/container-registry-go-sdk v0.0.15 h1:sfEXm4qNj9ZCwTlFOsdjF5P/lvajU/Sc22yNlzg0F9I=
github.com/IBM/container-registry-go-sdk v0.0.15/go.mod h1:KqSZFO4VIK9QAyF8O1JW6jkyzkfE/BNKUIo+OdzIDk4=
github.com/IBM/continuous-delivery-go-sdk v0.0.5 h1:nwIvo4S2IAFtndIbloUbTp3unScc3osgapCieD0aD2E=
github.com/IBM/continuous-delivery-go-sdk v0.0.5/go.mod h1:u63XH83hLREOAeGs+/nbe3BEn21udFP9dddryP24OGM=
github.com/IBM/continuous-delivery-go-sdk v0.0.6 h1:XrQwFqGU7n3AzS0j0wou11LFqUaWx7q+UYrq+l4vnW8=
github.com/IBM/continuous-delivery-go-sdk v0.0.6/go.mod h1:u63XH83hLREOAeGs+/nbe3BEn21udFP9dddryP24OGM=
github.com/IBM/event-notifications-go-admin-sdk v0.1.2 h1:LLA12WFqSD0+Uf16SNdErcu2MVK4EnyXHJmDIkKkudE=
Expand Down Expand Up @@ -57,12 +55,8 @@ github.com/IBM/ibm-hpcs-uko-sdk v0.0.4 h1:B3FEq830k/B7HjQqvQubxmz8PxOUvKYD2ZypDq
github.com/IBM/ibm-hpcs-uko-sdk v0.0.4/go.mod h1:MLVNHMYoKsvovJZ4v1gQCpIYtRDHTtoIHK6XztDZGsU=
github.com/IBM/keyprotect-go-client v0.7.0 h1:JstSHD14Lp6ihwQseyPuGcs1AjOBjAmcisP0dTBA6A0=
github.com/IBM/keyprotect-go-client v0.7.0/go.mod h1:SVr2ylV/fhSQPDiUjWirN9fsyWFCNNbt8GIT8hPJVjE=
github.com/IBM/networking-go-sdk v0.28.0 h1:kdZnHb9SaVd/NgYFpOlXfXSA8Q/mASBGaiAECxVI2i4=
github.com/IBM/networking-go-sdk v0.28.0/go.mod h1:tVxXclpQs8nQJYPTr9ZPNC1voaPNQLy8iy/72oVfFtM=
github.com/IBM/networking-go-sdk v0.30.0 h1:GUfvq4AOK0iTUEodPL2k812y2W1GdZs6hUTa81KUKys=
github.com/IBM/networking-go-sdk v0.30.0/go.mod h1:tVxXclpQs8nQJYPTr9ZPNC1voaPNQLy8iy/72oVfFtM=
github.com/IBM/platform-services-go-sdk v0.25.1 h1:hF4EvJNe8KRGiytN0mVJvJaZV4UJHsrJi1xIRgIaa5w=
github.com/IBM/platform-services-go-sdk v0.25.1/go.mod h1:9/v5qTMXaEBOpFe2marMukgCqv83W8PcjPWr91m2Ids=
github.com/IBM/platform-services-go-sdk v0.26.1 h1:8maFrdgp8su5H99v5/fith9ft+nE1V7RRpcM3jBUKYs=
github.com/IBM/platform-services-go-sdk v0.26.1/go.mod h1:ZFuISyKu+qekMfvFebzqJ8AIpNlRqI7a6WuieGfjGuA=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
Expand Down Expand Up @@ -639,6 +633,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down Expand Up @@ -802,7 +797,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f h1:rlezHXNlxYWvBCzNses9Dlc7nGFaNMJeqLolcmQSSZY=
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
88 changes: 54 additions & 34 deletions ibm/service/power/data_source_ibm_pi_dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,124 @@ package power

import (
"context"
"fmt"

"log"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"

"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const (
PIDhcpID = "pi_dhcp_id"
)

func DataSourceIBMPIDhcp() *schema.Resource {

return &schema.Resource{
ReadContext: dataSourceIBMPIDhcpRead,
Schema: map[string]*schema.Schema{
helpers.PICloudInstanceId: {

// Required Arguments
Arg_CloudInstanceID: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},
PIDhcpID: {
Arg_DhcpID: {
Type: schema.TypeString,
Required: true,
Description: "The ID of the DHCP Server",
},
// Computed Attributes
PIDhcpStatus: {
Type: schema.TypeString,
Computed: true,
Description: "The status of the DHCP Server",
},
PIDhcpNetwork: {

// Attributes
Attr_DhcpID: {
Type: schema.TypeString,
Computed: true,
Description: "The DHCP Server private network",
Description: "The ID of the DHCP Server",
},
PIDhcpLeases: {
Attr_DhcpLeases: {
Type: schema.TypeList,
Computed: true,
Description: "The list of DHCP Server PVM Instance leases",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
PIDhcpInstanceIp: {
Attr_DhcpLeaseInstanceIP: {
Type: schema.TypeString,
Computed: true,
Description: "The IP of the PVM Instance",
},
PIDhcpInstanceMac: {
Attr_DhcpLeaseInstanceMac: {
Type: schema.TypeString,
Computed: true,
Description: "The MAC Address of the PVM Instance",
},
},
},
},
Attr_DhcpNetworkDeprecated: {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the DHCP Server private network (deprecated - replaced by network_id)",
},
Attr_DhcpNetworkID: {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the DHCP Server private network",
},
Attr_DhcpNetworkName: {
Type: schema.TypeString,
Computed: true,
Description: "The name of the DHCP Server private network",
},
Attr_DhcpStatus: {
Type: schema.TypeString,
Computed: true,
Description: "The status of the DHCP Server",
},
},
}
}

func dataSourceIBMPIDhcpRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

// session
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
dhcpID := d.Get(PIDhcpID).(string)
// arguments
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
dhcpID := d.Get(Arg_DhcpID).(string)

// client
client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID)

// get dhcp
dhcpServer, err := client.Get(dhcpID)
if err != nil {
log.Printf("[DEBUG] get DHCP failed %v", err)
return diag.FromErr(err)
}

d.SetId(*dhcpServer.ID)
d.Set(PIDhcpStatus, *dhcpServer.Status)
dhcpNetwork := dhcpServer.Network
if dhcpNetwork != nil {
d.Set(PIDhcpNetwork, *dhcpNetwork.ID)
}
dhcpLeases := dhcpServer.Leases
if dhcpLeases != nil {
leaseList := make([]map[string]string, len(dhcpLeases))
for i, lease := range dhcpLeases {
// set attributes
d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, *dhcpServer.ID))
d.Set(Attr_DhcpID, *dhcpServer.ID)
d.Set(Attr_DhcpNetworkDeprecated, *dhcpServer.Network.ID)
d.Set(Attr_DhcpNetworkID, *dhcpServer.Network.ID)
d.Set(Attr_DhcpNetworkName, *dhcpServer.Network.Name)
d.Set(Attr_DhcpStatus, *dhcpServer.Status)
if dhcpServer.Leases != nil {
leases := dhcpServer.Leases
leaseList := make([]map[string]string, len(leases))
for i, lease := range leases {
leaseList[i] = map[string]string{
PIDhcpInstanceIp: *lease.InstanceIP,
PIDhcpInstanceMac: *lease.InstanceMacAddress,
Attr_DhcpLeaseInstanceIP: *lease.InstanceIP,
Attr_DhcpLeaseInstanceMac: *lease.InstanceMacAddress,
}
}
d.Set(PIDhcpLeases, leaseList)
d.Set(Attr_DhcpLeases, leaseList)
}

return nil
Expand Down
65 changes: 40 additions & 25 deletions ibm/service/power/data_source_ibm_pi_dhcps.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -21,38 +20,50 @@ import (
Datasource to get the list of dhcp servers in a power instance
*/

const PIDhcpServers = "servers"

func DataSourceIBMPIDhcps() *schema.Resource {

return &schema.Resource{
ReadContext: dataSourceIBMPIDhcpServersRead,
Schema: map[string]*schema.Schema{
helpers.PICloudInstanceId: {

// Required Arguments
Arg_CloudInstanceID: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},
// Computed Attributes
PIDhcpServers: {
Type: schema.TypeList,
Computed: true,

// Attributes
Attr_DhcpServers: {
Type: schema.TypeList,
Computed: true,
Description: "The list of all the DHCP Servers",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
PIDhcpId: {
Attr_DhcpID: {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the DHCP Server",
},
PIDhcpStatus: {
Attr_DhcpNetworkDeprecated: {
Type: schema.TypeString,
Computed: true,
Description: "The status of the DHCP Server",
Description: "The ID of the DHCP Server private network (deprecated - replaced by network_id)",
},
Attr_DhcpNetworkID: {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the DHCP Server private network",
},
Attr_DhcpNetworkName: {
Type: schema.TypeString,
Computed: true,
Description: "The name of the DHCP Server private network",
},
PIDhcpNetwork: {
Attr_DhcpStatus: {
Type: schema.TypeString,
Computed: true,
Description: "The DHCP Server private network",
Description: "The status of the DHCP Server",
},
},
},
Expand All @@ -62,37 +73,41 @@ func DataSourceIBMPIDhcps() *schema.Resource {
}

func dataSourceIBMPIDhcpServersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

// session and client
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
}

cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
// arguments
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)

// client
client := st.NewIBMPIDhcpClient(ctx, sess, cloudInstanceID)

// get all dhcp
dhcpServers, err := client.GetAll()
if err != nil {
log.Printf("[DEBUG] get all DHCP failed %v", err)
return diag.FromErr(err)
}

result := make([]map[string]interface{}, 0, len(dhcpServers))
// set attributes
servers := make([]map[string]interface{}, 0, len(dhcpServers))
for _, dhcpServer := range dhcpServers {
server := map[string]interface{}{
PIDhcpId: *dhcpServer.ID,
PIDhcpStatus: *dhcpServer.Status,
}

dhcpNetwork := dhcpServer.Network
if dhcpNetwork != nil {
server[PIDhcpNetwork] = *dhcpNetwork.ID
Attr_DhcpID: *dhcpServer.ID,
Attr_DhcpNetworkDeprecated: *dhcpServer.Network.ID,
Attr_DhcpNetworkID: *dhcpServer.Network.ID,
Attr_DhcpNetworkName: *dhcpServer.Network.Name,
Attr_DhcpStatus: *dhcpServer.Status,
}
result = append(result, server)
servers = append(servers, server)
}

var genID, _ = uuid.GenerateUUID()
d.SetId(genID)
d.Set(PIDhcpServers, result)
d.Set(Attr_DhcpServers, servers)

return nil
}
38 changes: 28 additions & 10 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import "time"

const (

// used by all
Arg_CloudInstanceID = "pi_cloud_instance_id"

// Keys
PIKeys = "keys"
PIKeyName = "name"
Expand All @@ -20,16 +23,21 @@ const (
PISAPProfileType = "type"

// DHCP
PIDhcpStatusBuilding = "Building"
PIDhcpStatusActive = "ACTIVE"
PIDhcpDeleting = "Deleting"
PIDhcpDeleted = "Deleted"
PIDhcpId = "dhcp_id"
PIDhcpStatus = "status"
PIDhcpNetwork = "network"
PIDhcpLeases = "leases"
PIDhcpInstanceIp = "instance_ip"
PIDhcpInstanceMac = "instance_mac"
Arg_DhcpCidr = "pi_cidr"
Arg_DhcpID = "pi_dhcp_id"
Arg_DhcpCloudConnectionID = "pi_cloud_connection_id"
Arg_DhcpDnsServer = "pi_dns_server"
Arg_DhcpName = "pi_dhcp_name"

Attr_DhcpServers = "servers"
Attr_DhcpID = "dhcp_id"
Attr_DhcpLeases = "leases"
Attr_DhcpLeaseInstanceIP = "instance_ip"
Attr_DhcpLeaseInstanceMac = "instance_mac"
Attr_DhcpNetworkDeprecated = "network" // to deprecate
Attr_DhcpNetworkID = "network_id"
Attr_DhcpNetworkName = "network_name"
Attr_DhcpStatus = "status"

// Instance
//Added timeout values for warning and active status
Expand Down Expand Up @@ -66,4 +74,14 @@ const (

// Cloud Connections
PICloudConnectionTransitEnabled = "pi_cloud_connection_transit_enabled"

// status
// common status states
StatusShutoff = "SHUTOFF"
StatusActive = "ACTIVE"
StatusResize = "RESIZE"
StatusError = "ERROR"
StatusBuild = "BUILD"
SctionStart = "start"
SctionStop = "stop"
)
Loading

0 comments on commit e9a2b36

Please sign in to comment.