opennebula 6.10.3 → 6.99.85.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cloud/CloudClient.rb +3 -3
  3. data/lib/models/role.rb +349 -823
  4. data/lib/models/service.rb +156 -80
  5. data/lib/models/vmrole.rb +703 -0
  6. data/lib/models/vrrole.rb +284 -0
  7. data/lib/models.rb +3 -1
  8. data/lib/opennebula/acl.rb +1 -1
  9. data/lib/opennebula/acl_pool.rb +1 -1
  10. data/lib/opennebula/backupjob.rb +1 -1
  11. data/lib/opennebula/backupjob_pool.rb +1 -1
  12. data/lib/opennebula/client.rb +1 -1
  13. data/lib/opennebula/cluster.rb +45 -2
  14. data/lib/opennebula/cluster_pool.rb +1 -1
  15. data/lib/opennebula/datastore.rb +1 -1
  16. data/lib/opennebula/datastore_pool.rb +1 -1
  17. data/lib/opennebula/document.rb +1 -1
  18. data/lib/opennebula/document_json.rb +1 -1
  19. data/lib/opennebula/document_pool.rb +1 -1
  20. data/lib/opennebula/document_pool_json.rb +1 -1
  21. data/lib/opennebula/error.rb +1 -1
  22. data/lib/opennebula/flow/grammar.rb +1 -1
  23. data/lib/opennebula/flow/service_pool.rb +1 -1
  24. data/lib/opennebula/flow/service_template.rb +353 -97
  25. data/lib/opennebula/flow/service_template_ext.rb +3 -3
  26. data/lib/opennebula/flow/service_template_pool.rb +1 -1
  27. data/lib/opennebula/flow/validator.rb +458 -410
  28. data/lib/opennebula/flow.rb +1 -1
  29. data/lib/opennebula/group.rb +1 -1
  30. data/lib/opennebula/group_pool.rb +1 -1
  31. data/lib/opennebula/hook.rb +1 -1
  32. data/lib/opennebula/hook_log.rb +1 -1
  33. data/lib/opennebula/hook_pool.rb +1 -1
  34. data/lib/opennebula/host.rb +1 -60
  35. data/lib/opennebula/host_pool.rb +1 -1
  36. data/lib/opennebula/image.rb +1 -1
  37. data/lib/opennebula/image_pool.rb +1 -1
  38. data/lib/opennebula/ldap_auth.rb +1 -1
  39. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  40. data/lib/opennebula/lockable_ext.rb +1 -1
  41. data/lib/opennebula/marketplace.rb +1 -1
  42. data/lib/opennebula/marketplace_pool.rb +1 -1
  43. data/lib/opennebula/marketplaceapp.rb +1 -1
  44. data/lib/opennebula/marketplaceapp_ext.rb +14 -211
  45. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  46. data/lib/opennebula/oneflow_client.rb +11 -9
  47. data/lib/opennebula/pool.rb +1 -1
  48. data/lib/opennebula/pool_element.rb +1 -1
  49. data/lib/opennebula/security_group.rb +1 -1
  50. data/lib/opennebula/security_group_pool.rb +1 -1
  51. data/lib/opennebula/server_cipher_auth.rb +1 -1
  52. data/lib/opennebula/server_x509_auth.rb +1 -1
  53. data/lib/opennebula/ssh_auth.rb +1 -1
  54. data/lib/opennebula/system.rb +1 -1
  55. data/lib/opennebula/template.rb +1 -1
  56. data/lib/opennebula/template_ext.rb +1 -1
  57. data/lib/opennebula/template_pool.rb +1 -1
  58. data/lib/opennebula/user.rb +1 -1
  59. data/lib/opennebula/user_pool.rb +1 -1
  60. data/lib/opennebula/utils.rb +2 -2
  61. data/lib/opennebula/vdc.rb +1 -1
  62. data/lib/opennebula/vdc_pool.rb +1 -1
  63. data/lib/opennebula/virtual_machine.rb +3 -12
  64. data/lib/opennebula/virtual_machine_ext.rb +2 -31
  65. data/lib/opennebula/virtual_machine_pool.rb +1 -1
  66. data/lib/opennebula/virtual_network.rb +1 -1
  67. data/lib/opennebula/virtual_network_pool.rb +1 -1
  68. data/lib/opennebula/virtual_router.rb +1 -1
  69. data/lib/opennebula/virtual_router_pool.rb +1 -1
  70. data/lib/opennebula/vm_group.rb +1 -1
  71. data/lib/opennebula/vm_group_pool.rb +1 -1
  72. data/lib/opennebula/vntemplate.rb +1 -1
  73. data/lib/opennebula/vntemplate_pool.rb +1 -1
  74. data/lib/opennebula/wait_ext.rb +1 -1
  75. data/lib/opennebula/x509_auth.rb +1 -1
  76. data/lib/opennebula/xml_element.rb +2 -2
  77. data/lib/opennebula/xml_pool.rb +1 -1
  78. data/lib/opennebula/xml_utils.rb +1 -1
  79. data/lib/opennebula/zone.rb +1 -1
  80. data/lib/opennebula/zone_pool.rb +1 -1
  81. data/lib/opennebula.rb +2 -2
  82. metadata +6 -67
  83. data/lib/ActionManager.rb +0 -280
  84. data/lib/CommandManager.rb +0 -328
  85. data/lib/DriverExecHelper.rb +0 -213
  86. data/lib/HostSyncManager.rb +0 -111
  87. data/lib/OpenNebulaDriver.rb +0 -223
  88. data/lib/VirtualMachineDriver.rb +0 -404
  89. data/lib/datacenter.rb +0 -1319
  90. data/lib/datastore.rb +0 -1049
  91. data/lib/distributed_firewall.rb +0 -293
  92. data/lib/file_helper.rb +0 -374
  93. data/lib/host.rb +0 -1518
  94. data/lib/logical_port.rb +0 -50
  95. data/lib/logical_switch.rb +0 -77
  96. data/lib/memoize.rb +0 -74
  97. data/lib/network.rb +0 -705
  98. data/lib/nsx_client.rb +0 -157
  99. data/lib/nsx_component.rb +0 -28
  100. data/lib/nsx_constants.rb +0 -162
  101. data/lib/nsx_driver.rb +0 -91
  102. data/lib/nsx_error.rb +0 -77
  103. data/lib/nsx_rule.rb +0 -206
  104. data/lib/nsxt_client.rb +0 -189
  105. data/lib/nsxt_dfw.rb +0 -196
  106. data/lib/nsxt_logical_port.rb +0 -94
  107. data/lib/nsxt_rule.rb +0 -188
  108. data/lib/nsxt_tz.rb +0 -38
  109. data/lib/nsxv_client.rb +0 -189
  110. data/lib/nsxv_dfw.rb +0 -202
  111. data/lib/nsxv_logical_port.rb +0 -107
  112. data/lib/nsxv_rule.rb +0 -172
  113. data/lib/nsxv_tz.rb +0 -41
  114. data/lib/opaque_network.rb +0 -134
  115. data/lib/rest_client.rb +0 -191
  116. data/lib/scripts_common.rb +0 -176
  117. data/lib/transport_zone.rb +0 -43
  118. data/lib/vcenter_driver.rb +0 -152
  119. data/lib/vcenter_importer.rb +0 -626
  120. data/lib/vi_client.rb +0 -273
  121. data/lib/vi_helper.rb +0 -328
  122. data/lib/virtual_machine.rb +0 -3574
  123. data/lib/virtual_wire.rb +0 -158
  124. data/lib/vm_device.rb +0 -80
  125. data/lib/vm_disk.rb +0 -202
  126. data/lib/vm_folder.rb +0 -69
  127. data/lib/vm_helper.rb +0 -30
  128. data/lib/vm_monitor.rb +0 -305
  129. data/lib/vm_nic.rb +0 -70
  130. data/lib/vm_template.rb +0 -2112
  131. data/lib/vmm_importer.rb +0 -165
