xclarity_client 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db726a2cff6799fb0a4b45f3b3f198fb1e6f7b1
4
- data.tar.gz: 87aa0cd3480d190f491f8b7bffa9bb41b7b6290c
3
+ metadata.gz: 5f6fe01d2f0c546424c2b60568dac517bf577fb5
4
+ data.tar.gz: dd4a30bdaccb0a616f8c802d2a258b9126d426d6
5
5
  SHA512:
6
- metadata.gz: 3c97e083577ea734fd44926e5d2d7bf343cb1e17414d2371824b751cea36fde1324a65f50ee247b831d7ee7bb8c4cf85b52009298214c022b4ba872455ec9556
7
- data.tar.gz: 646ebe36c2b47d7cb61a222972f6f23359e39538c2b16f56ee5c79756a6bb23bcc04b67b61abd0a6b15f74743a8b9f4716f8ff0d2c3165e78616d32c8ed8cce2
6
+ metadata.gz: b71782c8a9d1f72ec4e8d4b4001d63305b4dda3830a9df8730028101b03e894965cbde6ed48e5bc06dc93b13141a9c622e746fa10ac4dc418f32fdeca4b13dab
7
+ data.tar.gz: a57f0f9881982d2ebeb7a9c2669cfdc4c08dd859aecbe62c4f3da0cad022f383af60828f4d19a75c29980f19f9b3ebb0692686b0b2ad4263e77321db8e9c577e
@@ -7,6 +7,7 @@ require 'xclarity_client/configuration'
7
7
  require 'xclarity_client/client'
8
8
  require 'xclarity_client/xclarity_base'
9
9
  require 'xclarity_client/xclarity_resource'
10
+ require 'xclarity_client/xclarity_management_mixin'
10
11
  require 'xclarity_client/virtual_appliance_management'
11
12
  require 'xclarity_client/node'
12
13
  require 'xclarity_client/node_management'
@@ -3,6 +3,7 @@ module XClarityClient
3
3
  include XClarityClient::Resource
4
4
 
5
5
  BASE_URI = '/cabinet'.freeze
6
+ LIST_NAME = 'cabinetList'.freeze
6
7
 
7
8
  attr_accessor :cabinetName, :chassisList, :complexList, :height, :location, :nodeList,
8
9
  :placeholderList, :room, :storageList, :switchList, :UUID
@@ -3,57 +3,15 @@ require 'json'
3
3
  module XClarityClient
4
4
  class CabinetManagement < XClarityBase
5
5
 
6
- BASE_URI = '/cabinet'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, Cabinet::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
-
15
- body = JSON.parse(response.body)
16
- body = {'cabinetList' => [body]} unless body.has_key? 'cabinetList'
17
- body['cabinetList'].map do |cabinet|
18
- Cabinet.new cabinet
19
- end
20
- end
21
-
22
- def get_object_cabinet(uuids, includeAttributes, excludeAttributes)
23
-
24
- response = if not includeAttributes.nil?
25
- get_object_cabinet_include_attributes(uuids, includeAttributes)
26
- elsif not excludeAttributes.nil?
27
- get_object_cabinet_exclude_attributes(uuids, excludeAttributes)
28
- elsif not uuids.nil?
29
- connection(BASE_URI + "/" + uuids.join(","))
30
- else
31
- connection(BASE_URI)
32
- end
33
-
34
- body = JSON.parse(response.body)
35
- body = {'cabinetList' => [body]} unless body.has_key? 'cabinetList'
36
- body['cabinetList'].map do |cabinet|
37
- Cabinet.new cabinet
38
- end
39
-
12
+ def population(opts = {})
13
+ get_all_resources(Cabinet, opts)
40
14
  end
41
15
 
42
- def get_object_cabinet_exclude_attributes(uuids, attributes)
43
-
44
- response = if not uuids.nil?
45
- connection(BASE_URI + "/" + uuids.join(",") + "?excludeAttributes="+ attributes.join(","))
46
- else
47
- connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
48
- end
49
- end
50
-
51
- def get_object_cabinet_include_attributes(uuids, attributes)
52
- response = if not uuids.nil?
53
- connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes="+ attributes.join(","))
54
- else
55
- connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
56
- end
57
- end
58
16
  end
59
17
  end
@@ -3,6 +3,7 @@ module XClarityClient
3
3
  include XClarityClient::Resource
4
4
 
5
5
  BASE_URI = '/canisters'.freeze
6
+ LIST_NAME = 'canisterList'.freeze
6
7
 
7
8
  attr_accessor :cmmDisplayName, :backedBy, :contact, :dataHandle, :description,
8
9
  :firmware, :FRU, :domainName, :driveBays, :drives, :errorFields, :ipInterfaces, :powerStatus,
@@ -3,58 +3,15 @@ require 'json'
3
3
  module XClarityClient
4
4
  class CanisterManagement < XClarityBase
5
5
 
