Class: ResourceRole
- Inherits:
-
Object
- Object
- ResourceRole
- Defined in:
- lib/HMC/ResourceRole.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #decode(string) ⇒ Object
- #has_all_lpars?(type_model_serial) ⇒ Boolean
- #has_all_partitions?(type_model_serial) ⇒ Boolean
- #has_lpar?(type_model_serial, lpar_id) ⇒ Boolean
-
#initialize(string = '') ⇒ ResourceRole
constructor
name=L2support,“resources=cec:root/ibmhscS1_0|9131-52A*6535CCG|IBMHSC_ComputerSystem,lpar:root/ibmhscS1_0|ALL_PARTITIONS*9131-52A*6535CCG|IBMHSC_Partition”.
Constructor Details
#initialize(string = '') ⇒ ResourceRole
name=L2support,“resources=cec:root/ibmhscS1_0|9131-52A*6535CCG|IBMHSC_ComputerSystem,lpar:root/ibmhscS1_0|ALL_PARTITIONS*9131-52A*6535CCG|IBMHSC_Partition”
13 14 15 16 17 |
# File 'lib/HMC/ResourceRole.rb', line 13 def initialize(string='') @resources = [] decode(string) unless string.empty? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/HMC/ResourceRole.rb', line 9 def name @name end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
10 11 12 |
# File 'lib/HMC/ResourceRole.rb', line 10 def resources @resources end |
Instance Method Details
#decode(string) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/HMC/ResourceRole.rb', line 19 def decode(string) raise 'new line character in string' if string.include?("\n") if match = /^name=([\w\-\_]+),"resources=(.*?)"$/.match(string) @name = match[1] match[2].split(',').each do |resource| @resources.push(Resource.new(resource)) end elsif match = /^name=([\w\-\_]+),resources=$/.match(string) @name = match[1] elsif match = /^name=([\w\-\_]+),resources=(.*?)$/.match(string) @name = match[1] match[2].split(',').each do |resource| @resources.push(Resource.new(resource)) end else puts string puts "regexp couldn't decode string" raise end end |
#has_all_lpars?(type_model_serial) ⇒ Boolean
66 67 68 69 70 71 72 73 |
# File 'lib/HMC/ResourceRole.rb', line 66 def has_all_lpars?(type_model_serial) @resources.each do |resource| if resource.type == 'lpar' return true if resource.frame == type_model_serial && resource.lpar == 'ALL_PARTITIONS' end end false end |
#has_all_partitions?(type_model_serial) ⇒ Boolean
43 44 45 46 47 48 49 50 |
# File 'lib/HMC/ResourceRole.rb', line 43 def has_all_partitions?(type_model_serial) @resources.each { |resource| if resource.type == 'lpar' return true if resource.frame == type_model_serial && resource.lpar == 'ALL_PARTITIONS' end } false end |
#has_lpar?(type_model_serial, lpar_id) ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/HMC/ResourceRole.rb', line 52 def has_lpar?(type_model_serial, lpar_id) @resources.each do |resource| if resource.type == 'lpar' if resource.frame == type_model_serial && resource.lpar == 'ALL_PARTITIONS' return true end return true if resource.frame == type_model_serial && resource.lpar == lpar_id.to_s end end false end |