class IBM::Cloud::SDK::PowerIaas

Attributes

crn[R]
guid[R]
region[R]
tenant[R]
token[R]

Public Class Methods

new(region, guid, token, crn, tenant) click to toggle source

Create an API Client object for the Power IaaS service

@param region [String] the IBM Power Cloud instance region @param guid [String] the IBM Power Cloud instance GUID @param token [IAMtoken] the IBM Cloud IAM Token object @param crn [String] the IBM Power Cloud instance CRN @param tenant [String] the IBM Power Cloud account ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 16
def initialize(region, guid, token, crn, tenant)
  @crn    = crn
  @guid   = guid
  @region = region
  @token  = token
  @tenant = tenant
  RestClient.log = logger
end

Public Instance Methods

attach_volume(pvm_instance_id, volume_id) click to toggle source

Attach a volume

@param pvm_instance_id [String] PVM Instance ID @param volume_id [String] Volume ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 212
def attach_volume(pvm_instance_id, volume_id)
  post("cloud-instances/#{guid}/pvm-instances/#{pvm_instance_id}/volumes/#{volume_id}", {})
end
create_key_pair(name, sshkey) click to toggle source

Add a new SSH key to the tenant

@param name [String] User defined name for the SSH key @param sshkey [String] SSH RSA key @return [Hash] SSHKey

# File lib/ibm/cloud/sdk/power_iaas.rb, line 293
def create_key_pair(name, sshkey)
  payload = {"name" => name, "sshkey" => sshkey}
  post("tenants/#{tenant}/sshkeys", payload.to_json)
end
create_network(network_hash) click to toggle source

Create a new network

@param network_hash [Hash] New network attributes @return [Hash] Network

# File lib/ibm/cloud/sdk/power_iaas.rb, line 262
def create_network(network_hash)
  post("cloud-instances/#{guid}/networks", network_hash.to_json)
end
create_pvm_instance(instance_hash) click to toggle source

Create a new PVM instance

@param instance_hash [Hash] New instance attributes @return [Hash] PVMInstance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 135
def create_pvm_instance(instance_hash)
  post("cloud-instances/#{guid}/pvm-instances", instance_hash.to_json)
end
create_sap_pvm_instance(instance_hash) click to toggle source

Create a new SAP PVM Instance

Create a new PVM instance using an SAP profile. The resultant PVM instance is the standard 'PVMInstance' type and can be accessed via the existing *_pvm_instance methods.

@param sap_profile_id [String] SAP Profile ID @return [Hash] SAP profile

# File lib/ibm/cloud/sdk/power_iaas.rb, line 332
def create_sap_pvm_instance(instance_hash)
  post("cloud-instances/#{guid}/sap", instance_hash.to_json)
end
create_volume(volume_hash) click to toggle source

Create a volume

@param volume_hash [Hash] New volume attributes @return [Hash] Volume

# File lib/ibm/cloud/sdk/power_iaas.rb, line 204
def create_volume(volume_hash)
  post("cloud-instances/#{guid}/volumes", volume_hash.to_json)
end
delete_image(image_id) click to toggle source

Delete an image from a cloud instance

@param image_id [String] Image ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 170
def delete_image(image_id)
  delete("cloud-instances/#{guid}/images/#{image_id}")
end
delete_key_pair(name) click to toggle source

Delete SSH key from the tenant

@param sshkey_name [String] SSH Key name

# File lib/ibm/cloud/sdk/power_iaas.rb, line 301
def delete_key_pair(name)
  delete("tenants/#{tenant}/sshkeys/#{name}")
end
delete_network(network_id) click to toggle source

Delete a network

@param network_id [String] Network ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 269
def delete_network(network_id)
  delete("cloud-instances/#{guid}/networks/#{network_id}")
end
delete_pvm_instance(instance_id) click to toggle source