6
- BASE_URI = '/canisters'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, Canister::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
-
15
- body = JSON.parse(response.body)
16
- body = {'canisterList' => [body]} unless body.has_key? 'canisterList'
17
- body['canisterList'].map do |canister|
18
- Canister.new canister
19
- end
20
- end
21
-
22
- def get_object_canisters(uuids, includeAttributes, excludeAttributes)
23
-
24
- response = if not includeAttributes.nil?
25
- get_object_canisters_include_attributes(uuids, includeAttributes)
26
- elsif not excludeAttributes.nil?
27
- get_object_canisters_exclude_attributes(uuids, excludeAttributes)
28
- elsif not uuids.nil?
29
- connection(BASE_URI + "/" + uuids)
30
- else
31
- connection(BASE_URI)
32
- end
33
-
34
- body = JSON.parse(response.body)
35
- body = {'canisterList' => [body]} unless body.has_key? 'canisterList'
36
- body['canisterList'].map do |canister|
37
- Canister.new canister
38
- end
39
-
12
+ def population(opts = {})
13
+ get_all_resources(Canister, opts)
40
14
  end
41
15
 
42
- def get_object_canisters_exclude_attributes(uuids, attributes)
43
-
44
- response = if not uuids.nil?
45
- connection(BASE_URI + "/#{uuids}"+"?excludeAttributes=#{attributes.join(",")}")
46
- else
47
- connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
48
- end
49
-
50
- end
51
-
52
- def get_object_canisters_include_attributes(uuids, attributes)
53
- response = if not uuids.nil?
54
- connection(BASE_URI + "/" + uuids + "?includeAttributes=" + attributes.join(","))
55
- else
56
- connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
57
- end
58
- end
59
16
  end
60
17
  end
@@ -3,6 +3,7 @@ module XClarityClient
3
3
  include XClarityClient::Resource
4
4
 
5
5
  BASE_URI = '/chassis'.freeze
6
+ LIST_NAME = 'chassisList'.freeze
6
7
 
7
8
  attr_accessor :properties, :_id, :accessState, :activationKeys, :activeAlerts, :backedBy, :bladeSlots,
8
9
  :cmmDisplayName, :cmmHealthState, :cmms, :cmmSlots, :complex, :contact, :dataHandle,
@@ -3,61 +3,14 @@ require 'json'
3
3
  module XClarityClient
4
4
  class ChassiManagement < XClarityBase
5
5
 
6
- BASE_URI = '/chassis'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, Chassi::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
-
15
- body = JSON.parse(response.body)
16
- body = {'chassisList' => [body]} unless body.has_key? 'chassisList'
17
- body['chassisList'].map do |chassi|
18
- Chassi.new chassi
19
- end
20
- end
21
-
22
- def discover_chassis
23
- ChassiManagement.new(@connection).population
24
- end
25
-
26
- def get_object_chassis(uuids, includeAttributes, excludeAttributes)
27
-
28
- if not includeAttributes.nil?
29
- response = get_object_chassis_include_attributes(uuids, includeAttributes)
30
- elsif not excludeAttributes.nil?
31
- response = get_object_chassis_exclude_attributes(uuids, excludeAttributes)
32
- elsif not uuids.nil?
33
- response = connection(BASE_URI + "/" + uuids.join(","))
34
- else
35
- response = connection(BASE_URI)
36
- end
37
-
38
- body = JSON.parse(response.body) #rescue {}
39
- body = {'chassisList' => [body]} unless body.has_key? 'chassisList'
40
- body['chassisList'].map do |chassi|
41
- Chassi.new chassi
42
- end
43
- end
44
-
45
- private
46
-
47
- def get_object_chassis_exclude_attributes(uuids, attributes)
48
- if not uuids.nil?
49
- response = connection(BASE_URI + "/#{uuids.join(",")}"+"?excludeAttributes=#{attributes.join(",")}")
50
- else
51
- response = connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
52
- end
53
- end
54
-
55
- def get_object_chassis_include_attributes(uuids, attributes)
56
- if not uuids.nil?
57
- response = connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes=" + attributes.join(","))
58
- else
59
- response = connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
60
- end
12
+ def population(opts = {})
13
+ get_all_resources(Chassi, opts)
61
14
  end
62
15
 
63
16
  end
@@ -5,85 +5,84 @@ module XClarityClient
5
5
  @connection = connection
6
6
  end
7
7
 
8
- def discover_nodes
9
- NodeManagement.new(@connection).population
8
+ def discover_nodes(opts = {})
9
+ NodeManagement.new(@connection).population opts
10
10
  end
11
11
 
12
- def discover_scalableComplexes
13
- ScalableComplexManagement.new(@connection).population
12
+ def discover_scalableComplexes(opts = {})
13
+ ScalableComplexManagement.new(@connection).population opts
14
14
  end
15
15
 
16
- def discover_cabinet
17
- CabinetManagement.new(@connection).population
16
+ def discover_cabinet(opts = {})
17
+ CabinetManagement.new(@connection).population opts
18
18
  end
19
19
 
20
20
  def fetch_cabinet(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
21
- CabinetManagement.new(@connection).get_object_cabinet(uuids, includeAttributes, excludeAttributes)
21
+ CabinetManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Cabinet)
22
22
  end
23
23
 
24
- def discover_canisters
25
- CanisterManagement.new(@connection).population
24
+ def discover_canisters(opts = {})
25
+ CanisterManagement.new(@connection).population opts
26
26
  end
