Skip to content

Commit

Permalink
Refactor PI Instance
Browse files Browse the repository at this point in the history
Fix conflict

Sync branch to master

Remove duplicate const

Update mac_address

Fix test
  • Loading branch information
michaelkad authored and hkantare committed Aug 16, 2024
1 parent d960a55 commit 045433e
Show file tree
Hide file tree
Showing 17 changed files with 816 additions and 800 deletions.
6 changes: 6 additions & 0 deletions ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func DataSourceIBMPIInstance() *schema.Resource {
Description: "The MAC address of the instance.",
Type: schema.TypeString,
},
Attr_Macaddress: {
Computed: true,
Deprecated: "Deprecated, use mac_address instead",
Description: "The MAC address of the instance.",
Type: schema.TypeString,
},
Attr_NetworkID: {
Computed: true,
Description: "The network ID of the instance.",
Expand Down
4 changes: 2 additions & 2 deletions ibm/service/power/data_source_ibm_pi_instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func DataSourceIBMPIInstanceIP() *schema.Resource {
Description: "The IP octet of the network that is attached to this instance.",
Type: schema.TypeString,
},
Attr_MacAddress: {
Attr_Macaddress: {
Computed: true,
Description: "The MAC address of the network that is attached to this instance.",
Type: schema.TypeString,
Expand Down Expand Up @@ -96,7 +96,7 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData,
d.SetId(network.NetworkID)
d.Set(Attr_ExternalIP, network.ExternalIP)
d.Set(Attr_IP, network.IPAddress)
d.Set(Attr_MacAddress, network.MacAddress)
d.Set(Attr_Macaddress, network.MacAddress)
d.Set(Attr_NetworkID, network.NetworkID)
d.Set(Attr_Type, network.Type)

Expand Down
6 changes: 6 additions & 0 deletions ibm/service/power/data_source_ibm_pi_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func DataSourceIBMPIInstances() *schema.Resource {
Description: "The MAC address of the instance.",
Type: schema.TypeString,
},
Attr_Macaddress: {
Computed: true,
Deprecated: "Deprecated, use mac_address instead",
Description: "The MAC address of the instance.",
Type: schema.TypeString,
},
Attr_NetworkID: {
Computed: true,
Description: "The network ID of the instance.",
Expand Down
8 changes: 4 additions & 4 deletions ibm/service/power/data_source_ibm_pi_network_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func DataSourceIBMPINetworkPort() *schema.Resource {
Description: "Network port href.",
Type: schema.TypeString,
},
Attr_IPAddress: {
Attr_IPaddress: {
Computed: true,
Description: "The IP address of the port.",
Type: schema.TypeString,
},
Attr_MacAddress: {
Attr_Macaddress: {
Computed: true,
Description: "The MAC address of the port.",
Type: schema.TypeString,
Expand Down Expand Up @@ -111,8 +111,8 @@ func flattenNetworkPorts(networkPorts []*models.NetworkPort) interface{} {
l := map[string]interface{}{
Attr_Description: i.Description,
Attr_Href: i.Href,
Attr_IPAddress: *i.IPAddress,
Attr_MacAddress: *i.MacAddress,
Attr_IPaddress: *i.IPAddress,
Attr_Macaddress: *i.MacAddress,
Attr_PortID: *i.PortID,
Attr_PublicIP: i.ExternalIP,
Attr_Status: *i.Status,
Expand Down
98 changes: 36 additions & 62 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (
Arg_Name = "pi_name"
Arg_Network = "pi_network"
Arg_NetworkName = "pi_network_name"
Arg_PIInstanceSharedProcessorPool = "pi_shared_processor_pool"
Arg_PinPolicy = "pi_pin_policy"
Arg_PlacementGroupID = "pi_placement_group_id"
Arg_PlacementGroupName = "pi_placement_group_name"
Expand Down Expand Up @@ -100,6 +99,10 @@ const (
Arg_VolumeType = "pi_volume_type"
Arg_VTL = "vtl"

// Duplicate Arguments, will be removed as refactoring take course.
PIVolumeGroupID = "pi_volume_group_id"
PIVolumeOnboardingID = "pi_volume_onboarding_id"

// Attributes
Attr_Access = "access"
Attr_AccessConfig = "access_config"
Expand Down Expand Up @@ -198,14 +201,16 @@ const (
Attr_Images = "images"
Attr_ImageType = "image_type"
Attr_InputVolumes = "input_volumes"
Attr_InstanceID = "instance_id"
Attr_InstanceIP = "instance_ip"
Attr_InstanceMac = "instance_mac"
Attr_Instances = "instances"
Attr_InstanceSnapshots = "instance_snapshots"
Attr_InstanceVolumes = "instance_volumes"
Attr_IOThrottleRate = "io_throttle_rate"
Attr_IP = "ip"
Attr_IPAddress = "ipaddress"
Attr_IPAddress = "ip_address"
Attr_IPaddress = "ipaddress"
Attr_IPOctet = "ipoctet"
Attr_IsActive = "is_active"
Attr_Jumbo = "jumbo"
Expand All @@ -220,7 +225,8 @@ const (
Attr_LicenseRepositoryCapacity = "license_repository_capacity"
Attr_LicenseType = "license_type"
Attr_Location = "location"
Attr_MacAddress = "macaddress"
Attr_MacAddress = "mac_address"
Attr_Macaddress = "macaddress"
Attr_MasterChangedVolumeName = "master_changed_volume_name"
Attr_MasterVolumeName = "master_volume_name"
Attr_Max = "max"
Expand Down Expand Up @@ -255,9 +261,8 @@ const (
Attr_NumberOfVolumes = "number_of_volumes"
Attr_Onboardings = "onboardings"
Attr_OperatingSystem = "operating_system"
Attr_OSType = "os_type"
Attr_PercentComplete = "percent_complete"
Attr_PIInstanceSharedProcessorPool = "shared_processor_pool"
Attr_PIInstanceSharedProcessorPoolID = "shared_processor_pool_id"
Attr_PinPolicy = "pin_policy"
Attr_PlacementGroupID = "placement_group_id"
Attr_PlacementGroups = "placement_groups"
Expand Down Expand Up @@ -309,14 +314,12 @@ const (
Attr_SharedProcessorPoolInstanceMemory = "memory"
Attr_SharedProcessorPoolInstanceName = "name"
Attr_SharedProcessorPoolInstances = "instances"
Attr_SharedProcessorPoolInstanceStatus = "status"
Attr_SharedProcessorPoolInstanceUncapped = "uncapped"
Attr_SharedProcessorPoolInstanceVcpus = "vcpus"
Attr_SharedProcessorPoolName = "name"
Attr_SharedProcessorPoolPlacementGroups = "spp_placement_groups"
Attr_SharedProcessorPoolReservedCores = "reserved_cores"
Attr_SharedProcessorPools = "shared_processor_pools"
Attr_SharedProcessorPoolStatus = "status"
Attr_SharedProcessorPoolStatusDetail = "status_detail"
Attr_Size = "size"
Attr_SnapshotID = "snapshot_id"
Expand Down Expand Up @@ -392,6 +395,18 @@ const (
Attr_WorkspaceType = "pi_workspace_type"
Attr_WWN = "wwn"

// Duplicate Attributes, will be removed as refactoring take course.
PICloudConnectionClassicGreSource = "gre_source_address"
PICloudConnectionConnectionMode = "connection_mode"
PICloudConnectionIBMIPAddress = "ibm_ip_address"
PICloudConnectionId = "cloud_connection_id"
PICloudConnectionPort = "port"
PICloudConnectionUserIPAddress = "user_ip_address"
PIDRLocation = "location"
PIPlacementGroupID = "placement_group_id"
PIPlacementGroupMembers = "members"
PIVPNConnectionDeadPeerDetectionAction = "action"

// OS Type
OS_IBMI = "ibmi"
StockVTL = "stock-vtl"
Expand Down Expand Up @@ -442,13 +457,12 @@ const (
State_Added = "added"
State_Adding = "adding"
State_Available = "available"
State_BUILD = "BUILD"
State_Build = "build"
State_Building = "building"
State_Completed = "completed"
State_Creating = "creating"
State_Deleted = "deleted"
State_Deleting = "deleting"
State_DELETING = "DELETING"
State_Down = "down"
State_Error = "error"
State_ERROR = "ERROR"
Expand All @@ -457,68 +471,35 @@ const (
State_Inactive = "inactive"
State_InProgress = "in progress"
State_InUse = "in-use"
State_NotFound = "Not Found"
State_NotFound = "not found"
State_Pending = "pending"
State_PENDING = "PENDING"
State_PendingReclamation = "pending_reclamation"
State_Provisioning = "provisioning"
State_Removed = "removed"
State_Resize = "resize"
State_RESIZE = "RESIZE"
State_Retry = "retry"
State_Shutoff = "shutoff"
State_Stopping = "stopping"
State_SHUTOFF = "SHUTOFF"
State_Up = "up"
State_VerifyResize = "verify_resize"
Status_Active = "ACTIVE"
Status_Deleting = "deleting"
Status_Error = "ERROR"
Status_Pending = "PENDING"
Status_Shutoff = "SHUTOFF"

// TODO: Second Half Cleanup, remove extra variables

// SAP Profile
PISAPProfiles = "profiles"
PISAPProfileCertified = "certified"
PISAPProfileCores = "cores"
PISAPProfileMemory = "memory"
PISAPProfileID = "profile_id"
PISAPProfileType = "type"

//Added timeout values for warning and active status
warningTimeOut = 60 * time.Second
activeTimeOut = 2 * time.Minute
// Timeout values
Timeout_Active = 2 * time.Minute
Timeout_Delay = 60 * time.Second
Timeout_Warning = 60 * time.Second

PIConsoleLanguageCode = "pi_language_code"
PICloudConnectionId = "cloud_connection_id"
PICloudConnectionStatus = "status"
PICloudConnectionIBMIPAddress = "ibm_ip_address"
PICloudConnectionUserIPAddress = "user_ip_address"
PICloudConnectionPort = "port"
PICloudConnectionClassicGreSource = "gre_source_address"
PICloudConnectionConnectionMode = "connection_mode"
PIInstanceDeploymentType = "pi_deployment_type"
PIInstanceMigratable = "pi_migratable"
PIInstanceNetwork = "pi_network"
PIInstanceStoragePool = "pi_storage_pool"
PIInstanceStorageType = "pi_storage_type"
PISAPInstanceProfileID = "pi_sap_profile_id"
PISAPInstanceDeploymentType = "pi_sap_deployment_type"
PIInstanceSharedProcessorPool = "pi_shared_processor_pool"
PIInstanceStorageConnection = "pi_storage_connection"
PIInstanceStoragePoolAffinity = "pi_storage_pool_affinity"

PIInstanceUserData = "pi_user_data"
PIInstanceVolumeIds = "pi_volume_ids"

// Placement Group
PIPlacementGroupID = "placement_group_id"
PIPlacementGroupMembers = "members"
// TODO: Second Half Cleanup, remove extra variables

// Volume
PIVolumeIds = "pi_volume_ids"
PIAffinityPolicy = "pi_affinity_policy"
PIAffinityVolume = "pi_affinity_volume"
PIAffinityInstance = "pi_affinity_instance"
PIAntiAffinityInstances = "pi_anti_affinity_instances"
PIAntiAffinityVolumes = "pi_anti_affinity_volumes"
PIConsoleLanguageCode = "pi_language_code"
PIInstanceMigratable = "pi_migratable"

// Volume Clone
PIVolumeCloneName = "pi_volume_clone_name"
Expand All @@ -528,18 +509,12 @@ const (
// IBM PI Volume Group
PIVolumeGroupName = "pi_volume_group_name"
PIVolumeGroupConsistencyGroupName = "pi_consistency_group_name"
PIVolumeGroupID = "pi_volume_group_id"
PIVolumeGroupAction = "pi_volume_group_action"
PIVolumeOnboardingID = "pi_volume_onboarding_id"

// Disaster Recovery Location
PIDRLocation = "location"

// VPN
PIVPNConnectionId = "connection_id"
PIVPNConnectionStatus = "connection_status"
PIVPNConnectionDeadPeerDetection = "dead_peer_detections"
PIVPNConnectionDeadPeerDetectionAction = "action"
PIVPNConnectionDeadPeerDetectionInterval = "interval"
PIVPNConnectionDeadPeerDetectionThreshold = "threshold"
PIVPNConnectionLocalGatewayAddress = "local_gateway_address"
Expand All @@ -553,5 +528,4 @@ const (
PIWorkspaceDatacenter = "pi_datacenter"
PIWorkspaceResourceGroup = "pi_resource_group_id"
PIWorkspacePlan = "pi_plan"
PIVirtualOpticalDevice = "pi_virtual_optical_device"
)
4 changes: 2 additions & 2 deletions ibm/service/power/resource_ibm_pi_cloud_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func ResourceIBMPICloudConnection() *schema.Resource {
Computed: true,
Description: "Cloud connection ID",
},
PICloudConnectionStatus: {
Attr_Status: {
Type: schema.TypeString,
Computed: true,
Description: "Link status",
Expand Down Expand Up @@ -443,7 +443,7 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat
d.Set(helpers.PICloudConnectionMetered, cloudConnection.Metered)
d.Set(PICloudConnectionIBMIPAddress, cloudConnection.IbmIPAddress)
d.Set(PICloudConnectionUserIPAddress, cloudConnection.UserIPAddress)
d.Set(PICloudConnectionStatus, cloudConnection.LinkStatus)
d.Set(Attr_Status, cloudConnection.LinkStatus)
d.Set(PICloudConnectionPort, cloudConnection.Port)
d.Set(helpers.PICloudConnectionSpeed, cloudConnection.Speed)
d.Set(helpers.PICloudInstanceId, cloudInstanceID)
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/resource_ibm_pi_dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/IBM-Cloud/power-go-client/clients/instance"
Expand Down Expand Up @@ -272,7 +273,7 @@ func waitForIBMPIDhcpStatus(ctx context.Context, client *instance.IBMPIDhcpClien
log.Printf("[DEBUG] get DHCP failed %v", err)
return nil, "", err
}
if *dhcpServer.Status != State_Active {
if strings.ToLower(*dhcpServer.Status) != State_Active {
return dhcpServer, State_Building, nil
}
return dhcpServer, State_Active, nil
Expand Down
Loading

0 comments on commit 045433e

Please sign in to comment.