-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathprovision_workflow.rb
181 lines (162 loc) · 6.56 KB
/
provision_workflow.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
180
181
class ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow < ManageIQ::Providers::InfraManager::ProvisionWorkflow
include DialogFieldValidation
def self.default_dialog_file
'miq_provision_dialogs'
end
def self.default_pre_dialog_file
'miq_provision_dialogs_pre'
end
def self.encrypted_options_fields
super + [:sysprep_password, :sysprep_domain_password]
end
def supports_pxe?
get_value(@values[:provision_type]).to_s == 'pxe'
end
def dialog_name_from_automate(message = 'get_dialog_name')
super(message, {'platform' => 'vmware'})
end
def allowed_provision_types(_options = {})
{
"vmware" => "VMware",
"pxe" => "PXE"
}
end
SYSPREP_TIMEZONES = {
'000' => '(GMT-12:00) International Date Line West',
'001' => '(GMT-11:00) Midway Island, Samoa',
'002' => '(GMT-10:00) Hawaii',
'003' => '(GMT-09:00) Alaska',
'004' => '(GMT-08:00) Pacific Time (US and Canada); Tijuana',
'010' => '(GMT-07:00) Mountain Time (US and Canada)',
'013' => '(GMT-07:00) Chihuahua, La Paz, Mazatlan',
'015' => '(GMT-07:00) Arizona',
'020' => '(GMT-06:00) Central Time (US and Canada)',
'025' => '(GMT-06:00) Saskatchewan',
'030' => '(GMT-06:00) Guadalajara, Mexico City, Monterrey',
'033' => '(GMT-06:00) Central America',
'035' => '(GMT-05:00) Eastern Time (US and Canada)',
'040' => '(GMT-05:00) Indiana (East)',
'045' => '(GMT-05:00) Bogota, Lima, Quito',
'050' => '(GMT-04:00) Atlantic Time (Canada)',
'055' => '(GMT-04:00) Caracas, La Paz',
'056' => '(GMT-04:00) Santiago',
'060' => '(GMT-03:30) Newfoundland and Labrador',
'065' => '(GMT-03:00) Brasilia',
'070' => '(GMT-03:00) Buenos Aires, Georgetown',
'073' => '(GMT-03:00) Greenland',
'075' => '(GMT-02:00) Mid-Atlantic',
'080' => '(GMT-01:00) Azores',
'083' => '(GMT-01:00) Cape Verde Islands',
'085' => '(GMT-00:00) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London',
'090' => '(GMT-00:00) Casablanca, Monrovia',
'095' => '(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague',
'100' => '(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb',
'105' => '(GMT+01:00) Brussels, Copenhagen, Madrid, Paris',
'110' => '(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
'113' => '(GMT+01:00) West Central Africa',
'115' => '(GMT+02:00) Bucharest',
'120' => '(GMT+02:00) Cairo',
'125' => '(GMT+02:00) Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius',
'130' => '(GMT+02:00) Athens, Istanbul, Minsk',
'135' => '(GMT+02:00) Jerusalem',
'140' => '(GMT+02:00) Harare, Pretoria',
'145' => '(GMT+03:00) Moscow, St. Petersburg, Volgograd',
'150' => '(GMT+03:00) Kuwait, Riyadh',
'155' => '(GMT+03:00) Nairobi',
'158' => '(GMT+03:00) Baghdad',
'160' => '(GMT+03:30) Tehran',
'165' => '(GMT+04:00) Abu Dhabi, Muscat',
'170' => '(GMT+04:00) Baku, Tbilisi, Yerevan',
'175' => '(GMT+04:30) Kabul',
'180' => '(GMT+05:00) Ekaterinburg',
'185' => '(GMT+05:00) Islamabad, Karachi, Tashkent',
'190' => '(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi',
'193' => '(GMT+05:45) Kathmandu',
'195' => '(GMT+06:00) Astana, Dhaka',
'200' => '(GMT+06:00) Sri Jayawardenepura',
'201' => '(GMT+06:00) Almaty, Novosibirsk',
'203' => '(GMT+06:30) Yangon (Rangoon)',
'205' => '(GMT+07:00) Bangkok, Hanoi, Jakarta',
'207' => '(GMT+07:00) Krasnoyarsk',
'210' => '(GMT+08:00) Beijing, Chongqing, Hong Kong SAR, Urumqi',
'215' => '(GMT+08:00) Kuala Lumpur, Singapore',
'220' => '(GMT+08:00) Taipei',
'225' => '(GMT+08:00) Perth',
'227' => '(GMT+08:00) Irkutsk, Ulaanbaatar',
'230' => '(GMT+09:00) Seoul',
'235' => '(GMT+09:00) Osaka, Sapporo, Tokyo',
'240' => '(GMT+09:00) Yakutsk',
'245' => '(GMT+09:30) Darwin',
'250' => '(GMT+09:30) Adelaide',
'255' => '(GMT+10:00) Canberra, Melbourne, Sydney',
'260' => '(GMT+10:00) Brisbane',
'265' => '(GMT+10:00) Hobart',
'270' => '(GMT+10:00) Vladivostok',
'275' => '(GMT+10:00) Guam, Port Moresby',
'280' => '(GMT+11:00) Magadan, Solomon Islands, New Caledonia',
'285' => '(GMT+12:00) Fiji Islands, Kamchatka, Marshall Islands',
'290' => '(GMT+12:00) Auckland, Wellington',
'300' => '(GMT+13:00) Nuku\'alofa'
}.freeze
def get_timezones(_options = {})
SYSPREP_TIMEZONES
end
def self.provider_model
ManageIQ::Providers::Vmware::InfraManager
end
def update_field_visibility
options = {}
vm = load_ar_obj(get_source_vm)
unless vm.nil?
vm_hardware_version = vm.hardware.virtual_hw_version rescue nil
options[:read_only_fields] = [:cores_per_socket] if vm_hardware_version.to_i < 7
end
super(options)
end
def available_vlans_and_hosts(options = {})
vlans, hosts = super
# Remove certain networks
vlans.delete_if { |_k, v| v.in?(['Service Console', 'VMkernel']) }
# dvportgroups key-value transformed
if options[:dvs]
dvlans = Hash.new { |h, k| h[k] = [] }
unless hosts.nil?
shared_lans = Lan.distinct.select(:id, :switch_id, :name)
.includes(:switch)
.joins(:switch => :host_switches)
.where(:host_switches => {:host_id => hosts.map(&:id)})
.merge(Switch.shareable)
shared_lans.each { |l| dvlans[l.name] << l.switch.name }
end
dvlans.each do |l, v|
vlans["dvs_#{l}"] = "#{l} (#{v.sort.uniq.join('/')})"
end
end
return vlans, hosts
end
def filter_hosts_by_vlan_name(all_hosts)
vlan_name = get_value(@values[:vlan])
return all_hosts unless vlan_name
_log.info("Filtering hosts with the following network: <#{vlan_name}>")
shared = !vlan_name.match(/dvs_/).nil?
vlan_search_name = shared ? vlan_name.sub(/^dvs_/, '') : vlan_name
MiqPreloader.preload(all_hosts, :lans => :switch)
all_hosts.select { |h| h.lans.any? { |lan| lan.name == vlan_search_name && !lan.switch.shared.blank? == shared } }
end
def allowed_storage_profiles(_options = {})
return [] if (src = resources_for_ui).blank? || src[:vm].nil?
@values[:placement_storage_profile] ||=
unless (template = load_ar_obj(src[:vm])).nil?
[template.storage_profile.try(:id), template.storage_profile.try(:name)]
end
@filters[:StorageProfile] ||=
unless (ems = load_ar_obj(src[:ems])).nil?
ems.storage_profiles.each_with_object({}) { |s, m| m[s.id] = s.name }
end
end
def set_on_vm_id_changed
super
@filters[:StorageProfile] = nil
@values[:placement_storage_profile] = nil
end
end