27
27
 
28
28
  def fetch_canisters(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
29
- CanisterManagement.new(@connection).get_object_canisters(uuids, includeAttributes, excludeAttributes)
29
+ CanisterManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Canister)
30
30
  end
31
31
 
32
- def discover_cmms
33
- CmmManagement.new(@connection).population
32
+ def discover_cmms(opts = {})
33
+ CmmManagement.new(@connection).population opts
34
34
  end
35
35
 
36
36
  def fetch_cmms(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
37
- CmmManagement.new(@connection).get_object_cmms(uuids, includeAttributes, excludeAttributes)
37
+ CmmManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Cmm)
38
38
  end
39
39
 
40
40
  def fetch_fans(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
41
-
42
- FanManagement.new(@connection).get_object_fans(uuids, includeAttributes, excludeAttributes)
41
+ FanManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Fan)
43
42
  end
44
43
 
45
- def discover_fans
46
- FanManagement.new(@connection).population
44
+ def discover_fans(opts = {})
45
+ FanManagement.new(@connection).population opts
47
46
  end
48
47
 
49
- def discover_switches
50
- SwitchManagement.new(@connection).population
48
+ def discover_switches(opts = {})
49
+ SwitchManagement.new(@connection).population opts
51
50
  end
52
51
 
53
- def discover_fan_muxes
54
- FanMuxManagement.new(@connection).population
52
+ def discover_fan_muxes(opts = {})
53
+ FanMuxManagement.new(@connection).population opts
55
54
  end
56
55
 
57
56
  def fetch_fan_muxes(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
58
- FanMuxManagement.new(@connection).get_object_fan_muxes(uuids, includeAttributes, excludeAttributes)
57
+ FanMuxManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, FanMux)
59
58
  end
60
59
 
61
- def discover_chassis
62
- ChassiManagement.new(@connection).population
60
+ def discover_chassis(opts = {})
61
+ ChassiManagement.new(@connection).population opts
63
62
  end
64
63
 
65
- def discover_power_supplies
66
- PowerSupplyManagement.new(@connection).population
64
+ def discover_power_supplies(opts = {})
65
+ PowerSupplyManagement.new(@connection).population opts
67
66
  end
68
67
 
69
68
  def fetch_nodes(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
70
- NodeManagement.new(@connection).get_object_nodes(uuids, includeAttributes, excludeAttributes)
69
+ NodeManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Node)
71
70
  end
72
71
 
73
72
  def fetch_chassis(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
74
- ChassiManagement.new(@connection).get_object_chassis(uuids, includeAttributes, excludeAttributes)
73
+ ChassiManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Chassi)
75
74
  end
76
75
 
77
76
  def fetch_scalableComplexes(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
78
- ScalableComplexManagement.new(@connection).get_object_scalableComplexes(uuids, includeAttributes, excludeAttributes)
77
+ ScalableComplexManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, ScalableComplex)
79
78
  end
80
79
 
81
80
  def fetch_switches(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
82
- SwitchManagement.new(@connection).get_object_switches(uuids, includeAttributes, excludeAttributes)
81
+ SwitchManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, Switch)
83
82
  end
84
83
 
85
84
  def fetch_power_supplies(uuids = nil, includeAttributes = nil, excludeAttributes = nil)
86
- PowerSupplyManagement.new(@connection).get_object_power_supplies(uuids, includeAttributes, excludeAttributes)
85
+ PowerSupplyManagement.new(@connection).get_object(uuids, includeAttributes, excludeAttributes, PowerSupply)
87
86
  end
88
87
  end
89
88
  end
@@ -5,6 +5,7 @@ module XClarityClient
5
5
  include XClarityClient::Resource
6
6
 
7
7
  BASE_URI = '/cmms'.freeze
8
+ LIST_NAME = 'cmmList'.freeze
8
9
 
9
10
  attr_accessor :_id, :properties, :accessState, :backedBy, :cmmDisplayName, :cmmHealthState, :dataHandle, :dnsHostnames, :domainName, :errorFields,
10
11
  :excludedHealthState, :firmware, :FRU, :fruSerialNumber, :hostConfig, :hostname, :ipInterfaces, :ipv4Addresses, :ipv6Addresses,
@@ -3,58 +3,14 @@ require 'json'
3
3
  module XClarityClient
4
4
  class CmmManagement < XClarityBase
5
5
 
