forked from ManageIQ/manageiq-providers-openstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.rb
131 lines (109 loc) · 3.92 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
class ManageIQ::Providers::Openstack::CloudManager::Template < ManageIQ::Providers::CloudManager::Template
include ManageIQ::Providers::Openstack::HelperMethods
belongs_to :cloud_tenant
supports :smartstate_analysis do
feature_supported, reason = check_feature_support('smartstate_analysis')
unless feature_supported
unsupported_reason_add(:smartstate_analysis, reason)
end
end
supports :provisioning do
if ext_management_system
unsupported_reason_add(:provisioning, ext_management_system.unsupported_reason(:provisioning)) unless ext_management_system.supports_provisioning?
else
unsupported_reason_add(:provisioning, _('not connected to ems'))
end
end
has_and_belongs_to_many :cloud_tenants,
:foreign_key => "vm_id",
:join_table => "cloud_tenants_vms",
:association_foreign_key => "cloud_tenant_id",
:class_name => "ManageIQ::Providers::Openstack::CloudManager::CloudTenant"
def provider_object(connection = nil)
connection ||= ext_management_system.connect
connection.images.get(ems_ref)
end
def perform_metadata_scan(ost)
require 'OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage'
image_id = ems_ref
_log.debug "image_id = #{image_id}"
ost.scanTime = Time.now.utc unless ost.scanTime
ems = ext_management_system
os_handle = ems.openstack_handle
begin
miqVm = MiqOpenStackImage.new(image_id, :os_handle => os_handle)
scan_via_miq_vm(miqVm, ost)
ensure
miqVm.unmount if miqVm
end
end
def perform_metadata_sync(ost)
sync_stashed_metadata(ost)
end
# TODO: Does this code need to be reimplemented?
def proxies4job(_job = nil)
{
:proxies => [MiqServer.my_server],
:message => 'Perform SmartState Analysis on this Image'
}
end
def allocated_disk_storage
hardware.try(:size_on_disk)
end
def has_active_proxy?
true
end
def has_proxy?
true
end
def requires_storage_for_scan?
false
end
def self.raw_create_image(ext_management_system, create_options)
ext_management_system.with_provider_connection(:service => 'Image') do |service|
service.create_image(create_options)
end
rescue => err
_log.error("image=[#{name}], error=[#{err}]")
raise MiqException::MiqOpenstackApiRequestError, parse_error_message_from_fog_response(err), err.backtrace
end
def self.validate_create_image(ext_management_system, _options = {})
if ext_management_system
{:available => true, :message => nil}
else
{:available => false,
:message => _("The Image is not connected to an active %{table}") %
{:table => ui_lookup(:table => "ext_management_system")}}
end
end
def self.create_image(ext_management_system, create_options)
raw_create_image(ext_management_system, create_options)
end
def raw_update_image(options)
ext_management_system.with_provider_connection(:service => 'Image') do |service|
image_attrs = service.images.find_by_id(ems_ref).attributes.stringify_keys
options = options.select { |k| image_attrs.key?(k) }
service.images.find_by_id(ems_ref).update(options)
end
rescue => err
_log.error("image=[#{name}], error: #{err}")
raise MiqException::MiqOpenstackApiRequestError, parse_error_message_from_fog_response(err), err.backtrace
end
def update_image(options)
raw_update_image(options)
end
def raw_delete_image
ext_management_system.with_provider_connection(:service => 'Image') do |service|
service.delete_image(ems_ref)
end
rescue => err
_log.error("image=[#{name}], error: #{err}")
raise MiqException::MiqOpenstackApiRequestError, parse_error_message_from_fog_response(err), err.backtrace
end
def validate_delete_image
{:available => true, :message => nil}
end
def delete_image
raw_delete_image
end
end