opennebula 5.12.6 → 5.13.90.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ActionManager.rb +1 -1
  3. data/lib/CommandManager.rb +1 -1
  4. data/lib/DriverExecHelper.rb +44 -28
  5. data/lib/OpenNebulaDriver.rb +8 -4
  6. data/lib/VirtualMachineDriver.rb +9 -2
  7. data/lib/cloud/CloudClient.rb +3 -3
  8. data/lib/datacenter.rb +1259 -0
  9. data/lib/datastore.rb +1025 -0
  10. data/lib/distributed_firewall.rb +280 -0
  11. data/lib/file_helper.rb +370 -0
  12. data/lib/host.rb +1517 -0
  13. data/lib/logical_port.rb +50 -0
  14. data/lib/logical_switch.rb +77 -0
  15. data/lib/memoize.rb +74 -0
  16. data/lib/models.rb +32 -0
  17. data/lib/models/role.rb +1126 -0
  18. data/lib/models/service.rb +709 -0
  19. data/lib/network.rb +708 -0
  20. data/lib/nsx_client.rb +144 -0
  21. data/lib/nsx_component.rb +28 -0
  22. data/lib/nsx_constants.rb +149 -0
  23. data/lib/nsx_driver.rb +78 -0
  24. data/lib/nsx_error.rb +77 -0
  25. data/lib/nsx_rule.rb +193 -0
  26. data/lib/nsxt_client.rb +176 -0
  27. data/lib/nsxt_dfw.rb +196 -0
  28. data/lib/nsxt_logical_port.rb +94 -0
  29. data/lib/nsxt_rule.rb +188 -0
  30. data/lib/nsxt_tz.rb +38 -0
  31. data/lib/nsxv_client.rb +176 -0
  32. data/lib/nsxv_dfw.rb +202 -0
  33. data/lib/nsxv_logical_port.rb +107 -0
  34. data/lib/nsxv_rule.rb +172 -0
  35. data/lib/nsxv_tz.rb +41 -0
  36. data/lib/opaque_network.rb +134 -0
  37. data/lib/opennebula.rb +5 -2
  38. data/lib/opennebula/acl.rb +1 -1
  39. data/lib/opennebula/acl_pool.rb +1 -1
  40. data/lib/opennebula/client.rb +10 -2
  41. data/lib/opennebula/cluster.rb +1 -1
  42. data/lib/opennebula/cluster_pool.rb +1 -1
  43. data/lib/opennebula/datastore.rb +1 -1
  44. data/lib/opennebula/datastore_pool.rb +1 -1
  45. data/lib/opennebula/document.rb +8 -29
  46. data/lib/opennebula/document_json.rb +42 -12
  47. data/lib/opennebula/document_pool.rb +1 -1
  48. data/lib/opennebula/document_pool_json.rb +1 -1
  49. data/lib/opennebula/error.rb +4 -1
  50. data/lib/opennebula/flow.rb +23 -0
  51. data/lib/opennebula/flow/grammar.rb +1195 -0
  52. data/lib/opennebula/flow/service_pool.rb +190 -0
  53. data/lib/opennebula/flow/service_template.rb +572 -0
  54. data/lib/opennebula/flow/service_template_ext.rb +84 -0
  55. data/lib/opennebula/flow/service_template_pool.rb +32 -0
  56. data/lib/opennebula/flow/validator.rb +499 -0
  57. data/lib/opennebula/group.rb +1 -1
  58. data/lib/opennebula/group_pool.rb +1 -1
  59. data/lib/opennebula/hook.rb +5 -12
  60. data/lib/opennebula/hook_log.rb +1 -1
  61. data/lib/opennebula/hook_pool.rb +1 -1
  62. data/lib/opennebula/host.rb +1 -1
  63. data/lib/opennebula/host_pool.rb +1 -1
  64. data/lib/opennebula/image.rb +19 -14
  65. data/lib/opennebula/image_pool.rb +1 -1
  66. data/lib/opennebula/ldap_auth.rb +1 -1
  67. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  68. data/lib/opennebula/lockable_ext.rb +163 -0
  69. data/lib/opennebula/marketplace.rb +1 -1
  70. data/lib/opennebula/marketplace_pool.rb +1 -1
  71. data/lib/opennebula/marketplaceapp.rb +9 -119
  72. data/lib/opennebula/marketplaceapp_ext.rb +522 -0
  73. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  74. data/lib/opennebula/oneflow_client.rb +4 -3
  75. data/lib/opennebula/pool.rb +19 -3
  76. data/lib/opennebula/pool_element.rb +1 -1
  77. data/lib/opennebula/security_group.rb +1 -1
  78. data/lib/opennebula/security_group_pool.rb +1 -1
  79. data/lib/opennebula/server_cipher_auth.rb +1 -1
  80. data/lib/opennebula/server_x509_auth.rb +1 -1
  81. data/lib/opennebula/ssh_auth.rb +1 -1
  82. data/lib/opennebula/system.rb +1 -1
  83. data/lib/opennebula/template.rb +4 -13
  84. data/lib/opennebula/template_ext.rb +342 -0
  85. data/lib/opennebula/template_pool.rb +1 -1
  86. data/lib/opennebula/user.rb +26 -2
  87. data/lib/opennebula/user_pool.rb +1 -1
  88. data/lib/opennebula/utils.rb +1 -1
  89. data/lib/opennebula/vdc.rb +1 -1
  90. data/lib/opennebula/vdc_pool.rb +1 -1
  91. data/lib/opennebula/virtual_machine.rb +26 -206
  92. data/lib/opennebula/virtual_machine_ext.rb +469 -0
  93. data/lib/opennebula/virtual_machine_pool.rb +5 -1
  94. data/lib/opennebula/virtual_network.rb +4 -10
  95. data/lib/opennebula/virtual_network_pool.rb +1 -1
  96. data/lib/opennebula/virtual_router.rb +4 -12
  97. data/lib/opennebula/virtual_router_pool.rb +1 -1
  98. data/lib/opennebula/vm_group.rb +4 -11
  99. data/lib/opennebula/vm_group_pool.rb +1 -1
  100. data/lib/opennebula/vntemplate.rb +4 -13
  101. data/lib/opennebula/vntemplate_pool.rb +1 -1
  102. data/lib/opennebula/wait_ext.rb +257 -0
  103. data/lib/opennebula/x509_auth.rb +1 -1
  104. data/lib/opennebula/xml_element.rb +1 -1
  105. data/lib/opennebula/xml_pool.rb +1 -1
  106. data/lib/opennebula/xml_utils.rb +1 -1
  107. data/lib/opennebula/zone.rb +1 -1
  108. data/lib/opennebula/zone_pool.rb +1 -1
  109. data/lib/rest_client.rb +201 -0
  110. data/lib/scripts_common.rb +180 -0
  111. data/lib/transport_zone.rb +43 -0
  112. data/lib/vcenter_driver.rb +13 -12
  113. data/lib/vcenter_importer.rb +616 -0
  114. data/lib/vi_client.rb +281 -0
  115. data/lib/vi_helper.rb +312 -0
  116. data/lib/virtual_machine.rb +3477 -0
  117. data/lib/virtual_wire.rb +158 -0
  118. data/lib/vm_device.rb +80 -0
  119. data/lib/vm_disk.rb +202 -0
  120. data/lib/vm_folder.rb +69 -0
  121. data/lib/vm_helper.rb +30 -0
  122. data/lib/vm_monitor.rb +303 -0
  123. data/lib/vm_nic.rb +70 -0
  124. data/lib/vm_template.rb +1961 -0
  125. data/lib/vmm_importer.rb +121 -0
  126. metadata +130 -17