6
- BASE_URI = '/cmms'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, Cmm::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
-
15
- body = JSON.parse(response.body)
16
- body = {'cmmList' => [body]} unless body.has_key? 'cmmList'
17
- body['cmmList'].map do |cmm|
18
- Cmm.new cmm
19
- end
20
- end
21
-
22
- def get_object_cmms(uuids, includeAttributes, excludeAttributes)
23
-
24
- if not includeAttributes.nil?
25
- response = get_object_cmms_include_attributes(uuids, includeAttributes)
26
- elsif not excludeAttributes.nil?
27
- response = get_object_cmms_exclude_attributes(uuids, excludeAttributes)
28
- elsif not uuids.nil?
29
- response = connection(BASE_URI + "/" + uuids.join(","))
30
- else
31
- response = connection(BASE_URI)
32
- end
33
-
34
-
35
- body = JSON.parse(response.body) #rescue {}
36
- body = {'cmmList' => [body]} unless body.has_key? 'cmmList'
37
- body['cmmList'].map do |cmm|
38
- Cmm.new cmm
39
- end
40
- end
41
-
42
- private
43
-
44
- def get_object_cmms_exclude_attributes(uuids, attributes)
45
- if not uuids.nil?
46
- response = connection(BASE_URI + "/#{uuids.join(",")}"+"?excludeAttributes=#{attributes.join(",")}")
47
- else
48
- response = connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
49
- end
50
- end
51
-
52
- def get_object_cmms_include_attributes(uuids, attributes)
53
- if not uuids.nil?
54
- response = connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes=" + attributes.join(","))
55
- else
56
- response = connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
57
- end
12
+ def population(opts = {})
13
+ get_all_resources(Cmm, opts)
58
14
  end
59
15
 
60
16
  end
@@ -6,6 +6,7 @@ module XClarityClient
6
6
  attr_accessor :username, :password, :host, :csrf_token, :auth_type, :generated_token, :verify_ssl
7
7
 
8
8
  def initialize(args)
9
+ puts "::> #{args}"
9
10
 
10
11
  args.each { |key, value| send("#{key}=", value) }
11
12
 
@@ -20,5 +21,14 @@ module XClarityClient
20
21
 
21
22
  @csrf_token ||= SecureRandom.base64(120) if @auth_type == 'token'
22
23
  end
24
+
25
+ def self.default
26
+ new({
27
+ :username => ENV['LXCA_USERNAME'],
28
+ :password => ENV['LXCA_PASSWORD'],
29
+ :host => ENV['LXCA_HOST'],
30
+ :verify_ssl => ENV['LXCA_VERIFY_SSL'] != "NONE"
31
+ })
32
+ end
23
33
  end
24
34
  end
@@ -3,6 +3,7 @@ module XClarityClient
3
3
  include XClarityClient::Resource
4
4
 
5
5
  BASE_URI = '/fans'.freeze
6
+ LIST_NAME = 'fanList'.freeze
6
7
 
7
8
  attr_accessor :cmmDisplayName, :cmmHealthState, :dataHandle, :firmware, :FRU,
8
9
  :fruSerialNumber, :hardwareRevision, :manufacturer, :manufacturerId,
@@ -3,81 +3,15 @@ require 'json'
3
3
  module XClarityClient
4
4
  class FanManagement < XClarityBase
5
5
 
6
- BASE_URI = '/fans'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, Fan::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
-
15
-
16
- body = JSON.parse(response.body)
17
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
18
- body['fanList'].map do |fan|
19
- Fan.new fan
20
- end
21
- end
22
-
23
- def get_object_fans(uuids, includeAttributes, excludeAttributes)
24
-
25
- response = if not includeAttributes.nil?
26
- get_object_fans_include_attributes(uuids, includeAttributes)
27
- elsif not excludeAttributes.nil?
28
- get_object_fans_exclude_attributes(uuids, excludeAttributes)
29
- elsif not uuids.nil?
30
- response = connection(BASE_URI + "/" + uuids)
31
- body = JSON.parse(response.body)
32
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
33
- body['fanList'].map do |fan|
34
- Fan.new fan
35
- end
36
- else
37
- response = connection(BASE_URI)
38
- body = JSON.parse(response.body)
39
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
40
- body['fanList'].map do |fan|
41
- Fan.new fan
42
- end
43
- end
12
+ def population(opts = {})
13
+ get_all_resources(Fan, opts)
44
14
  end
45
15
 
46
- def get_object_fans_exclude_attributes(uuids, attributes)
47
-
48
- response = if not uuids.nil?
49
- response = connection(BASE_URI + "/" + uuids + "?excludeAttributes="+ attributes.join(","))
50
- body = JSON.parse(response.body)
51
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
52
- body['fanList'].map do |fan|
53
- Fan.new fan
54
- end
55
- else
56
- response = connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
57
- body = JSON.parse(response.body)
58
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
59
- body['fanList'].map do |fan|
60
- Fan.new fan
61
- end
62
- end
63
- end
64
-
65
- def get_object_fans_include_attributes(uuids, attributes)
66
- response = if not uuids.nil?
67
- response = connection(BASE_URI + "/" + uuids + "?includeAttributes="+ attributes.join(","))
68
- body = JSON.parse(response.body)
69
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
70
- body['fanList'].map do |fan|
71
- Fan.new fan
72
- end
73
- else
74
- response = connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
75
- body = JSON.parse(response.body)
76
- body = {'fanList' => [body]} unless body.has_key? 'fanList'
77
- body['fanList'].map do |fan|
78
- Fan.new fan
79
- end
80
- end
81
- end
82
16
  end
83
17
  end
@@ -2,7 +2,8 @@ module XClarityClient
2
2
  class FanMux
3
3
  include XClarityClient::Resource
4
4
 