@@ -1,107 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
- module NSXDriver
17
-
18
- # The NSXVLogicalPort class represents a LogicalPort in NSXv
19
- class NSXVLogicalPort < LogicalPort
20
-
21
- # ATTRIBUTES
22
- attr_reader :id, :name, :type, :url
23
-
24
- # CONSTRUCTOR
25
- # Logical port class variables:
26
- # @lp_id
27
- # @url_lp
28
- # @lp_name
29
- # @lp_type
30
- def initialize(nsx_client, id = nil, data = nil)
31
- super(nsx_client)
32
- # lpid can be:
33
- # - Logical port ID
34
- # - Logical port attach ID
35
- if id
36
- initialize_with_id(id)
37
- else
38
- if data
39
- begin
40
- @id = new_logical_port(data)
41
- rescue NSXError::IncorrectResponseCodeError => e
42
- raise 'Logical Port not created in ' \
43
- "NSX Manager: #{e.message}"
44
- end
45
- unless @id
46
- raise 'Logical Port not created in NSX Manager: '\
47
- 'generic error'
48
- end
49
- # Construct logical port class variables
50
- @url = NSXConstants::NSXT_LP_BASE + @id
51
- @name = lp_name
52
- @type = lp_type
53
- end
54
- end
55
- end
56
-
57
- # Creates a NSXTLogicalPort from its id
58
- def initialize_with_id(id)
59
- # First try lpid as logical port id
60
- @id = id
61
- # Construct URL of the created logical switch
62
- @url = NSXConstants::NSXV_LP_BASE + @id
63
- if lp?
64
- @name = lp_name
65
- @type = lp_type
66
- else
67
- # Second try with lpid as logical port attach id
68
- @id = lp_with_attachid(id)
69
- if @id.nil?
70
- error_msg = "Logical port with id: #{id} not found"
71
- error = NSXError::ObjectNotFound
72
- .new(error_msg)
73
- raise error
74
- else
75
- @url = NSXConstants::NSXT_LP_BASE + @id
76
- @name = lp_name
77
- @type = lp_type
78
- end
79
- end
80
- end
81
-
82
- # Check if logical port exists
83
- def lp?
84
- @nsx_client.get(@url) ? true : false
85
- end
86
-
87
- # Get logical port id from attach id
88
- def lp_with_attachid(attach_id)
89
- lps = @nsx_client.get(NSXConstants::NSXT_LP_BASE)
90
- lps['results'].each do |lp|
91
- return lp['id'] if lp['attachment']['id'] == attach_id
92
- end
93
- end
94
-
95
- # Get logical port display name
96
- def lp_name
97
- @nsx_client.get(@url)['display_name']
98
- end
99
-
100
- # Get resource type
101
- def lp_type
102
- @nsx_client.get(@url)['resource_type']
103
- end
104
-
105
- end
106
-
107
- end
data/lib/nsxv_rule.rb DELETED
@@ -1,172 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
- module NSXDriver
17
-
18
- module NSXRule
19
-
20
- # Module NSXVRule
21
- module NSXVRule
22
-
23
- def nsxv_rule_spec(rule, vm_data, nic_data)
24
- rule_name = "#{rule[:id]}-#{rule[:name]}-#{vm_data[:id]}"
25
- rule_name << "-#{vm_data[:deploy_id]}-#{nic_data[:id]}"
26
-
27
- # rubocop:disable Layout/LineLength
28
- builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
29
- # rubocop:enable Layout/LineLength
30
- xml.rule('disabled' => 'false', 'logged' => 'false') do
31
- xml.name rule_name
32
- xml.action 'allow'
33
- xml.appliedToList do
34
- xml.appliedTo do
35
- xml.name nic_data[:name]
36
- xml.value nic_data[:lp]
37
- xml.type 'Vnic'
38
- xml.isValid 'true'
39
- end
40
- end
41
- xml.sectionId @one_section_id
42
-
43
- # SOURCES / DESTINATIONS: Any | IP Address | Vnet
44
-
45
- unless rule[:network_id].empty? && rule[:subnets].empty?
46
-
47
- if rule[:direction] == 'IN'
48
- xml.sources('excluded' => 'false') do
49
- if !rule[:network_id].empty?
50
- xml.source do
51
- xml.name rule[:network_name]
52
- xml.value rule[:network_nsxid]
53
- xml.type 'VirtualWire'
54
- xml.isValid 'true'
55
- end
56
- elsif !rule[:subnets].empty?
57
- rule[:subnets].each do |subnet|
58
- xml.source do
59
- # rubocop:disable Layout/LineLength
60
- ip_version = IPAddr.new(subnet).ipv4? ? 'Ipv4Address' : 'Ipv6Address'
61
- # rubocop:enable Layout/LineLength
62
- xml.value subnet
63
- xml.type ip_version
64
- xml.isValid 'true'
65
- end
66
- end
67
- end
68
- end
69
- else
70
- xml.destinations('excluded' => 'false') do
71
- # Target network: Vnet
72
- if !rule[:network_id].empty?
73
- xml.destination do
74
- xml.name nic_data[:network_name]
75
- xml.value rule[:network_nsxid]
76
- xml.type 'VirtualWire'
77
- xml.isValid 'true'
78
- end
79
- # Target network: Manual network(IP Address)
80
- elsif !rule[:subnets].empty?
81
- rule[:subnets].each do |subnet|
82
- xml.destination do
83
- # rubocop:disable Layout/LineLength
84
- ip_version = IPAddr.new(subnet).ipv4? ? 'Ipv4Address' : 'Ipv6Address'
85
- # rubocop:enable Layout/LineLength
86
- xml.value subnet
87
- xml.type ip_version
88
- xml.isValid 'true'
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
95
-
96
- ##### SERVICES #####
97
- unless rule[:protocol].empty?
98
- xml.services do
99
- case rule[:protocol]
100
- when 'TCP'
101
- xml.service do
102
- xml.isValid 'true'
103
- xml.protocol '6'
104
- xml.protocolName 'TCP'
105
- # rubocop:disable Layout/LineLength
106
- xml.sourcePort parse_ports(rule[:ports]) \
107
- if rule[:direction] == 'IN'
108
- xml.destinationPort parse_ports(rule[:ports]) \
109
- if rule[:direction] == 'OUT'
110
- # rubocop:enable Layout/LineLength
111
- end
112
- when 'UDP'
113
- xml.service do
114
- xml.isValid 'true'
115
- xml.protocol '17'
116
- xml.protocolName 'UDP'
117
- # rubocop:disable Layout/LineLength
118
- xml.sourcePort parse_ports(rule[:ports]) \
119
- if rule[:direction] == 'IN'
120
- xml.destinationPort parse_ports(rule[:ports]) \
121
- if rule[:direction] == 'OUT'
122
- # rubocop:enable Layout/LineLength
123
- end
124
- when 'ICMP'
125
- xml.service do
126
- xml.isValid 'true'
127
- xml.protocol '1'
128
- xml.protocolName 'ICMP'
129
- end
130
- when 'ICMPv6'
131
- xml.service do
132
- xml.isValid 'true'
133
- xml.protocol '58'
134
- xml.protocolName 'IPV6ICMP'
135
- end
136
- when 'IPSEC'
137
- ports = NSXConstants::NSX_RULE_IPSEC_PORTS
138
- xml.service do
139
- xml.isValid 'true'
140
- xml.protocol '50'
141
- xml.protocolName 'ESP'
142
- end
143
- xml.service do
144
- xml.isValid 'true'
145
- xml.protocol '51'
146
- xml.protocolName 'AH'
147
- end
148
- xml.service do
149
- xml.isValid 'true'
150
- xml.protocol '17'
151
- xml.protocolName 'UDP'
152
- xml.sourcePort parse_ports(ports) \
153
- if rule[:direction] == 'IN'
154
- xml.destinationPort parse_ports(ports) \
155
- if rule[:direction] == 'OUT'
156
- end
157
- end
158
- end
159
- end
160
-
161
- xml.direction rule[:direction].downcase
162
- xml.packetType 'any'
163
- end
164
- end
165
- builder.to_xml
166
- end
167
-
168
- end
169
-
170
- end
171
-
172
- end
data/lib/nsxv_tz.rb DELETED
@@ -1,41 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
- module NSXDriver
17
-
18
- # Class Transport Zone
19
- class NSXVtz < TransportZone
20
-
21
- # ATTRIBUTES
22
- attr_reader :tz_id
23
-
24
- # CONSTRUCTOR
25
- def initialize(nsx_client)
26
- super(nsx_client)
27
- # Construct base URLs
28
- @url_tzs_nsxv = NSXConstants::NSXV_TZS
29
- end
30
-
31
- # METHODS
32
- # Return the transport zones list
33
- def tzs
34
- @nsx_client
35
- .get(@url_tzs_nsxv)
36
- .xpath(NSXConstants::NSXV_TZS_XPATH)
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,134 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
- module NSXDriver
17
-
18
- # Class Opaque Network NSX-T Network
19
- class OpaqueNetwork < LogicalSwitch
20
-
21
- # ATTRIBUTES
22
- # attr_reader :ls_id, :admin_display
23
-
24
- # CONSTRUCTOR
25
- def initialize(nsx_client, ls_id = nil, tz_id = nil, ls_data = nil)
26
- super(nsx_client)
27
- if ls_id
28
- initialize_with_id(ls_id)
29
- else
30
- if tz_id && ls_data
31
- begin
32
- @ls_id = new_logical_switch(ls_data)
33
- rescue NSXError::IncorrectResponseCodeError => e
34
- raise 'Opaque Network not created in ' \
35
- "NSX Manager: #{e.message}"
36
- end
37
- unless @ls_id
38
- raise 'Opaque Network not created in NSX Manager: '\
39
- 'generic error'
40
- end
41
-
42
- # Construct URL of the created logical switch
43
- @url_ls = NSXConstants::NSXT_LS_SECTION + @ls_id
44
- @ls_vni = ls_vni
45
- @ls_name = ls_name
46
- @tz_id = ls_tz
47
- @admin_display = 'UP'
48
- end
49
- end
50
- end
51
-
52
- # Creates a OpaqueNetwork from its name
53
- def self.new_from_name(nsx_client, ls_name)
54
- lswitch = new(nsx_client)
55
- ls_id = lswitch.ls_id_from_name(nsx_client, ls_name)
56
- unless ls_id
57
- error_msg = "Opaque Network with name: #{ls_name} not found"
58
- error = NSXError::ObjectNotFound
59
- .new(error_msg)
60
- raise error
61
- end
62
-
63
- # initialize_with_id(@ls_id)
64
- lswitch.initialize_with_id(ls_id)
65
- lswitch
66
- end
67
-
68
- # Creates a OpaqueNetwork from its id
69
- def initialize_with_id(ls_id)
70
- @ls_id = ls_id
71
- # Construct URL of the created logical switch
72
- @url_ls = NSXConstants::NSXT_LS_SECTION + \
73
- @ls_id
74
- if ls?
75
- @ls_vni = ls_vni
76
- @ls_name = ls_name
77
- @tz_id = ls_tz
78
- @admin_display = 'UP'
79
- else
80
- error_msg = "Opaque Network with id: #{ls_id} not found"
81
- error = NSXError::ObjectNotFound
82
- .new(error_msg)
83
- raise error
84
- end
85
- end
86
-
87
- # Get the logical switch id from its name
88
- def ls_id_from_name(nsx_client, name)
89
- url = NSXConstants::NSXT_LS_SECTION
90
- lswitches = nsx_client.get(url)['results']
91
- lswitches.each do |lswitch|
92
- lsname = lswitch['display_name']
93
- lsid = lswitch['id']
94
- if lsname == name && lsid
95
- return lsid
96
- end
97
- end
98
- nil
99
- end
100
-
101
- # METHODS
102
- # Check if logical switch exists
103
- def ls?
104
- @nsx_client.get(@url_ls) ? true : false
105
- end
106
-
107
- # Get logical switch's name
108
- def ls_name
109
- @nsx_client.get(@url_ls)['display_name']
110
- end
111
-
112
- # Get logical switch's vni
113
- def ls_vni
114
- @nsx_client.get(@url_ls)['vni']
115
- end
116
-
117
- # Get the Transport Zone of the logical switch
118
- def ls_tz
119
- @nsx_client.get(@url_ls)['transport_zone_id']
120
- end
121
-
122
- # Create a new logical switch (NSX-T: opaque network)
123
- def new_logical_switch(ls_data)
124
- @nsx_client.post(NSXConstants::NSXT_LS_SECTION, ls_data)
125
- end
126
-
127
- # Delete a logical switch
128
- def delete_logical_switch
129
- @nsx_client.delete(@url_ls)
130
- end
131
-
132
- end
133
-
134
- end
data/lib/rest_client.rb DELETED
@@ -1,191 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
- require 'openssl'
17
- require 'yaml'
18
- require 'vsphere-automation-vcenter'
19
- require 'vsphere-automation-cis'
20
-
21
- module VCenterDriver
22
-
23
- ########################################################################
24
- # Class RESTClient
25
- ########################################################################
26
- class RESTClient
27
-
28
- attr_accessor :configuration
29
-
30
- def initialize(opts)
31
- @opts = {
32
- :insecure => true,
33
- :associable_types => [
34
- ClusterComputeResource,
35
- DistributedVirtualSwitch,
36
- VmwareDistributedVirtualSwitch,
37
- LibraryItem,
38
- ResourcePool,
39
- Folder,
40
- HostNetwork,
41
- DistributedVirtualPortgroup,
42
- VirtualApp,
43
- StoragePod,
44
- Datastore,
45
- Network,
46
- Datacenter,
47
- Library,
48
- HostSystem,
49
- OpaqueNetwork,
50
- VirtualMachine
51
- ],
52
- :category_name => 'OpenNebula',
53
- :category_description => 'OpenNebula Category',
54
- :cardinality =>
55
- VSphereAutomation::CIS::CisTaggingCategoryModelCardinality
56
- .const_get(
57
- 'multiple'.upcase
58
- )
59
- }.merge(opts)
60
-
61
- @configuration = VSphereAutomation::Configuration.new.tap do |c|
62
- c.host = @opts[:hostname]
63
- c.username = @opts[:username]
64
- c.password = @opts[:password]
65
- c.scheme = 'https'
66
- c.verify_ssl = !@opts[:insecure]
67
- c.verify_ssl_host = !@opts[:insecure]
68
- end
69
- end
70
-
71
- def self.new_from_host(host_id)
72
- client = OpenNebula::Client.new
73
- host = OpenNebula::Host.new_with_id(host_id, client)
74
- rc = host.info(true)
75
- if OpenNebula.is_error?(rc)
76
- raise "Could not get host info for ID: \
77
- #{host_id} - #{rc.message}"
78
- end
79
-
80
- connection = {
81
- :hostname => host['TEMPLATE/VCENTER_HOST'],
82
- :username => host['TEMPLATE/VCENTER_USER'],
83
- :password => host['TEMPLATE/VCENTER_PASSWORD']
84
- }
85
-
86
- new(connection)
87
- end
88
-
89
- def get_or_create_tag(api_client, category_id, tag_name, tag_description)
90
- tag_api = VSphereAutomation::CIS::TaggingTagApi.new(api_client)
91
- tag = tag_api.list.value.find do |id|
92
- c = tag_api.get(id).value
93
- break c if c.name == tag_name
94
- end
95
-
96
- if tag.nil?
97
- create_spec =
98
- VSphereAutomation::CIS::CisTaggingTagCreateSpec
99
- .new(
100
- name => tag_name,
101
- description => tag_description,
102
- category_id => category_id
103
- )
104
- create_model = VSphereAutomation::CIS::CisTaggingTagCreate.new(
105
- create_spec => create_spec
106
- )
107
-
108
- api_instance =
109
- VSphereAutomation::CIS::TaggingTagApi.new(api_client)
110
- api_instance.create(create_model).value
111
- else
112
- tag.id
113
- end
114
- end
115
-
116
- def get_or_create_category(api_client, category_name)
117
- category_api =
118
- VSphereAutomation::CIS::TaggingCategoryApi.new(api_client)
119
- category = category_api.list.value.find do |id|
120
- c = category_api.get(id).value
121
- break c if c.name == category_name
122
- end
123
- if category.nil?
124
- create_spec =
125
- VSphereAutomation::CIS::CisTaggingCategoryCreateSpec
126
- .new(
127
- name => category_name,
128
- description => @opts[:category_description],
129
- associable_types => @opts[:associable_types],
130
- cardinality => @opts[:cardinality]
131
- )
132
- create_model =
133
- VSphereAutomation::CIS::CisTaggingCategoryCreate
134
- .new(create_spec => create_spec)
135
-
136
- category = category_api.create(create_model)
137
- category.value
138
- else
139
- category.id
140
- end
141
- end
142
-
143
- def sync_tags(vm)
144
- api_client = VSphereAutomation::ApiClient.new(@configuration)
145
- VSphereAutomation::CIS::SessionApi.new(api_client).create('')
146
-
147
- association_api =
148
- VSphereAutomation::CIS::TaggingTagAssociationApi
149
- .new(api_client)
150
-
151
- vm.vcenter_tags.each do |tag|
152
- category_name = @opts[:category_name]
153
-
154
- unless tag['CATEGORY_NAME'].nil?
155
- category_name = tag['CATEGORY_NAME']
156
- end
157
-
158
- category_id = get_or_create_category(api_client, category_name)
159
-
160
- tag_name = tag['NAME']
161
- tag_description = tag['DESCRIPTION']
162
-
163
- tag_id =
164
- get_or_create_tag(
165
- api_client,
166
- category_id,
167
- tag_name,
168
- tag_description
169
- )
170
-
171
- request_body =
172
- VSphereAutomation::CIS::CisTaggingTagAssociationAttach.new
173
-
174
- object_id = VSphereAutomation::CIS::VapiStdDynamicID.new
175
- object_id.id = vm['_ref']
176
- object_id.type = 'VirtualMachine'
177
-
178
- request_body.object_id = object_id
179
-
180
- begin
181
- association_api.attach(tag_id, request_body)
182
- rescue VSphereAutomation::ApiError => e
183
- puts "Exception when calling \
184
- TaggingTagAssociationApi->attach: #{e}"
185
- end
186
- end
187
- end
188
-
189
- end
190
-
191
- end