Class: Morpheus::VirtualImagesInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::VirtualImagesInterface
show all
- Defined in:
- lib/morpheus/api/virtual_images_interface.rb
Constant Summary
Constants inherited
from APIClient
APIClient::CLIENT_ID
Instance Method Summary
collapse
-
#convert(id, payload) ⇒ Object
-
#create(payload) ⇒ Object
-
#destroy(id, params = {}) ⇒ Object
-
#destroy_file(id, filename) ⇒ Object
-
#destroy_location(resource_id, id, params = {}, headers = {}) ⇒ Object
-
#download_chunked(id, outfile, params = {}) ⇒ Object
-
#get(options = nil) ⇒ Object
-
#get_location(resource_id, id, params = {}, headers = {}) ⇒ Object
-
#list(params = {}) ⇒ Object
-
#list_locations(resource_id, params = {}, headers = {}) ⇒ Object
-
#location_base_path(resource_id) ⇒ Object
-
#update(id, payload) ⇒ Object
-
#upload(id, image_file, filename = nil, do_gzip = false) ⇒ Object
-
#upload_by_url(id, file_url, filename = nil) ⇒ Object
-
#virtual_image_types(options = {}) ⇒ Object
Methods inherited from APIClient
#account_groups, #account_users, #accounts, #activity, #appliance_settings, #approvals, #apps, #archive_buckets, #archive_files, #audit, #auth, #authorization_required?, #backup_jobs, #backup_restores, #backup_results, #backup_service_types, #backup_services, #backup_settings, #backup_types, #backups, #billing, #blueprints, #budgets, #catalog, #catalog_item_types, #certificate_types, #certificates, #client_id, #client_id=, #clients, #cloud_datastores, #cloud_folders, #cloud_policies, #cloud_resource_pools, #clouds, #clusters, #common_interface_options, #containers, #credential_types, #credentials, #cypher, #dashboard, #datastores, #default_content_type, #default_timeout, #deploy, #deployments, #dry, #dry_run, #email_templates, #environments, #execute, #execute_schedules, #execution_request, #file_copy_request, #forgot, #group_policies, #groups, #guidance, #guidance_settings, #health, #hub, #image_builder, #initialize, #inspect, #instance_types, #instances, #integration_types, #integrations, #interface, #invoice_line_items, #invoices, #jobs, #key_pairs, #library_cluster_layouts, #library_cluster_packages, #library_container_scripts, #library_container_templates, #library_container_types, #library_container_upgrades, #library_instance_types, #library_layouts, #library_operating_systems, #library_spec_template_types, #library_spec_templates, #license, #load_balancer_monitors, #load_balancer_pool_nodes, #load_balancer_pools, #load_balancer_pools_secondary, #load_balancer_profiles, #load_balancer_types, #load_balancer_virtual_servers, #load_balancers, #log_settings, #logged_in?, #login, #logout, #logs, #monitoring, #monitoring_settings, #network_dhcp_relays, #network_dhcp_servers, #network_domain_records, #network_domains, #network_edge_clusters, #network_floating_ips, #network_groups, #network_pool_ips, #network_pool_server_types, #network_pool_servers, #network_pools, #network_proxies, #network_resource_types, #network_routers, #network_security_server_types, #network_security_servers, #network_server_groups, #network_server_services, #network_server_types, #network_servers, #network_services, #network_static_routes, #network_types, #networks, #old_cypher, #option_type_forms, #option_type_lists, #option_types, #options, #packages, #ping, #plugins, #policies, #power_schedules, #price_sets, #prices, #processes, #projects, #provision_types, #provisioning_license_types, #provisioning_licenses, #provisioning_settings, #reports, #resource_pool_groups, #rest, #roles, #scale_thresholds, #search, #security_group_rules, #security_groups, #security_package_types, #security_packages, #security_scans, #server_devices, #server_types, #servers, #service_plans, #set_ssl_verification_enabled, #setopts, #setup, #snapshots, #ssl_verification_enabled?, #storage_datastores, #storage_providers, #storage_server_types, #storage_servers, #storage_volume_types, #storage_volumes, #subnet_types, #subnets, #task_sets, #tasks, #to_s, #url, #usage, #use_refresh_token, #user_groups, #user_settings, #user_sources, #users, #vdi, #vdi_allocations, #vdi_apps, #vdi_gateways, #vdi_pools, #virtual_images, #whitelabel_settings, #whoami, #wiki, #withopts
Instance Method Details
#convert(id, payload) ⇒ Object
47
48
49
50
51
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 47
def convert(id, payload)
url = "#{@base_url}/api/virtual-images/#{id}/convert"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
execute(method: :post, url: url, headers: , payload: payload.to_json)
end
|
#create(payload) ⇒ Object
35
36
37
38
39
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 35
def create(payload)
url = "#{@base_url}/api/virtual-images"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
execute(method: :post, url: url, headers: , payload: payload.to_json)
end
|
#destroy(id, params = {}) ⇒ Object
53
54
55
56
57
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 53
def destroy(id, params={})
url = "#{@base_url}/api/virtual-images/#{id}"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
execute(method: :delete, url: url, params: params, headers: )
end
|
#destroy_file(id, filename) ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 144
def destroy_file(id, filename)
url = "#{@base_url}/api/virtual-images/#{id}/files"
= { params: {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
[:params][:filename] = filename
execute(method: :delete, url: url, headers: )
end
|
#destroy_location(resource_id, id, params = {}, headers = {}) ⇒ Object
196
197
198
199
200
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 196
def destroy_location(resource_id, id, params = {}, ={})
validate_id!(resource_id)
validate_id!(id)
execute(method: :delete, url: "#{location_base_path(resource_id)}/#{id}", params: params, headers: )
end
|
#download_chunked(id, outfile, params = {}) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 152
def download_chunked(id, outfile, params={})
raise "#{self.class}.download_chunked() passed a blank id!" if id.to_s == ''
url = "#{@base_url}/api/virtual-images/#{id}/download"
= { params: params, authorization: "Bearer #{@access_token}" }
opts = {method: :get, url: url, headers: }
if Dir.exist?(outfile)
raise "outfile is invalid. It is the name of an existing directory: #{outfile}"
end
if @dry_run
return opts
end
http_response = nil
File.open(outfile, 'w') {|f|
block = proc { |response|
response.read_body do |chunk|
f.write chunk
end
}
opts[:block_response] = block
http_response = Morpheus::RestClient.execute(opts)
}
return http_response
end
|
#get(options = nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 16
def get(options=nil)
url = "#{@base_url}/api/virtual-images"
= { params: {}, authorization: "Bearer #{@access_token}" }
if options.is_a?(Hash)
[:params].merge!(options)
elsif options.is_a?(Numeric)
url = "#{@base_url}/api/virtual-images/#{options}"
elsif options.is_a?(String)
[:params]['name'] = options
end
execute(method: :get, url: url, headers: )
end
|
#get_location(resource_id, id, params = {}, headers = {}) ⇒ Object
190
191
192
193
194
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 190
def get_location(resource_id, id, params={}, ={})
validate_id!(resource_id)
validate_id!(id)
execute(method: :get, url: "#{location_base_path(resource_id)}/#{id}", params: params, headers: )
end
|
#list(params = {}) ⇒ Object
29
30
31
32
33
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 29
def list(params={})
url = "#{@base_url}/api/virtual-images"
= { params: params, authorization: "Bearer #{@access_token}" }
execute(method: :get, url: url, headers: )
end
|
#list_locations(resource_id, params = {}, headers = {}) ⇒ Object
185
186
187
188
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 185
def list_locations(resource_id, params={}, ={})
validate_id!(resource_id)
execute(method: :get, url: "#{location_base_path(resource_id)}", params: params, headers: )
end
|
#location_base_path(resource_id) ⇒ Object
181
182
183
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 181
def location_base_path(resource_id)
"/api/virtual-images/#{resource_id}/locations"
end
|
#update(id, payload) ⇒ Object
41
42
43
44
45
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 41
def update(id, payload)
url = "#{@base_url}/api/virtual-images/#{id}"
= { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
execute(method: :put, url: url, headers: , payload: payload.to_json)
end
|
#upload(id, image_file, filename = nil, do_gzip = false) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 70
def upload(id, image_file, filename=nil, do_gzip=false)
filename = filename || File.basename(image_file)
url = "#{@base_url}/api/virtual-images/#{id}/upload"
= { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'}
[:params][:filename] = filename
payload = image_file
http_opts = {}
if Morpheus::RestClient.ssl_verification_enabled? == false
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
http_opts[:ssl_context] = ctx
end
query_params = .delete(:params) || {}
file_size = image_file.size
if File.blockdev?(image_file)
file_size = `blockdev --getsz '#{File.absolute_path(image_file)}'`.strip().to_i * 512
end
if do_gzip
['Content-Encoding'] = 'gzip'
['Content-Type'] = 'application/gzip'
['Content-Length'] = file_size
query_params['extractedContentLength'] = file_size
if @dry_run
return {method: :post, url: url, headers: , params: query_params, payload: payload}
end
http = HTTP.()
http_opts[:params] = query_params
rd, wr = IO.pipe
Thread.new {
gz = Zlib::GzipWriter.new(wr)
File.open(payload) do |fp|
while chunk = fp.read(10 * 1024 * 1024) do
gz.write chunk
end
end
gz.close
}
http_opts[:body] = Morpheus::BodyIO.new(rd)
response = http.post(url, http_opts)
else
if @dry_run
return {method: :post, url: url, headers: , params: query_params, payload: payload}
end
['Content-Length'] = file_size
http = HTTP.()
http_opts[:params] = query_params
http_opts[:body] = payload
response = http.post(url, http_opts)
end
return JSON.parse(response.body.to_s)
end
|
#upload_by_url(id, file_url, filename = nil) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 136
def upload_by_url(id, file_url, filename=nil)
url = "#{@base_url}/api/virtual-images/#{id}/upload"
= { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'}
[:params][:url] = file_url
[:params][:filename] = filename if filename
execute(method: :post, url: url, headers: , timeout: 172800)
end
|
#virtual_image_types(options = {}) ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/morpheus/api/virtual_images_interface.rb', line 7
def virtual_image_types(options={})
url = "#{@base_url}/api/virtual-image-types"
= { params: {}, authorization: "Bearer #{@access_token}" }
if options.is_a?(Hash)
[:params].merge!(options)
end
execute(method: :get, url: url, headers: )
end
|