5
- BASE_URI = '/fan_muxes'.freeze
5
+ BASE_URI = '/fanMuxes'.freeze
6
+ LIST_NAME = 'fanMuxList'.freeze
6
7
 
7
8
  attr_accessor :cmmDisplayName, :cmmHealthState, :dataHandle, :description, :FRU,
8
9
  :fruSerialNumber, :hardwareRevision, :leds, :machineType, :manufacturer, :manufactureDate,
@@ -3,80 +3,15 @@ require 'json'
3
3
  module XClarityClient
4
4
  class FanMuxManagement < XClarityBase
5
5
 
6
- BASE_URI = '/fanMuxes'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, FanMux::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
-
15
- body = JSON.parse(response.body)
16
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
17
- body['fanMuxList'].map do |fan_mux|
18
- FanMux.new fan_mux
19
- end
20
- end
21
-
22
- def get_object_fan_muxes(uuids, includeAttributes, excludeAttributes)
23
-
24
- response = if not includeAttributes.nil?
25
- get_object_fan_muxes_include_attributes(uuids, includeAttributes)
26
- elsif not excludeAttributes.nil?
27
- get_object_fan_muxes_exclude_attributes(uuids, excludeAttributes)
28
- elsif not uuids.nil?
29
- response = connection(BASE_URI + "/" + uuids.join(","))
30
- body = JSON.parse(response.body)
31
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
32
- body['fanMuxList'].map do |fan_mux|
33
- FanMux.new fan_mux
34
- end
35
- else
36
- response = connection(BASE_URI)
37
- body = JSON.parse(response.body)
38
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
39
- body['fanMuxList'].map do |fan_mux|
40
- FanMux.new fan_mux
41
- end
42
- end
12
+ def population(opts = {})
13
+ get_all_resources(FanMux, opts)
43
14
  end
44
15
 
45
- def get_object_fan_muxes_exclude_attributes(uuids, attributes)
46
-
47
- response = if not uuids.nil?
48
- response = connection(BASE_URI + "/" + uuids.join(",") + "?excludeAttributes="+ attributes.join(","))
49
- body = JSON.parse(response.body)
50
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
51
- body['fanMuxList'].map do |fan_mux|
52
- FanMux.new fan_mux
53
- end
54
- else
55
- response = connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
56
- body = JSON.parse(response.body)
57
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
58
- body['fanMuxList'].map do |fan_mux|
59
- FanMux.new fan_mux
60
- end
61
- end
62
- end
63
-
64
- def get_object_fan_muxes_include_attributes(uuids, attributes)
65
- if not uuids.nil?
66
- response = connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes="+ attributes.join(","))
67
- body = JSON.parse(response.body)
68
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
69
- body['fanMuxList'].map do |fan_mux|
70
- FanMux.new fan_mux
71
- end
72
- else
73
- response = connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
74
- body = JSON.parse(response.body)
75
- body = {'fanMuxList' => [body]} unless body.has_key? 'fanMuxList'
76
- body['fanMuxList'].map do |fan_mux|
77
- FanMux.new fan_mux
78
- end
79
- end
80
- end
81
16
  end
82
17
  end
@@ -3,6 +3,7 @@ module XClarityClient
3
3
  include XClarityClient::Resource
4
4
 
5
5
  BASE_URI = '/nodes'.freeze
6
+ LIST_NAME = 'nodeList'.freeze
6
7
 
7
8
  attr_accessor :properties,:_uuid, :accessState, :activationKeys, :uuid, :addinCardSlots, :addinCards, :vnicMode, :productName, :arch, :backedBy, :bladeState_health, :bootMode,
8
9
  :bootOrder, :canisters, :canisterSlots, :cmmDisplayName, :cmmHealthState, :complexID, :dataHandle, :dnsHostnames, :domainName, :bladeState, :bladeState_string,
@@ -4,59 +4,15 @@ require 'uuid'
4
4
  module XClarityClient
5
5
  class NodeManagement < XClarityBase
6
6
 
7
- BASE_URI = '/nodes'.freeze
7
+ include XClarityClient::ManagementMixin
8
8
 
9
9
  def initialize(conf)
10
- super(conf, BASE_URI)
10
+ super(conf, Node::BASE_URI)
11
11
  end
12
12
 
13
- def population
14
- response = connection(BASE_URI)
15
-
16
- body = JSON.parse(response.body)
17
- body['nodeList'].map do |node|
18
- Node.new node
19
- end
20
- end
21
-
22
- def get_object_nodes(uuids, includeAttributes, excludeAttributes)
23
-
24
- response = if not includeAttributes.nil?
25
- get_object_nodes_include_attributes(uuids, includeAttributes)
26
- elsif not excludeAttributes.nil?
27
- get_object_nodes_exclude_attributes(uuids, excludeAttributes)
28
- elsif not uuids.nil?
29
- connection(BASE_URI + "/" + uuids.join(","))
30
- else
31
- connection(BASE_URI)
32
- end
33
-
34
- body = JSON.parse(response.body)
35
- body = {'nodeList' => [body]} unless body.has_key? 'nodeList'
36
- body['nodeList'].map do |node|
37
- Node.new node
38
- end
39
-
13
+ def population(opts = {})
14
+ get_all_resources(Node, opts)
40
15
  end
