class Hpe3parSdk::VolumeManager

Public Class Methods

new(http, ssh, app_type) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 22
def initialize(http, ssh, app_type)
  @http = http
  @ssh = ssh
  @task = TaskManager.new(http)
  @volume_set = VolumeSetManager.new(http)
  @app_type = app_type
end

Public Instance Methods

_find_task(name, active=false) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 173
def _find_task(name, active=false) 
  cmd = ['showtask']
  if active
    cmd.push('-active')
  end
  cmd.push(name)
  command = cmd.join(" ")
  
  result = @ssh.run(command).split("\n")
  if result[0].gsub("\n",'') =='No tasks.'
    return nil
  end
  result
end
_sync_physical_copy(volume_name, action) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 192
def _sync_physical_copy(volume_name, action)
  info = { 'action' => action }
  response = @http.put("/volumes/#{volume_name}", body: info)
  response[1]
end
create_physical_copy(src_name, dest_name, dest_cpg, optional = nil) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 122
def create_physical_copy(src_name, dest_name, dest_cpg, optional = nil)
  parameters = { :destVolume => dest_name, :destCPG => dest_cpg }
  parameters = Util.merge_hash(parameters, optional) if optional

  
  if !parameters.key?(:online) || !((parameters[:online]))
    # 3Par won't allow destCPG to be set if it's not an online copy.
    parameters.delete(:destCPG)
  end
  
  info = { :action => 'createPhysicalCopy', :parameters => parameters }

  response = @http.post("/volumes/#{src_name}", body: info)
  response[1]
end
create_snapshot(name, copy_of_name, optional = nil) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 219
def create_snapshot(name, copy_of_name, optional = nil)
  parameters = { 'name' => name }
  parameters = Util.merge_hash(parameters, optional) if optional
  info = { 'action' => 'createSnapshot',
           'parameters' => parameters }

  response = @http.post("/volumes/#{copy_of_name}", body: info)
  response[1]
end
create_volume(name, cpg_name, size_mib, optional = nil) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 56
def create_volume(name, cpg_name, size_mib, optional = nil)
  info = { 'name' => name, 
           'cpg' => cpg_name, 
           'sizeMiB' => size_mib, 
           #Adding information related to telemetry
           'objectKeyValues' => [ 
             { 
               'key' => 'type' , 
               'value' => @app_type 
             } 
           ] 
         }
  
  info = Util.merge_hash(info, optional) if optional
  volumes_url = '/volumes'
  @http.post(volumes_url, body: info)
