Class: Hpe3parSdk::VlunManager

Inherits:
Object
  • Object
show all
Defined in:
lib/Hpe3parSdk/vlun_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(http, vlun_query_supported = false) ⇒ VlunManager

Returns a new instance of VlunManager.



17
18
19
20
# File 'lib/Hpe3parSdk/vlun_manager.rb', line 17

def initialize(http, vlun_query_supported = false)
  @http = http
  @vlun_query_supported = vlun_query_supported
end

Instance Method Details

#create_vlun(volume_name, host_name, lun, port_pos, no_vcn, override_lower_priority, auto) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/Hpe3parSdk/vlun_manager.rb', line 22

def create_vlun(volume_name, host_name, lun, port_pos, no_vcn, override_lower_priority, auto)
  info = {}
  info['volumeName'] = volume_name
  info['lun'] = lun unless lun.nil?
  info['hostname'] = host_name if host_name
  info['portPos'] = port_pos if port_pos
  info['noVcn'] = no_vcn if no_vcn
  if override_lower_priority
    info['overrideLowerPriority'] = override_lower_priority
  end
  if auto
    info['autoLun'] = true
    info['maxAutoLun'] = 0
    info['lun'] = 0
  end
  response = @http.post('/vluns', body: info)
  if response[0]
    location = response[0]['location'].gsub!('/api/v1/vluns/', '')
    return location
  else
    return nil
  end
end

#delete_vlun(volume_name, lun_id, host_name, port) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/Hpe3parSdk/vlun_manager.rb', line 75

def delete_vlun(volume_name, lun_id, host_name, port)
  vlun = "#{volume_name},#{lun_id}"
  vlun += ",#{host_name}" if host_name
  if port
    vlun += "," if host_name.nil?
    vlun += ",#{port[:node]}:#{port[:slot]}:#{port[:cardPort]}"
  end
  response, body = @http.delete("/vluns/#{vlun}")
end

#get_vlun(volume_name) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/Hpe3parSdk/vlun_manager.rb', line 94

def get_vlun(volume_name)
  # This condition if true is untested
  if volume_name.nil? || volume_name.strip.empty?
    raise HPE3PARException.new(nil, "Invalid volume name #{volume_name}")
  end
  if @vlun_query_supported
    query = %("volumeName EQ #{volume_name}")
    response, body = @http.get("/vluns?query=#{query}")
    # Return the first VLUN found for the volume.
    if body.key?('members') && !body['members'].empty?
      return VLUN.new(body['members'][0])
    else
      raise HTTPNotFound.new(nil, "No VLUNs for volumeName #{volume_name} found", nil, 404)
    end
  else
    vluns = get_vluns
    if vluns
      vluns.each do |vlun|
        return vlun if vlun.volume_name == volume_name
      end
    end
    raise HTTPNotFound.new(nil, 'Vlun doesnt exist', nil, 404)
  end
end

#get_vlunsObject



85
86
87
88
89
90
91
92
# File 'lib/Hpe3parSdk/vlun_manager.rb', line 85

def get_vluns
  response = @http.get('/vluns')
  vluns_list=[]
  response[1]['members'].each do |vlun_member|
    vluns_list.push(VLUN.new(vlun_member))
   end
  vluns_list
end

#vlun_exists?(volume_name, lunid, hostname, port) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/Hpe3parSdk/vlun_manager.rb', line 46

def vlun_exists?(volume_name, lunid, hostname, port)
  begin 
    vlun_id = ''
    if volume_name
      vlun_id = volume_name
    end
    if lunid
      vlun_id = vlun_id + ",#{lunid}"
    end
    if hostname
      vlun_id = vlun_id + ',' + hostname
    end
    if port
      if hostname.nil?
        vlun_id = vlun_id + ","
      end
      vlun_id = vlun_id + ',' + "#{port[:node].to_s}:#{port[:slot].to_s}:#{port[:cardPort].to_s}"
    end      
    if (volume_name.nil? or volume_name.empty?) or lunid.nil? and (hostname.nil? or port.nil?)
      raise HPE3PARException.new(nil, "Some or all parameters are missing : volume_name, lunid, hostname or port")
    end
   
    @http.get("/vluns/#{vlun_id}")
    return true
  rescue Hpe3parSdk::HTTPNotFound => ex
   return false
   end
end