41
16
 
42
- def get_object_nodes_exclude_attributes(uuids, attributes)
43
- uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
44
-
45
- response = if not uuids.nil?
46
- connection(BASE_URI + "/" + uuids.join(",") + "?excludeAttributes="+ attributes.join(","))
47
- else
48
- connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
49
- end
50
- end
51
-
52
- def get_object_nodes_include_attributes(uuids, attributes)
53
- uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
54
-
55
- response = if not uuids.nil?
56
- connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes="+ attributes.join(","))
57
- else
58
- connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
59
- end
60
- end
61
17
  end
62
18
  end
@@ -2,7 +2,8 @@ module XClarityClient
2
2
  class PowerSupply
3
3
  include XClarityClient::Resource
4
4
 
5
- BASE_URI = '/power_supplies'.freeze
5
+ BASE_URI = '/powerSupplies'.freeze
6
+ LIST_NAME = 'powerSupplyList'.freeze
6
7
 
7
8
  attr_accessor :properties, :_id, :cmmDisplayName, :cmmHealthState, :dataHandle,
8
9
  :description, :firmware, :FRU, :fruSerialNumber, :hardwareRevision, :inputVoltageMax,
@@ -2,88 +2,16 @@ require 'json'
2
2
 
3
3
  module XClarityClient
4
4
  class PowerSupplyManagement < XClarityBase
5
- BASE_URI = '/powerSupplies'.freeze
6
5
 
7
- def initialize(conf)
8
- super(conf, BASE_URI)
9
- end
10
-
11
- def population
12
- response = connection(BASE_URI)
13
-
14
- body = JSON.parse(response.body)
15
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
16
- body['powerSupplyList'].map do |power_supply|
17
- PowerSupply.new power_supply
18
- end
19
- end
20
-
21
- def get_object_power_supplies(uuids, includeAttributes, excludeAttributes)
22
- uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
6
+ include XClarityClient::ManagementMixin
23
7
 
24
- response = nil
25
- if not includeAttributes.nil?
26
- response = get_object_power_supplies_include_attributes(uuids, includeAttributes)
27
- elsif not excludeAttributes.nil?
28
- response = get_object_power_supplies_exclude_attributes(uuids, excludeAttributes)
29
- elsif not uuids.nil?
30
- response = connection(BASE_URI + "/" + uuids.join(","))
31
- body = JSON.parse(response.body)
32
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
33
- body['powerSupplyList'].map do |power_supply|
34
- PowerSupply.new power_supply
35
- end
36
- else
37
- response = connection(BASE_URI)
38
- body = JSON.parse(response.body)
39
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
40
- body['powerSupplyList'].map do |power_supply|
41
- PowerSupply.new power_supply
42
- end
43
- end
8
+ def initialize(conf)
9
+ super(conf, PowerSupply::BASE_URI)
44
10
  end
45
11
 
46
- def get_object_power_supplies_exclude_attributes(uuids, attributes)
47
- uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
48
-
49
- response = nil
50
- if not uuids.nil?
51
- response = connection(BASE_URI + "/" + uuids.join(",") + "?excludeAttributes="+ attributes.join(","))
52
- body = JSON.parse(response.body)
53
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
54
- body['powerSupplyList'].map do |power_supply|
55
- PowerSupply.new power_supply
56
- end
57
- else
58
- response = connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
59
- body = JSON.parse(response.body)
60
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
61
- body['powerSupplyList'].map do |power_supply|
62
- PowerSupply.new power_supply
63
- end
64
- end
12
+ def population(opts = {})
13
+ get_all_resources(PowerSupply, opts)
65
14
  end
66
15
 
67
- def get_object_power_supplies_include_attributes(uuids, attributes)
68
- uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
69
-
70
- response = nil
71
- if not uuids.nil?
72
- response = connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes="+ attributes.join(","))
73
- body = JSON.parse(response.body)
74
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
75
- body['powerSupplyList'].map do |power_supply|
76
- PowerSupply.new power_supply
77
- end
78
-
79
- else
80
- response = connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
81
- body = JSON.parse(response.body)
82
- body = {'powerSupplyList' => [body]} unless body.has_key? 'powerSupplyList'
83
- body['powerSupplyList'].map do |power_supply|
84
- PowerSupply.new power_supply
85
- end
86
- end
87
- end
88
16
  end
89
17
  end
@@ -2,7 +2,8 @@ module XClarityClient
2
2
  class ScalableComplex
3
3
  include XClarityClient::Resource
4
4
 
5
- BASE_URI = '/scalable_complexes'.freeze
5
+ BASE_URI = '/scalableComplex'.freeze
6
+ LIST_NAME = 'complex'.freeze
6
7
 
7
8
  attr_accessor :properties, :_id, :location, :nodeCount, :orphanNodes,
8
9
  :partition, :partitionCount, :uuid, :slots, :complexID
@@ -3,81 +3,15 @@ require 'json'
3
3
  module XClarityClient
4
4
  class ScalableComplexManagement < XClarityBase
5
5
 