end
delete_volume(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 92
def delete_volume(name)
  begin
    remove_volume_metadata(name, 'type')
  rescue; end

  response = @http.delete("/volumes/#{name}")
  response[1]
end
get_online_physical_copy_status(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 198
def get_online_physical_copy_status(name)
  status = nil
  tasks = @task.get_all_tasks
  tasks.each do |task|
    status = task['status'] if task['name'] == name &&
                               task['type'] == TaskType::ONLINE_COPY
  end
  raise HPE3PARException.new(nil, 'Volume not an online physical copy') if status.nil?
  status
end
get_volume(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 39
def get_volume(name)
  if name.nil? || name.strip.empty?
    raise 'Volume name cannot be nil or empty'
  else
    VirtualVolume.new(@http.get("/volumes/#{name}")[1])
  end
end
get_volume_by_wwn(wwn) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 47
def get_volume_by_wwn(wwn)
  response = @http.get("/volumes?query=\"wwn EQ #{wwn}\"")
  if response[1].key?('members') && !response[1]['members'].empty?
    return VirtualVolume.new(response[1]['members'][0])
  else
    raise HTTPNotFound.new(nil, "Volume with WWN #{wwn} does not exist", nil, 404)
  end
end
get_volume_snapshot_names(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 74
def get_volume_snapshot_names(name)
  snapshots = []
  headers, body = @http.get("/volumes?query=\"copyOf EQ #{name}\"")
  for member in body['members']
    snapshots.push(member['name'])
  end
  snapshots
end
get_volume_snapshots(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 83
def get_volume_snapshots(name)
  response = @http.get("/volumes?query=\"copyOf EQ #{name}\"")
  volume_snapshots = []
  response[1]['members'].each do |snapshot|
    volume_snapshots.push(VirtualVolume.new(snapshot))
  end
  volume_snapshots
end
get_volumes(volume_type) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 30
def get_volumes(volume_type)
  volumes = Array[]
  response = @http.get('/volumes')
  response[1]['members'].each do |member|
    volumes.push(VirtualVolume.new(member)) if member['copyType'] == volume_type
  end
  volumes
end
grow_volume(name, amount) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 116
def grow_volume(name, amount)
  info = { 'action' => VolumeCustomAction::GROW_VOLUME, 'sizeMiB' => amount }
  response = @http.put("/volumes/#{name}", body: info)
  response[1]
end
is_online_physical_copy(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 142
def is_online_physical_copy(name)
  task = _find_task(name, active=true)
  if task.nil?
    false
  else
    true
  end
end
modify_volume(name, volume_mods) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 108
def modify_volume(name, volume_mods)
  @http.put("/volumes/#{name}", body: volume_mods)
  if volume_mods.key? ('newName') && !volume_mods['newName'].nil?
    name = volume_mods['newName']
  end
  setVolumeMetaData(name, 'type', @app_type)     
end
offline_physical_copy_exists?(src_name, phy_copy_name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 291
def offline_physical_copy_exists?(src_name, phy_copy_name)
  begin
    if volume_exists?(src_name) and volume_exists?(phy_copy_name) and !_find_task(src_name + "->" + phy_copy_name,true).nil?
       return true
    else
       return false 
    end
  rescue Hpe3parSdk::HTTPNotFound => ex
    return false
  end
end
online_physical_copy_exists?(src_name, phy_copy_name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 279
def online_physical_copy_exists?(src_name, phy_copy_name)
  begin
    if volume_exists?(src_name) and volume_exists?(phy_copy_name) and !_find_task(phy_copy_name,true).nil?
      return true
    else
      return false 
    end
  rescue Hpe3parSdk::HTTPNotFound => ex
    return false
  end
end
remove_volume_metadata(name, key) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 101
def remove_volume_metadata(name, key)
  response = @http.delete(
        "/volumes/#{name}/objectKeyValues/#{key}"
        )
  body
end
restore_snapshot(name, optional = nil) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 229
def restore_snapshot(name, optional = nil)
  info = { 'action' => VolumeCustomAction::PROMOTE_VIRTUAL_COPY }
  info = Util.merge_hash(info, optional) if optional

  response = @http.put("/volumes/#{name}", body: info)
  response[1]
end
resync_physical_copy(volume_name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 188
def resync_physical_copy(volume_name)
  _sync_physical_copy(volume_name, VolumeCustomAction::RESYNC_PHYSICAL_COPY)
end
setVolumeMetaData(name, key, value) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 237
def setVolumeMetaData(name, key, value)
  key_exists = false
  info = {
      'key' => key,
      'value' => value
  }
  
  begin
    response = @http.post("/volumes/#{name}/objectKeyValues", body: info)
  rescue  Hpe3parSdk::HTTPConflict => ex
    key_exists = true
  rescue
  end
  
  if key_exists
    info = {
        'value' => value
    }
    begin
      response = @http.put("/volumes/#{name}/objectKeyValues/#{key}", body: info)
    rescue; end
  end
end
stop_offline_physical_copy(volume_name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 138
def stop_offline_physical_copy(volume_name)
  _sync_physical_copy(volume_name, VolumeCustomAction::STOP_PHYSICAL_COPY)
end
stop_online_physical_copy(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 151
def stop_online_physical_copy(name)
  task = _find_task(name, active=false)
  unless task.nil?
    task_id = task[0].split(",")[0]
    unless task_id.nil?
      cmd = ['canceltask', '-f', task_id]
      command = cmd.join(" ")
      result = @ssh.run(command)
      unless result.include? "is not active"        
        ready = false
        while ready == false
          sleep(1)
          task = _find_task(name, false)
          if task.nil?
            ready = true
          end
        end
      end
    end
  end
end
tune_volume(name, tune_operation, optional = nil) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 209
def tune_volume(name, tune_operation, optional = nil)
  info = { 'action' => VolumeCustomAction::TUNE_VOLUME,
           'tuneOperation' => tune_operation }
  info = Util.merge_hash(info, optional) if optional
  response = @http.put("/volumes/#{name}", body: info)
  response[1]
end
volume_exists?(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 261
def volume_exists?(name)
  begin
    get_volume(name)
    return true
  rescue Hpe3parSdk::HTTPNotFound => ex
    return false
  end
end
volume_set_exists?(name) click to toggle source
# File lib/Hpe3parSdk/volume_manager.rb, line 270
def volume_set_exists?(name)
  begin
    get_volume_set(name)
    return true
  rescue Hpe3parSdk::HTTPNotFound => ex
    return false
  end
end