Delete a PVM instance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 142
def delete_pvm_instance(instance_id)
  delete("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
end
delete_volume(volume_id) click to toggle source

Delete a volume

@param volume_id [String] Volume ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 196
def delete_volume(volume_id)
  delete("cloud-instances/#{guid}/volumes/#{volume_id}")
end
detach_volume(pvm_instance_id, volume_id) click to toggle source

Detach a volume

@param pvm_instance_id [String] PVM Instance ID @param volume_id [String] Volume ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 220
def detach_volume(pvm_instance_id, volume_id)
  delete("cloud-instances/#{guid}/pvm-instances/#{pvm_instance_id}/volumes/#{volume_id}")
end
endpoint() click to toggle source

Get the API service Endpoint URL

@return [String] Endpoint URL

# File lib/ibm/cloud/sdk/power_iaas.rb, line 28
def endpoint
  "https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/pcloud/v1"
end
get_image(image_id) click to toggle source

Get an IBM Power Cloud image

@param image_id [String] Image ID @return [Hash] Image

# File lib/ibm/cloud/sdk/power_iaas.rb, line 161
def get_image(image_id)
  get("cloud-instances/#{guid}/images/#{image_id}")
rescue
  nil
end
get_images() click to toggle source

Get all images in an IBM Power Cloud instance

@return [Array<Hash>] all Images for this instance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 149
def get_images
  images = get("cloud-instances/#{guid}/images")["images"] || []

  images.map do |image|
    get_image(image["imageID"])
  end.compact
end
get_network(network_id) click to toggle source

Get an IBM Power Cloud network

@param network_id [String] Network ID @return [Hash] Network

# File lib/ibm/cloud/sdk/power_iaas.rb, line 238
def get_network(network_id)
  get("cloud-instances/#{guid}/networks/#{network_id}")
end
get_network_ports(network_id) click to toggle source

Get all ports for a network

@param network_id [String] Network ID @return [Array<Hash>] NetworkPort

# File lib/ibm/cloud/sdk/power_iaas.rb, line 277
def get_network_ports(network_id)
  get("cloud-instances/#{guid}/networks/#{network_id}/ports")["ports"]
end
get_networks() click to toggle source

Get all networks in an IBM Power Cloud instance

@return [Array<Hash>] all networks for this IBM Power Cloud instance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 227
def get_networks
  networks = get("cloud-instances/#{guid}/networks")["networks"] || []
  networks.map do |network|
    get_network(network["networkID"])
  end
end
get_pcloud_instance() click to toggle source

Get Power Cloud Instance information

@return [Hash] CloudInstance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 35
def get_pcloud_instance
  get("cloud-instances/#{guid}")
end
get_pvm_instance(instance_id) click to toggle source

Get an IBM Power Cloud PVM instance

@param pvm_instance_id [String] PVM instance ID @return [Hash] PVM Instances

# File lib/ibm/cloud/sdk/power_iaas.rb, line 54
def get_pvm_instance(instance_id)
  get("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
end
get_pvm_instances() click to toggle source

Get all PVM instances in an IBM Power Cloud instance

@return [Array<Hash>] all PVM Instances for this instance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 42
def get_pvm_instances
  pvm_instances = get("cloud-instances/#{guid}/pvm-instances")["pvmInstances"] || []

  pvm_instances.map do |pvm_instance|
    get_pvm_instance(pvm_instance["pvmInstanceID"])
  end
end
get_sap_profile(sap_profile_id) click to toggle source

Get an SAP profile

@param sap_profile_id [String] SAP Profile ID @return [Hash] SAP profile

# File lib/ibm/cloud/sdk/power_iaas.rb, line 309
def get_sap_profile(sap_profile_id)
  get("cloud-instances/#{guid}/sap/#{sap_profile_id}")
end
get_sap_profiles() click to toggle source

Get list of all SAP profiles

@return [Array<Hash>] all SAP profiles available to this instance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 316
def get_sap_profiles
  sap_profiles = get("cloud-instances/#{guid}/sap")["profiles"] || []

  sap_profiles.map do |sap_profile|
    get_sap_profile(sap_profile["profileID"])
  end
end
get_ssh_keys() click to toggle source

List the tenant's SSH Keys

@return [Array<Hash>] SSHKey

# File lib/ibm/cloud/sdk/power_iaas.rb, line 284
def get_ssh_keys
  get("tenants/#{tenant}")["sshKeys"]
end
get_storage_types() click to toggle source

Get a storage types list in IBM Power Cloud. note: this method to be refactored under the common IBM::Cloud::SDK::PowerIaas.endpoint when the rest api become available.

@return [Array<Hash>] StorageType

# File lib/ibm/cloud/sdk/power_iaas.rb, line 254
def get_storage_types
  JSON.parse(RestClient.get("https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/broker/v1/storage-types", headers))[region]
end
get_system_pool() click to toggle source

Get a available system pools list for IBM Power Cloud DC

@return [Hash] SystemPool

# File lib/ibm/cloud/sdk/power_iaas.rb, line 245
def get_system_pool
  get("cloud-instances/#{guid}/system-pools")
end
get_volume(volume_id) click to toggle source

Get a specific volume

@param volume_id [String] Image ID @return [Hash] Volume

# File lib/ibm/cloud/sdk/power_iaas.rb, line 189
def get_volume(volume_id)
  get("cloud-instances/#{guid}/volumes/#{volume_id}")
end
get_volumes() click to toggle source

List all the volumes.

@return [Array<Hash>] all volumes for this instance

# File lib/ibm/cloud/sdk/power_iaas.rb, line 177
def get_volumes
  volumes = get("cloud-instances/#{guid}/volumes")["volumes"] || []

  volumes.map do |volume|
    get_volume(volume["volumeID"])
  end
end
hard_reboot_pvm_instance(instance_id) click to toggle source

Perform 'hard-reboot' action on a PVMInstance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 114
def hard_reboot_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "hard-reboot"}.to_json
  )
end
immediate_shutdown_pvm_instance(instance_id) click to toggle source

Perform 'immediate-shutdown' action on a PVMInstance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 81
def immediate_shutdown_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "immediate-shutdown"}.to_json
  )
end
reboot_pvm_instance(instance_id) click to toggle source

Perform 'reboot' action on a PVMInstance

This action has been deprecated and replaced by 'soft-reboot' and 'hard-reboot'

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 94
def reboot_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "reboot"}.to_json
  )
end
reset_state_pvm_instance(instance_id) click to toggle source

Perform 'reset-state' action on a PVMInstance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 124
def reset_state_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "reset-state"}.to_json
  )
end
soft_reboot_pvm_instance(instance_id) click to toggle source

Perform 'soft-reboot' action on a PVMInstance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 104
def soft_reboot_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "soft-reboot"}.to_json
  )
end
start_pvm_instance(instance_id) click to toggle source

Perform 'start' action on a PVMInstance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 61
def start_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "start"}.to_json
  )
end
stop_pvm_instance(instance_id) click to toggle source

Perform 'stop' action on a PVMInstance

@param pvm_instance_id [String] PVM instance ID

# File lib/ibm/cloud/sdk/power_iaas.rb, line 71
def stop_pvm_instance(instance_id)
  post(
    "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
    {"action" => "stop"}.to_json
  )
end

Private Instance Methods

headers() click to toggle source
# File lib/ibm/cloud/sdk/power_iaas.rb, line 340
def headers
  {
    'Authorization' => token.authorization_header,
    'CRN'           => crn,
    'Content-Type'  => 'application/json'
  }
end