6
- BASE_URI = '/scalableComplex'.freeze
6
+ include XClarityClient::ManagementMixin
7
7
 
8
8
  def initialize(conf)
9
- super(conf, BASE_URI)
9
+ super(conf, ScalableComplex::BASE_URI)
10
10
  end
11
11
 
12
- def population
13
- response = connection(BASE_URI)
14
- body = JSON.parse(response.body)
15
- body = {'complex' => [body]} unless body.has_key? 'complex'
16
- body['complex'].map do |scalableComplex|
17
- ScalableComplex.new scalableComplex
18
- end
12
+ def population(opts = {})
13
+ get_all_resources(ScalableComplex, opts)
19
14
  end
20
15
 
21
- def get_object_scalableComplexes(uuids, includeAttributes, excludeAttributes)
22
-
23
- response = if not includeAttributes.nil?
24
- get_object_scalableComplexes_include_attributes(uuids, includeAttributes)
25
- elsif not excludeAttributes.nil?
26
- get_object_scalableComplexes_exclude_attributes(uuids, excludeAttributes)
27
- elsif not uuids.nil?
28
- response = connection(BASE_URI + "/" + uuids)
29
- body = JSON.parse(response.body)
30
- body = {'complex' => [body]} unless body.has_key? 'complex'
31
- body['complex'].map do |scalableComplex|
32
- ScalableComplex.new scalableComplex
33
- end
34
- else
35
- response = connection(BASE_URI)
36
- body = JSON.parse(response.body)
37
- body = {'complex' => [body]} unless body.has_key? 'complex'
38
- body['complex'].map do |scalableComplex|
39
- ScalableComplex.new scalableComplex
40
- end
41
- end
42
-
43
- end
44
-
45
- def get_object_scalableComplexes_exclude_attributes(uuids, attributes)
46
-
47
- if not uuids.nil?
48
- response = connection(BASE_URI + "/" + uuids +"?excludeAttributes=" + attributes.join(","))
49
- body = JSON.parse(response.body)
50
- body = {'complex' => [body]} unless body.has_key? 'complex'
51
- body['complex'].map do |scalableComplex|
52
- ScalableComplex.new scalableComplex
53
- end
54
- else
55
- response = connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
56
- body = JSON.parse(response.body)
57
- body = {'complex' => [body]} unless body.has_key? 'complex'
58
- body['complex'].map do |scalableComplex|
59
- ScalableComplex.new scalableComplex
60
- end
61
- end
62
-
63
- end
64
-
65
- def get_object_scalableComplexes_include_attributes(uuids, attributes)
66
- if not uuids.nil?
67
- response = connection(BASE_URI + "/" + uuids + "?includeAttributes=" + attributes.join(","))
68
- body = JSON.parse(response.body)
69
- body = {'complex' => [body]} unless body.has_key? 'complex'
70
- body['complex'].map do |scalableComplex|
71
- ScalableComplex.new scalableComplex
72
- end
73
- else
74
- response = connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
75
- body = JSON.parse(response.body)
76
- body = {'complex' => [body]} unless body.has_key? 'complex'
77
- body['complex'].map do |scalableComplex|
78
- ScalableComplex.new scalableComplex
79
- end
80
- end
81
- end
82
16
  end
83
17
  end
@@ -3,6 +3,7 @@ module XClarityClient
3
3
  include XClarityClient::Resource
4
4
 
5
5
  BASE_URI = '/switches'.freeze
6
+ LIST_NAME = 'switchList'.freeze
6
7
 
7
8
  attr_accessor :properties, :_id, :accessState, :applyPending, :attachedNodes, :cmmDisplayName, :cmmHealthState, :entitleSerialNumber, :fans, :firmware, :hostname, :ipInterfaces,
8
9
  :leds, :macAddresses, :machineType, :manufacturer, :manufacturerId, :ports, :productId, :productName, :protectedMode, :serialNumber, :type, :upTime, :uuid, :accessState,
@@ -2,58 +2,15 @@ require 'json'
2
2
 
3
3
  module XClarityClient
4
4
  class SwitchManagement < XClarityBase
5
-
6
- BASE_URI = '/switches'.freeze
5
+ include XClarityClient::ManagementMixin
7
6
 
8
7
  def initialize(conf)
9
- super(conf, BASE_URI)
10
- end
11
-
12
- def population
13
- response = connection(BASE_URI)
14
- body = JSON.parse(response.body)
15
- body = {'switchList' => [body]} unless body.has_key? 'switchList'
16
- body['switchList'].map do |switch|
17
- Switch.new switch
18
- end
8
+ super(conf, Switch::BASE_URI)
19
9
  end
20
10
 
21
- def get_object_switches(uuids, includeAttributes, excludeAttributes)
22
-
23
- response = if not includeAttributes.nil?
24
- get_object_switches_include_attributes(uuids, includeAttributes)
25
- elsif not excludeAttributes.nil?
26
- get_object_switches_exclude_attributes(uuids, excludeAttributes)
27
- elsif not uuids.nil?
28
- connection(BASE_URI + "/" + uuids.join(","))
29
- else
30
- connection(BASE_URI)
31
- end
32
-
33
- body = JSON.parse(response.body)
34
- body = {'switchList' => [body]} unless body.has_key? 'switchList'
35
- body['switchList'].map do |switch|
36
- Switch.new switch
37
- end
38
-
11
+ def population(opts = {})
12
+ get_all_resources(Switch, opts)
39
13
  end