@@ -0,0 +1,94 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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 NSXTLogicalPort
19
+ class NSXTLogicalPort < 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 attach ID
34
+ if id
35
+ initialize_with_id(id)
36
+ else
37
+ if data
38
+ begin
39
+ @id = new_logical_port(data)
40
+ rescue NSXError::IncorrectResponseCodeError => e
41
+ raise 'Logical Port not created in ' \
42
+ "NSX Manager: #{e.message}"
43
+ end
44
+ unless @id
45
+ raise 'Logical Port not created in NSX Manager: '\
46
+ 'generic error'
47
+ end
48
+ # Construct logical port class variables
49
+ @url = NSXConstants::NSXT_LP_BASE + @id
50
+ @name = lp_name
51
+ @type = lp_type
52
+ end
53
+ end
54
+ end
55
+
56
+ # Creates a NSXTLogicalPort from its id
57
+ def initialize_with_id(id)
58
+ @id = lp_with_attachid(id)
59
+ # Construct URL of the created logical switch
60
+ @url = NSXConstants::NSXT_LP_BASE + @id
61
+ return unless lp?
62
+
63
+ @name = lp_name
64
+ @type = lp_type
65
+ end
66
+
67
+ # Check if logical port exists
68
+ def lp?
69
+ @nsx_client.get(@url)
70
+ end
71
+
72
+ # Get logical port id from attach id
73
+ def lp_with_attachid(attach_id)
74
+ lps = @nsx_client.get(NSXConstants::NSXT_LP_BASE)
75
+ lps['results'].each do |lp|
76
+ return lp['id'] if lp['attachment']['id'] == attach_id
77
+ end
78
+ end
79
+
80
+ # # Get logical port display name
81
+ def lp_name
82
+ lp = @nsx_client.get(@url)
83
+ lp['display_name']
84
+ end
85
+
86
+ # # Get resource type
87
+ def lp_type
88
+ lp = @nsx_client.get(@url)
89
+ lp['resource_type']
90
+ end
91
+
92
+ end
93
+
94
+ end
data/lib/nsxt_rule.rb ADDED
@@ -0,0 +1,188 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ # Class Logical Switch
21
+ module NSXTRule
22
+
23
+ def nsxt_rule_spec(rule, vm_data, nic_data)
24
+ # default spec
25
+ # Allow any-any to any port applied on the
26
+ # virtual machine logical port
27
+ rule_name = "#{rule[:id]}-#{rule[:name]}-#{vm_data[:id]}"
28
+ rule_name << "-#{vm_data[:deploy_id]}-#{nic_data[:id]}"
29
+ rule_spec = {
30
+ :display_name => rule_name,
31
+ :destinations_excluded => false,
32
+ :sources => [],
33
+ :destinations => [],
34
+ :services => [],
35
+ :applied_tos => [
36
+ {
37
+ :target_id => nic_data[:lp].id,
38
+ :target_display_name => nic_data[:name],
39
+ :target_type => nic_data[:lp].type,
40
+ :is_valid => true
41
+ }
42
+ ],
43
+ :ip_protocol => 'IPV4_IPV6',
44
+ :logged => false,
45
+ :action => 'ALLOW',
46
+ :sources_excluded => false,
47
+ :disabled => false,
48
+ :direction => rule[:direction]
49
+ }
50
+
51
+ rule_protocol_template = {
52
+ 'TCP' => [
53
+ {
54
+ :service => {
55
+ :l4_protocol => 'TCP',
56
+ :source_ports => [],
57
+ :destination_ports => [],
58
+ :resource_type => 'L4PortSetNSService'
59
+ }
60
+ }
61
+ ],
62
+ 'UDP' => [
63
+ {
64
+ :service => {
65
+ :l4_protocol => 'UDP',
66
+ :source_ports => [],
67
+ :destination_ports => [],
68
+ :resource_type => 'L4PortSetNSService'
69
+ }
70
+ }
71
+ ],
72
+ 'ICMP' => [
73
+ {
74
+ :service => {
75
+ :protocol => 'ICMPv4',
76
+ :resource_type => 'ICMPTypeNSService'
77
+ }
78
+ }
79
+ ],
80
+ 'ICMPv6' => [
81
+ {
82
+ :service => {
83
+ :protocol => 'ICMPv6',
84
+ :resource_type => 'ICMPTypeNSService'
85
+ }
86
+ }
87
+ ],
88
+ 'IPSEC' => [
89
+ {
90
+ :service => {
91
+ :l4_protocol => 'UDP',
92
+ :source_ports => [],
93
+ :destination_ports => [],
94
+ :resource_type => 'L4PortSetNSService'
95
+ }
96
+ },
97
+ {
98
+ :service => {
99
+ :protocol_number => 50,
100
+ :resource_type => 'IPProtocolNSService'
101
+ }
102
+ },
103
+ {
104
+ :service => {
105
+ :protocol_number => 51,
106
+ :resource_type => 'IPProtocolNSService'
107
+ }
108
+ }
109
+ ]
110
+ }
111
+
112
+ # Modify default rule spec based on rule_data extracted
113
+ # from vm template
114
+
115
+ ###### SOURCES / DESTINATIONS: Any | IP Address | Vnet #####
116
+ src_or_dst = []
117
+
118
+ # Target network: Vnet
119
+ if !rule[:network_id].empty?
120
+
121
+ src_or_dst << {
122
+ :target_id => rule[:network_nsxid],
123
+ :target_display_name => rule[:network_name],
124
+ :target_type => 'LogicalSwitch',
125
+ :is_valid => true
126
+ }
127
+
128
+ # Target network: Manual network (IP Address)
129
+ elsif !rule[:subnets].empty?
130
+ rule[:subnets].each do |subnet|
131
+ src_or_dst << {
132
+ :target_id => subnet,
133
+ :target_display_name => subnet,
134
+ :target_type => 'IPAddress',
135
+ :is_valid => true
136
+ }
137
+ end
138
+ end
139
+
140
+ # (OpenNebula) INBOUND => Destination (NSX)
141
+ # (OpenNebula) OUTBOUND => Source (NSX)
142
+ unless src_or_dst.empty?
143
+ rule_spec[:sources] = src_or_dst \
144
+ if rule[:direction] == 'IN'
145
+ rule_spec[:destinations] = src_or_dst \
146
+ if rule[:direction] == 'OUT'
147
+ end
148
+
149
+ ##### SERVICES #####
150
+ services = []
151
+ service = rule_protocol_template[rule[:protocol]]
152
+
153
+ case rule[:protocol]
154
+ when 'TCP'
155
+ service[0][:service][:source_ports] = rule[:ports] \
156
+ if rule[:direction] == 'IN'
157
+ service[0][:service][:destination_ports] = rule[:ports] \
158
+ if rule[:direction] == 'OUT'
159
+ when 'UDP'
160
+ service[0][:service][:source_ports] = rule[:ports] \
161
+ if rule[:direction] == 'IN'
162
+ service[0][:service][:destination_ports] = rule[:ports] \
163
+ if rule[:direction] == 'OUT'
164
+ # when 'ICMP'
165
+ # when 'ICMPv6'
166
+ when 'IPSEC'
167
+ ipsec_ports = NSXConstants::NSX_RULE_IPSEC_PORTS
168
+ service[0][:service][:source_ports] = ipsec_ports \
169
+ if rule[:direction] == 'IN'
170
+ service[0][:service][:destination_ports] = ipsec_ports \
171
+ if rule[:direction] == 'OUT'
172
+ end
173
+
174
+ if rule[:protocol] != 'ALL' && !service.empty?
175
+ service.each do |s|
176
+ services << s
177
+ end
178
+ rule_spec[:services] = services
179
+ end
180
+
181
+ rule_spec
182
+ end
183
+
184
+ end
185
+
186
+ end
187
+
188
+ end
data/lib/nsxt_tz.rb ADDED
@@ -0,0 +1,38 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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 NSXTtz < 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_nsxt = NSXConstants::NSXT_TZS
29
+ end
30
+
31
+ # METHODS
32
+ def tzs
33
+ @nsx_client.get(@url_tzs_nsxt)
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,176 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2021, 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
+ ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
19
+
20
+ if !ONE_LOCATION
21
+ RUBY_LIB_LOCATION = '/usr/lib/one/ruby' \
22
+ unless defined?(RUBY_LIB_LOCATION)
23
+ GEMS_LOCATION = '/usr/share/one/gems' \
24
+ unless defined?(GEMS_LOCATION)
25
+ else
26
+ RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' \
27
+ unless defined?(RUBY_LIB_LOCATION)
28
+ GEMS_LOCATION = ONE_LOCATION + '/share/gems' \
29
+ unless defined?(GEMS_LOCATION)
30
+ end
31
+
32
+ if File.directory?(GEMS_LOCATION)
33
+ real_gems_path = File.realpath(GEMS_LOCATION)
34
+ if !defined?(Gem) || Gem.path != [real_gems_path]
35
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
36
+ require 'rubygems'
37
+ Gem.use_paths(real_gems_path)
38
+ end
39
+ end
40
+
41
+ $LOAD_PATH << RUBY_LIB_LOCATION
42
+
43
+ # Class NSXVClient
44
+ class NSXVClient < NSXClient
45
+
46
+ # ATTIBUTES
47
+ attr_accessor :nsxmgr
48
+ attr_accessor :nsx_user
49
+ attr_accessor :nsx_password
50
+ attr_accessor :nsx_type
51
+
52
+ # CONSTRUCTORS
53
+ def initialize(nsxmgr, nsx_user, nsx_password)
54
+ super(nsxmgr, nsx_user, nsx_password)
55
+ @nsx_type = NSXConstants::NSXV
56
+ end
57
+
58
+ # Prepare headers
59
+ def add_headers(aditional_headers = [])
60
+ headers = NSXConstants::HEADER_XML.clone
61
+ unless aditional_headers.empty?
62
+ aditional_headers.each do |header|
63
+ headers[header.keys[0]] = header.values[0]
64
+ end
65
+ end
66
+ headers
67
+ end
68
+
69
+ # METHODS
70
+ def get(url, aditional_headers = [], valid_codes = [])
71
+ if valid_codes.empty?
72
+ valid_codes = [NSXConstants::CODE_OK,
73
+ NSXConstants::CODE_NO_CONTENT]
74
+ end
75
+ uri = URI.parse(@nsxmgr + url)
76
+ headers = add_headers(aditional_headers)
77
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
78
+ request.basic_auth(@nsx_user, @nsx_password)
79
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
80
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
81
+ https.request(request)
82
+ end
83
+ response = check_response(response, valid_codes)
84
+ Nokogiri::XML response.body
85
+ end
86
+
87
+ def get_full_response(url, aditional_headers = [], valid_codes = [])
88
+ if valid_codes.empty?
89
+ valid_codes = [NSXConstants::CODE_OK,
90
+ NSXConstants::CODE_NO_CONTENT]
91
+ end
92
+ uri = URI.parse(@nsxmgr + url)
93
+ headers = add_headers(aditional_headers)
94
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
95
+ request.basic_auth(@nsx_user, @nsx_password)
96
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
97
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
98
+ https.request(request)
99
+ end
100
+ check_response(response, valid_codes)
101
+ end
102
+
103
+ # Return: id of the created object
104
+ def post(url, data, aditional_headers = [], valid_codes = [])
105
+ if valid_codes.empty?
106
+ valid_codes = [NSXConstants::CODE_CREATED,
107
+ NSXConstants::CODE_OK]
108
+ end
109
+ uri = URI.parse(@nsxmgr + url)
110
+ headers = add_headers(aditional_headers)
111
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
112
+ request.body = data
113
+ request.basic_auth(@nsx_user, @nsx_password)
114
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
115
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
116
+ https.request(request)
117
+ end
118
+ response = check_response(response, valid_codes)
119
+ response.body
120
+ end
121
+
122
+ def put(url, data, aditional_headers = [], valid_codes = [])
123
+ if valid_codes.empty?
124
+ valid_codes = [NSXConstants::CODE_CREATED,
125
+ NSXConstants::CODE_OK]
126
+ end
127
+ uri = URI.parse(@nsxmgr + url)
128
+ headers = add_headers(aditional_headers)
129
+ request = Net::HTTP::Put.new(uri.request_uri, headers)
130
+ request.body = data
131
+ request.basic_auth(@nsx_user, @nsx_password)
132
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
133
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
134
+ https.request(request)
135
+ end
136
+ response = check_response(response, valid_codes)
137
+ response.body
138
+ end
139
+
140
+ def delete(url, aditional_headers = [], valid_codes = [])
141
+ if valid_codes.empty?
142
+ valid_codes = [NSXConstants::CODE_OK,
143
+ NSXConstants::CODE_NO_CONTENT]
144
+ end
145
+ uri = URI.parse(@nsxmgr + url)
146
+ headers = add_headers(aditional_headers)
147
+ request = Net::HTTP::Delete.new(uri.request_uri, headers)
148
+ request.basic_auth(@nsx_user, @nsx_password)
149
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
150
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
151
+ https.request(request)
152
+ end
153
+ check_response(response, valid_codes)
154
+ end
155
+
156
+ def get_token(url, aditional_headers = [], valid_codes = [])
157
+ if valid_codes.empty?
158
+ valid_codes = [NSXConstants::CODE_OK]
159
+ end
160
+ uri = URI.parse(@nsxmgr + url)
161
+ headers = add_headers(aditional_headers)
162
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
163
+ request.basic_auth(@nsx_user, @nsx_password)
164
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
165
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
166
+ https.request(request)
167
+ end
168
+ response = check_response(response, valid_codes)
169
+ response_xml = Nokogiri::XML response.body
170
+ token = response_xml.xpath('//authToken/value').text
171
+ { 'token' => token }.to_json
172
+ end
173
+
174
+ end
175
+
176
+ end