Skip to content

Commit

Permalink
Merge pull request IBM-Cloud#5384 from IBM-Cloud/refactor-instance-ac…
Browse files Browse the repository at this point in the history
…tion

Refactor PI Instance Action
  • Loading branch information
yussufsh authored Jul 15, 2024
2 parents 2a53ac3 + a1ec7d6 commit 51a25b2
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 112 deletions.
129 changes: 129 additions & 0 deletions go.sum

Large diffs are not rendered by default.

87 changes: 66 additions & 21 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "time"

const (
// Arguments
Arg_Action = "pi_action"
Arg_AffinityInstance = "pi_affinity_instance"
Arg_AffinityPolicy = "pi_affinity_policy"
Arg_AffinityVolume = "pi_affinity_volume"
Expand All @@ -14,42 +15,58 @@ const (
Arg_Datacenter = "pi_datacenter"
Arg_DatacenterZone = "pi_datacenter_zone"
Arg_DeploymentTarget = "pi_deployment_target"
Arg_DeploymentType = "pi_deployment_type"
Arg_Description = "pi_description"
Arg_DhcpCidr = "pi_cidr"
Arg_DhcpCloudConnectionID = "pi_cloud_connection_id"
Arg_DhcpDnsServer = "pi_dns_server"
Arg_DhcpID = "pi_dhcp_id"
Arg_DhcpName = "pi_dhcp_name"
Arg_DhcpSnatEnabled = "pi_dhcp_snat_enabled"
Arg_HealthStatus = "pi_health_status"
Arg_Host = "pi_host"
Arg_HostGroupID = "pi_host_group_id"
Arg_HostID = "pi_host_id"
Arg_Hosts = "pi_hosts"
Arg_IBMiCSS = "pi_ibmi_css"
Arg_IBMiPHA = "pi_ibmi_pha"
Arg_IBMiRDSUsers = "pi_ibmi_rds_users"
Arg_ImageID = "pi_image_id"
Arg_ImageImportDetails = "pi_image_import_details"
Arg_ImageName = "pi_image_name"
Arg_InstanceID = "pi_instance_id"
Arg_InstanceName = "pi_instance_name"
Arg_Key = "pi_ssh_key"
Arg_KeyName = "pi_key_name"
Arg_KeyPairName = "pi_key_pair_name"
Arg_LanguageCode = "pi_language_code"
Arg_LicenseRepositoryCapacity = "pi_license_repository_capacity"
Arg_Memory = "pi_memory"
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"
Arg_PlacementGroupPolicy = "pi_placement_group_policy"
Arg_Plan = "pi_plan"
Arg_Processors = "pi_processors"
Arg_ProcType = "pi_proc_type"
Arg_PVMInstanceActionType = "pi_action"
Arg_PVMInstanceHealthStatus = "pi_health_status"
Arg_PVMInstanceId = "pi_instance_id"
Arg_Remove = "pi_remove"
Arg_Replicants = "pi_replicants"
Arg_ReplicationEnabled = "pi_replication_enabled"
Arg_ReplicationPolicy = "pi_replication_policy"
Arg_ReplicationScheme = "pi_replication_scheme"
Arg_ResourceGroupID = "pi_resource_group_id"
Arg_SAP = "sap"
Arg_SAPDeploymentType = "pi_sap_deployment_type"
Arg_SAPProfileID = "pi_sap_profile_id"
Arg_Secondaries = "pi_secondaries"
Arg_SharedProcessorPool = "pi_shared_processor_pool"
Arg_SharedProcessorPoolHostGroup = "pi_shared_processor_pool_host_group"
Arg_SharedProcessorPoolID = "pi_shared_processor_pool_id"
Arg_SharedProcessorPoolName = "pi_shared_processor_pool_name"
Expand All @@ -61,8 +78,14 @@ const (
Arg_SPPPlacementGroupName = "pi_spp_placement_group_name"
Arg_SPPPlacementGroupPolicy = "pi_spp_placement_group_policy"
Arg_SSHKey = "pi_ssh_key"
Arg_StorageConnection = "pi_storage_connection"
Arg_StoragePool = "pi_storage_pool"
Arg_StoragePoolAffinity = "pi_storage_pool_affinity"
Arg_StorageType = "pi_storage_type"
Arg_SysType = "pi_sys_type"
Arg_UserData = "pi_user_data"
Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned"
Arg_VirtualOpticalDevice = "pi_virtual_optical_device"
Arg_VolumeGroupID = "pi_volume_group_id"
Arg_VolumeID = "pi_volume_id"
Arg_VolumeIDs = "pi_volume_ids"
Expand Down Expand Up @@ -367,24 +390,47 @@ const (
Attr_WWN = "wwn"

// OS Type
OS_IBMI = "ibmi"
OS_IBMI = "ibmi"
StockVTL = "stock-vtl"

// Allowed Values
Affinity = "affinity"
AntiAffinity = "anti-affinity"
BYOL = "byol"
Hana = "Hana"
Host = "host"
HostGroup = "hostGroup"
Netweaver = "Netweaver"
Private = "private"
Public = "public"
SAP = "SAP"
Affinity = "affinity"
AntiAffinity = "anti-affinity"
Attach = "attach"
BYOL = "byol"
Capped = "capped"
Critical = "CRITICAL"
CUSTOM_VIRTUAL_CORES = "custom-virtualcores"
Dedicated = "dedicated"
DeploymentTypeEpic = "EPIC"
DeploymentTypeVMNoStorage = "VMNoStorage"
Hana = "Hana"
Hard = "hard"
Host = "host"
HostGroup = "hostGroup"
Netweaver = "Netweaver"
None = "none"
OK = "OK"
Prefix = "prefix"
Private = "private"
Public = "public"
SAP = "SAP"
Shared = "shared"
Soft = "soft"
Suffix = "suffix"
vSCSI = "vSCSI"
Warning = "WARNING"

// Actions
Action_HardReboot = "hard-reboot"
Action_ImmediateShutdown = "immediate-shutdown"
Action_ResetState = "reset-state"
Action_SoftReboot = "soft-reboot"
Action_Start = "start"
Action_Stop = "stop"

// States
NotFound = "not found"
SctionStart = "start"
SctionStop = "stop"
State_Active = "active"
State_ACTIVE = "ACTIVE"
State_Added = "added"
Expand All @@ -396,27 +442,31 @@ const (
State_Deleting = "deleting"
State_DELETING = "DELETING"
State_Down = "down"
State_Error = "error"
State_Failed = "failed"
State_Inactive = "inactive"
State_InProgress = "in progress"
State_InUse = "in-use"
State_NotFound = "Not Found"
State_Pending = "pending"
State_PendingReclamation = "pending_reclamation"
State_Provisioning = "provisioning"
State_Removed = "removed"
State_Retry = "retry"
State_Shutoff = "shutoff"
State_Up = "up"
Status_Active = "ACTIVE"
Status_Deleting = "deleting"
Status_Error = "ERROR"
Status_Pending = "PENDING"
Status_Shutoff = "SHUTOFF"
StatusActive = "ACTIVE"
StatusBuild = "BUILD"
StatusError = "ERROR"
StatusPending = "PENDING"
StatusResize = "RESIZE"
StatusShutoff = "SHUTOFF"

// Health
Health_OK = "OK"

// TODO: Second Half Cleanup, remove extra variables

// SAP Profile
Expand All @@ -427,14 +477,9 @@ const (
PISAPProfileID = "profile_id"
PISAPProfileType = "type"

PVMInstanceHealthOk = "OK"
PVMInstanceHealthWarning = "WARNING"

//Added timeout values for warning and active status
warningTimeOut = 60 * time.Second
activeTimeOut = 2 * time.Minute
// power service instance capabilities
CUSTOM_VIRTUAL_CORES = "custom-virtualcores"

PIConsoleLanguageCode = "pi_language_code"
PICloudConnectionId = "cloud_connection_id"
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/power/resource_ibm_pi_dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func waitForIBMPIDhcpStatus(ctx context.Context, client *st.IBMPIDhcpClient, dhc
log.Printf("[DEBUG] get DHCP failed %v", err)
return nil, "", err
}
if *dhcpServer.Status != StatusActive {
if *dhcpServer.Status != Status_Active {
return dhcpServer, "building", nil
}
return dhcpServer, "active", nil
Expand Down
10 changes: 5 additions & 5 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,8 @@ func isWaitForPIInstanceShutoff(ctx context.Context, client *st.IBMPIInstanceCli
}

stateConf := &retry.StateChangeConf{
Pending: []string{StatusPending, helpers.PIInstanceBuilding, helpers.PIInstanceHealthWarning},
Target: []string{helpers.PIInstanceHealthOk, StatusError, "", StatusShutoff},
Pending: []string{Status_Pending, helpers.PIInstanceBuilding, helpers.PIInstanceHealthWarning},
Target: []string{helpers.PIInstanceHealthOk, Status_Error, "", Status_Shutoff},
Refresh: isPIInstanceShutoffRefreshFunc(client, id, instanceReadyStatus),
Delay: 30 * time.Second,
MinTimeout: queryTimeOut,
Expand All @@ -1129,10 +1129,10 @@ func isPIInstanceShutoffRefreshFunc(client *st.IBMPIInstanceClient, id, instance
if err != nil {
return nil, "", err
}
if *pvm.Status == StatusShutoff && (pvm.Health.Status == instanceReadyStatus || pvm.Health.Status == helpers.PIInstanceHealthOk) {
return pvm, StatusShutoff, nil
if *pvm.Status == Status_Shutoff && (pvm.Health.Status == instanceReadyStatus || pvm.Health.Status == helpers.PIInstanceHealthOk) {
return pvm, Status_Shutoff, nil
}
if *pvm.Status == StatusError {
if *pvm.Status == Status_Error {
if pvm.Fault != nil {
err = fmt.Errorf("failed to create the lpar: %s", pvm.Fault.Message)
} else {
Expand Down
Loading

0 comments on commit 51a25b2

Please sign in to comment.