40
14
 
41
- def get_object_switches_exclude_attributes(uuids, attributes)
42
-
43
- response = if not uuids.nil?
44
- connection(BASE_URI + "/#{uuids.join(",")}"+"?excludeAttributes=#{attributes.join(",")}")
45
- else
46
- connection(BASE_URI + "?excludeAttributes=" + attributes.join(","))
47
- end
48
-
49
- end
50
-
51
- def get_object_switches_include_attributes(uuids, attributes)
52
- response = if not uuids.nil?
53
- connection(BASE_URI + "/" + uuids.join(",") + "?includeAttributes=" + attributes.join(","))
54
- else
55
- connection(BASE_URI + "?includeAttributes=" + attributes.join(","))
56
- end
57
- end
58
15
  end
59
16
  end
@@ -1,3 +1,3 @@
1
1
  module XClarityClient
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -18,7 +18,7 @@ module XClarityClient
18
18
  #Building configuration
19
19
  @conn = Faraday.new(url: conf.host + uri) do |faraday|
20
20
  faraday.request :url_encoded # form-encode POST params
21
- # faraday.response :logger # log requests to STDOUT -- This line, should be uncommented if you wanna inspect the URL Request
21
+ faraday.response :logger # log requests to STDOUT -- This line, should be uncommented if you wanna inspect the URL Request
22
22
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
23
23
  faraday.ssl[:verify] = conf.verify_ssl == 'PEER'
24
24
  end
@@ -32,8 +32,9 @@ module XClarityClient
32
32
 
33
33
  private
34
34
 
35
- def connection(uri = "", options = {})
36
- @conn.get(uri)
35
+ def connection(uri = "", opts = {})
36
+ query = opts.size > 0 ? "?" + opts.map {|k, v| "#{k}=#{v}"}.join(",") : ""
37
+ @conn.get(uri + query)
37
38
  end
38
39
 
39
40
  def authentication(conf)
@@ -0,0 +1,65 @@
1
+ module XClarityClient
2
+ module ManagementMixin
3
+
4
+
5
+ def get_all_resources (resource, opts = {})
6
+ response = connection(resource::BASE_URI, opts)
7
+
8
+ return [] unless response.success?
9
+
10
+ body = JSON.parse(response.body)
11
+ body = {resource::LIST_NAME => [body]} unless body.has_key? resource::LIST_NAME
12
+ body[resource::LIST_NAME].map do |resource_params|
13
+ resource.new resource_params
14
+ end
15
+ end
16
+
17
+ def get_object(uuids, includeAttributes, excludeAttributes, resource)
18
+
19
+ uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
20
+
21
+ response = if not includeAttributes.nil?
22
+ get_object_with_include_attributes(uuids, includeAttributes, resource)
23
+ elsif not excludeAttributes.nil?
24
+ get_object_with_exclude_attributes(uuids, excludeAttributes, resource)
25
+ elsif not uuids.nil?
26
+ connection(resource::BASE_URI + "/" + uuids.join(","))
27
+ else
28
+ connection(resource::BASE_URI)
29
+ end
30
+
31
+ return [] unless response.success?
32
+
33
+ body = JSON.parse(response.body)
34
+ body = {resource::LIST_NAME => [body]} unless body.has_key? resource::LIST_NAME
35
+ body[resource::LIST_NAME].map do |resource_params|
36
+ resource.new resource_params
37
+ end
38
+ end
39
+
40
+ def get_object_with_include_attributes(uuids, attributes, resource)
41
+
42
+ uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
43
+
44
+ response = if not uuids.nil?
45
+ connection(resource::BASE_URI + "/" + uuids.join(",") + "?includeAttributes=" + attributes.join(","))
46
+ else
47
+ connection(resource::BASE_URI + "?includeAttributes=" + attributes.join(","))
48
+ end
49
+
50
+ end
51
+
52
+ def get_object_with_exclude_attributes(uuids, attributes, resource)
53
+
54
+ uuids.reject! { |uuid| UUID.validate(uuid).nil? } unless uuids.nil?
55
+
56
+ response = if not uuids.nil?
57
+ connection(resource::BASE_URI + "/#{uuids.join(",")}"+"?excludeAttributes=#{attributes.join(",")}")
58
+ else
59
+ connection(resource::BASE_URI + "?excludeAttributes=" + attributes.join(","))
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xclarity_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Cheal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-02 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -166,6 +166,7 @@ files:
166
166
  - lib/xclarity_client/version.rb
167
167
  - lib/xclarity_client/virtual_appliance_management.rb
168
168
  - lib/xclarity_client/xclarity_base.rb
169
+ - lib/xclarity_client/xclarity_management_mixin.rb
169
170
  - lib/xclarity_client/xclarity_resource.rb
170
171
  - xclarity_client.gemspec
171
172
  homepage: https://github.com/juliancheal/xclarity_client