foreman_azure_rm 2.0.7 → 2.1.3

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/azure_compute_resource_helper.rb +17 -0
  3. data/app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb +50 -28
  4. data/app/models/foreman_azure_rm/azure_rm.rb +86 -71
  5. data/app/models/foreman_azure_rm/azure_rm_compute.rb +34 -3
  6. data/app/views/compute_resources/form/_azurerm.html.erb +3 -6
  7. data/app/views/compute_resources_vms/form/azurerm/_base.html.erb +1 -1
  8. data/app/views/compute_resources_vms/form/azurerm/_volume.html.erb +20 -0
  9. data/app/views/images/form/_azurerm.html.erb +1 -1
  10. data/db/migrate/20200507103900_fix_image_uuid_prefix.rb +8 -0
  11. data/lib/foreman_azure_rm.rb +3 -0
  12. data/lib/foreman_azure_rm/azure_sdk_adapter.rb +68 -2
  13. data/lib/foreman_azure_rm/engine.rb +6 -0
  14. data/lib/foreman_azure_rm/version.rb +1 -1
  15. data/locale/Makefile +61 -0
  16. data/locale/action_names.rb +5 -0
  17. data/locale/ca/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  18. data/locale/ca/foreman_azure_rm.po +185 -0
  19. data/locale/cs_CZ/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  20. data/locale/cs_CZ/foreman_azure_rm.po +189 -0
  21. data/locale/de/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  22. data/locale/de/foreman_azure_rm.po +191 -0
  23. data/locale/en/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  24. data/locale/en/foreman_azure_rm.po +183 -0
  25. data/locale/en_GB/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  26. data/locale/en_GB/foreman_azure_rm.po +187 -0
  27. data/locale/es/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  28. data/locale/es/foreman_azure_rm.po +190 -0
  29. data/locale/foreman_azure_rm.pot +248 -0
  30. data/locale/fr/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  31. data/locale/fr/foreman_azure_rm.po +187 -0
  32. data/locale/gl/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  33. data/locale/gl/foreman_azure_rm.po +185 -0
  34. data/locale/it/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  35. data/locale/it/foreman_azure_rm.po +187 -0
  36. data/locale/ja/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  37. data/locale/ja/foreman_azure_rm.po +187 -0
  38. data/locale/ko/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  39. data/locale/ko/foreman_azure_rm.po +186 -0
  40. data/locale/nl_NL/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  41. data/locale/nl_NL/foreman_azure_rm.po +187 -0
  42. data/locale/pl/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  43. data/locale/pl/foreman_azure_rm.po +188 -0
  44. data/locale/pt_BR/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  45. data/locale/pt_BR/foreman_azure_rm.po +190 -0
  46. data/locale/ru/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  47. data/locale/ru/foreman_azure_rm.po +190 -0
  48. data/locale/sv_SE/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  49. data/locale/sv_SE/foreman_azure_rm.po +187 -0
  50. data/locale/zh_CN/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  51. data/locale/zh_CN/foreman_azure_rm.po +188 -0
  52. data/locale/zh_TW/LC_MESSAGES/foreman_azure_rm.mo +0 -0
  53. data/locale/zh_TW/foreman_azure_rm.po +187 -0
  54. metadata +59 -4
@@ -1,10 +1,7 @@
1
- <%= text_f f, :app_ident, :label => _('Client ID'), :required => true %>
1
+ <%= text_f f, :app_ident, :label => _('Client ID'), :required => true, :help_inline => link_to(icon_text('help', _('Documentation'), :kind => 'pficon'),
2
+ azure_doc_url, :rel => 'external', :class => 'btn btn-default btn-docs', :target => '_blank') %>
2
3
  <%= password_f f, :password, :label => _('Client Secret'), :keep_value => true, :required => true %>
3
4
  <%= text_f f, :user, :label => _('Subscription ID'), :required => true %>
4
5
  <%= text_f f, :uuid, :label => _('Tenant ID'), :required => true %>
5
6
 
6
- <%= selectable_f(f, :url, f.object.class.regions, {}, {:label => _('Azure Region'), :label_help => _("Some of the listed regions might not be supported for your subscription. Please verify on Azure portal."), :required => true }) %>
7
-
8
- <div class="col-md-offset-2">
9
- <%= test_connection_button_f(f, true) %>
10
- </div>
7
+ <%= regions_list(@compute_resource, f) %>
@@ -155,7 +155,7 @@
155
155
  %>
156
156
 
157
157
  <%= selectable_f f, :os_disk_caching, %w(None ReadOnly ReadWrite),
158
- { :include_blank => _('Please select OS Disk Caching method') },
158
+ { :include_blank => _("Azure's Default") },
159
159
  {
160
160
  :label => _('OS Disk Caching'),
161
161
  :label_help => _("Default ReadWrite"),
@@ -0,0 +1,20 @@
1
+ <%= number_f f, :disk_size_gb,
2
+ {
3
+ :class => "col-md-2",
4
+ :label => _("Size (GB)"), :label_size => "col-md-2",
5
+ :required => true,
6
+ :min => 0,
7
+ :value => f.object.disk_size_gb || f.object.disk.disk_size_gb,
8
+ :help_inline => _("Additional number of disks can be added based on VM Size. For more details, please refer to Microsoft Azure's documentation")
9
+ }
10
+ %>
11
+
12
+ <%= selectable_f f, :data_disk_caching, options_for_select(["None", "ReadOnly", "ReadWrite"],
13
+ :selected => f.object.data_disk_caching || f.object.disk.caching),
14
+ { :include_blank => _("Azure's default") },
15
+ {
16
+ :class => "col-md-2",
17
+ :label => _('Data Disk Caching'),
18
+ :required => true
19
+ }
20
+ %>
@@ -2,5 +2,5 @@
2
2
  :help_inline => _("The user that will be used to SSH into the VM for completion")
3
3
  %>
4
4
  <%= password_f f, :password, :keep_value => true, :help_inline => _("Password to authenticate with - used for SSH finish step.") %>
5
- <%= image_field(f, :label => _("Marketplace Image URN"), :help_inline => _("Marketplace URN (e.g. OpenLogic:CentOS:7.5:latest)")) %>
5
+ <%= image_field(f, :label => _("Azure Image Name"), :help_inline => _("For custom or shared gallery image prefix the uuid with 'custom://' or 'gallery://'. For public image, prefix the uuid with 'marketplace://'.' (e.g. 'marketplace://OpenLogic:CentOS:7.5:latest' or 'custom://image-name')")) %>
6
6
  <%= checkbox_f f, :user_data, :help_inline => _("Does this image support user data input?") %>
@@ -0,0 +1,8 @@
1
+ class FixImageUuidPrefix < ActiveRecord::Migration[5.2]
2
+ def up
3
+ Image.where(compute_resource: ForemanAzureRm::AzureRm.unscoped.all).update_all("uuid = concat('marketplace://', uuid)")
4
+ end
5
+
6
+ def down
7
+ end
8
+ end
@@ -3,15 +3,18 @@ require 'azure_mgmt_resources'
3
3
  require 'azure_mgmt_network'
4
4
  require 'azure_mgmt_storage'
5
5
  require 'azure_mgmt_compute'
6
+ require 'azure_mgmt_subscriptions'
6
7
 
7
8
  module ForemanAzureRm
8
9
  Storage = Azure::Storage::Profiles::Latest::Mgmt
9
10
  Network = Azure::Network::Profiles::Latest::Mgmt
10
11
  Compute = Azure::Compute::Profiles::Latest::Mgmt
11
12
  Resources = Azure::Resources::Profiles::Latest::Mgmt
13
+ Subscriptions = Azure::Subscriptions::Profiles::Latest::Mgmt
12
14
 
13
15
  StorageModels = Storage::Models
14
16
  NetworkModels = Network::Models
15
17
  ComputeModels = Compute::Models
16
18
  ResourceModels = Resources::Models
19
+ SubscriptionModels = Subscriptions::Models
17
20
  end
@@ -23,6 +23,10 @@ module ForemanAzureRm
23
23
  @storage_client ||= Storage::Client.new(azure_credentials)
24
24
  end
25
25
 
26
+ def subscription_client
27
+ @subscription_client ||= Subscriptions::Client.new(azure_credentials)
28
+ end
29
+
26
30
  def azure_credentials
27
31
  provider = MsRestAzure::ApplicationTokenProvider.new(
28
32
  @tenant,
@@ -37,6 +41,14 @@ module ForemanAzureRm
37
41
  }
38
42
  end
39
43
 
44
+ def list_regions(subscription_id)
45
+ subscription_client.subscriptions.list_locations(subscription_id)
46
+ end
47
+
48
+ def list_resources(filter)
49
+ resource_client.resources.list(filter)
50
+ end
51
+
40
52
  def rgs
41
53
  rgs = resource_client.resource_groups.list
42
54
  rgs.map(&:name)
@@ -58,6 +70,10 @@ module ForemanAzureRm
58
70
  network_client.network_interfaces.get(rg_name, nic_name)
59
71
  end
60
72
 
73
+ def vm_disk(rg_name, disk_name)
74
+ compute_client.disks.get(rg_name, disk_name)
75
+ end
76
+
61
77
  def get_vm_extension(rg_name, vm_name, vm_extension_name)
62
78
  compute_client.virtual_machine_extensions.get(rg_name, vm_name, vm_extension_name)
63
79
  end
@@ -77,6 +93,38 @@ module ForemanAzureRm
77
93
  compute_client.virtual_machines.get(rg_name, vm_name)
78
94
  end
79
95
 
96
+ def get_marketplace_image(location, publisher_name, offer, skus, version)
97
+ compute_client.virtual_machine_images.get(location, publisher_name, offer, skus, version)
98
+ end
99
+
100
+ def list_versions(location, publisher_name, offer, skus)
101
+ compute_client.virtual_machine_images.list(location, publisher_name, offer, skus)
102
+ end
103
+
104
+ def list_custom_images
105
+ compute_client.images.list
106
+ end
107
+
108
+ def get_custom_image(rg_name, image_name)
109
+ compute_client.images.get(rg_name, image_name)
110
+ end
111
+
112
+ def list_galleries
113
+ compute_client.galleries.list
114
+ end
115
+
116
+ def list_gallery_images(rg_name, gallery_name)
117
+ compute_client.gallery_images.list_by_gallery(rg_name, gallery_name)
118
+ end
119
+
120
+ def get_gallery_image(rg_name, gallery_name, gallery_image_name)
121
+ compute_client.gallery_images.get(rg_name, gallery_name, gallery_image_name)
122
+ end
123
+
124
+ def list_gallery_image_versions(rg_name, gallery_name, gallery_image_name)
125
+ compute_client.gallery_image_versions.list_by_gallery_image(rg_name, gallery_name, gallery_image_name)
126
+ end
127
+
80
128
  def get_storage_accts
81
129
  result = storage_client.storage_accounts.list
82
130
  result.value
@@ -113,8 +161,8 @@ module ForemanAzureRm
113
161
  compute_client.virtual_machines.delete(rg_name, vm_name)
114
162
  end
115
163
 
116
- def delete_disk(rg_name, osdisk_name)
117
- compute_client.disks.delete(rg_name, osdisk_name)
164
+ def delete_disk(rg_name, disk_name)
165
+ compute_client.disks.delete(rg_name, disk_name)
118
166
  end
119
167
 
120
168
  def check_vm_status(rg_name, vm_name)
@@ -141,5 +189,23 @@ module ForemanAzureRm
141
189
  compute_client.virtual_machines.power_off(rg_name, vm_name)
142
190
  compute_client.virtual_machines.deallocate(rg_name, vm_name)
143
191
  end
192
+
193
+ def self.gallery_caching(rg_name)
194
+ @gallery_caching ||= {}
195
+ @gallery_caching[rg_name] ||= {}
196
+ end
197
+
198
+ def actual_gallery_image_id(rg_name, image_id)
199
+ gallery_names = list_galleries.map(&:name)
200
+ gallery_names.each do |gallery|
201
+ gallery_image = list_gallery_images(rg_name, gallery).detect { |image| image.name == image_id }
202
+ return gallery_image&.id
203
+ end
204
+ nil
205
+ end
206
+
207
+ def fetch_gallery_image_id(rg_name, image_id)
208
+ AzureSdkAdapter.gallery_caching(rg_name)[image_id] ||= actual_gallery_image_id(rg_name, image_id)
209
+ end
144
210
  end
145
211
  end
@@ -5,6 +5,7 @@ module ForemanAzureRm
5
5
  #autoloading all files inside lib dir
6
6
  config.eager_load_paths += Dir["#{config.root}/lib"]
7
7
  config.eager_load_paths += Dir["#{config.root}/app/models/concerns/foreman_azure_rm/vm_extensions/"]
8
+ config.eager_load_paths += Dir["#{config.root}/app/helpers/"]
8
9
 
9
10
  initializer 'foreman_azure_rm.register_plugin', :before => :finisher_hook do
10
11
  Foreman::Plugin.register :foreman_azure_rm do
@@ -38,6 +39,11 @@ module ForemanAzureRm
38
39
  require 'azure_mgmt_network'
39
40
  require 'azure_mgmt_storage'
40
41
  require 'azure_mgmt_compute'
42
+ require 'azure_mgmt_subscriptions'
43
+
44
+ # Add format validation for azure images
45
+ ::Image.validates :uuid, format: { with: /\A((marketplace|custom|gallery):\/\/)[^:]+(:[^:]+:[^:]+:[^:]+)?\z/,
46
+ message: "Incorrect UUID format" }, if: -> (image){ image.compute_resource.is_a? ForemanAzureRm::AzureRm }
41
47
 
42
48
  # Use excon as default so that HTTP Proxy settings of foreman works
43
49
  Faraday::default_adapter=:excon
@@ -1,3 +1,3 @@
1
1
  module ForemanAzureRm
2
- VERSION = '2.0.7'.freeze
2
+ VERSION = '2.1.3'.freeze
3
3
  end
data/locale/Makefile ADDED
@@ -0,0 +1,61 @@
1
+ #
2
+ # Makefile for PO merging and MO generation. More info in the README.
3
+ #
4
+ # make all-mo (default) - generate MO files
5
+ # make check - check translations using translate-tool
6
+ # make tx-update - download and merge translations from Transifex
7
+ # make clean - clean everything
8
+ #
9
+ DOMAIN = foreman_azure_rm
10
+ VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
11
+ POTFILE = $(DOMAIN).pot
12
+ MOFILE = $(DOMAIN).mo
13
+ POFILES = $(shell find . -name '$(DOMAIN).po')
14
+ MOFILES = $(patsubst %.po,%.mo,$(POFILES))
15
+ POXFILES = $(patsubst %.po,%.pox,$(POFILES))
16
+ EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
17
+
18
+ %.mo: %.po
19
+ mkdir -p $(shell dirname $@)/LC_MESSAGES
20
+ msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
21
+
22
+ # Generate MO files from PO files
23
+ all-mo: $(MOFILES)
24
+
25
+ # Check for malformed strings
26
+ %.pox: %.po
27
+ msgfmt -c $<
28
+ pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
29
+ -t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
30
+ cat $@
31
+ ! grep -q msgid $@
32
+
33
+ %.edit.po:
34
+ touch $@
35
+
36
+ check: $(POXFILES)
37
+
38
+ # Unify duplicate translations
39
+ uniq-po:
40
+ for f in $(shell find ./ -name "*.po") ; do \
41
+ msguniq $$f -o $$f ; \
42
+ done
43
+
44
+ tx-pull: $(EDITFILES)
45
+ tx pull -f
46
+ for f in $(EDITFILES) ; do \
47
+ sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
48
+ done
49
+
50
+ tx-update: tx-pull
51
+ @echo
52
+ @echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
53
+ @echo
54
+
55
+ mo-files: $(MOFILES)
56
+ git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
57
+ git commit -m "i18n - pulling from tx"
58
+ @echo
59
+ @echo Changes commited!
60
+ @echo
61
+
@@ -0,0 +1,5 @@
1
+ # Autogenerated!
2
+ _("Action with sub plans")
3
+ _("Import facts")
4
+ _("Import Puppet classes")
5
+ _("Remote action:")
@@ -0,0 +1,185 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the foreman_azure_rm package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ # Translators:
7
+ # Robert Antoni Buj Gelonch <rbuj@fedoraproject.org>, 2020
8
+ #
9
+ msgid ""
10
+ msgstr ""
11
+ "Project-Id-Version: foreman_azure_rm 2.0.8\n"
12
+ "Report-Msgid-Bugs-To: \n"
13
+ "PO-Revision-Date: 2020-04-21 13:58+0000\n"
14
+ "Last-Translator: Robert Antoni Buj Gelonch <rbuj@fedoraproject.org>, 2020\n"
15
+ "Language-Team: Catalan (https://www.transifex.com/foreman/teams/114/ca/)\n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=UTF-8\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+ "Language: ca\n"
20
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
21
+
22
+ msgid "%{vm_size} VM Size"
23
+ msgstr ""
24
+
25
+ msgid "Action with sub plans"
26
+ msgstr ""
27
+
28
+ msgid "Actions"
29
+ msgstr "Accions"
30
+
31
+ msgid "Additional number of disks can be added based on VM Size. For more details, please refer to Microsoft Azure's documentation"
32
+ msgstr ""
33
+
34
+ msgid "Azure Region"
35
+ msgstr ""
36
+
37
+ msgid "Azure Resource Manager as a compute resource for Foreman"
38
+ msgstr ""
39
+
40
+ msgid "Azure Subnet"
41
+ msgstr ""
42
+
43
+ msgid "Azure's Default"
44
+ msgstr ""
45
+
46
+ msgid "Azure's default"
47
+ msgstr ""
48
+
49
+ msgid "Client ID"
50
+ msgstr ""
51
+
52
+ msgid "Client ID for AzureRm"
53
+ msgstr ""
54
+
55
+ msgid "Client Secret"
56
+ msgstr ""
57
+
58
+ msgid "Client Secret for AzureRm"
59
+ msgstr ""
60
+
61
+ msgid "Comma seperated file URIs"
62
+ msgstr ""
63
+
64
+ msgid "Custom Script Command"
65
+ msgstr ""
66
+
67
+ msgid "Data Disk Caching"
68
+ msgstr ""
69
+
70
+ msgid "Default ReadWrite"
71
+ msgstr ""
72
+
73
+ msgid "Does this image support user data input?"
74
+ msgstr "La imatge admet l'entrada de dades d'usuari?"
75
+
76
+ msgid "Image"
77
+ msgstr "Imatge"
78
+
79
+ msgid "Import Puppet classes"
80
+ msgstr ""
81
+
82
+ msgid "Import facts"
83
+ msgstr ""
84
+
85
+ msgid "Load Regions"
86
+ msgstr ""
87
+
88
+ msgid "Marketplace Image URN"
89
+ msgstr ""
90
+
91
+ msgid "Marketplace URN (e.g. OpenLogic:CentOS:7.5:latest)"
92
+ msgstr ""
93
+
94
+ msgid "Name"
95
+ msgstr "Nom"
96
+
97
+ msgid "OS Disk Caching"
98
+ msgstr ""
99
+
100
+ msgid "Password"
101
+ msgstr "Contrasenya"
102
+
103
+ msgid "Password to authenticate with - used for SSH finish step."
104
+ msgstr ""
105
+
106
+ msgid "Platform"
107
+ msgstr ""
108
+
109
+ msgid "Please select a Resource Group"
110
+ msgstr ""
111
+
112
+ msgid "Please select a VM Size"
113
+ msgstr ""
114
+
115
+ msgid "Please select an image"
116
+ msgstr "Si us plau, seleccioneu una imatge"
117
+
118
+ msgid "Premium OS Disk"
119
+ msgstr ""
120
+
121
+ msgid "Properties"
122
+ msgstr "Propietats"
123
+
124
+ msgid "Public IP"
125
+ msgstr ""
126
+
127
+ msgid "Region"
128
+ msgstr "Regió"
129
+
130
+ msgid "Reload Images, Sizes, vNets"
131
+ msgstr ""
132
+
133
+ msgid "Remote action:"
134
+ msgstr ""
135
+
136
+ msgid "Resource Group"
137
+ msgstr ""
138
+
139
+ msgid "SSH Key"
140
+ msgstr ""
141
+
142
+ msgid "Select"
143
+ msgstr "Selecciona"
144
+
145
+ msgid "Size"
146
+ msgstr "Mida"
147
+
148
+ msgid "Size (GB)"
149
+ msgstr "Mida (GB)"
150
+
151
+ msgid "State"
152
+ msgstr "Estat"
153
+
154
+ msgid "Static Private IP"
155
+ msgstr ""
156
+
157
+ msgid "Subscription ID"
158
+ msgstr "ID de subscripció"
159
+
160
+ msgid "Subscription ID for AzureRm"
161
+ msgstr ""
162
+
163
+ msgid "Tenant ID"
164
+ msgstr ""
165
+
166
+ msgid "The region you selected has no sizes associated with it"
167
+ msgstr ""
168
+
169
+ msgid "The selected image has no associated compute resource"
170
+ msgstr ""
171
+
172
+ msgid "The selected region has no subnets"
173
+ msgstr ""
174
+
175
+ msgid "The user that will be used to SSH into the VM for completion"
176
+ msgstr ""
177
+
178
+ msgid "To perform commands as root, prefix it with 'sudo'"
179
+ msgstr ""
180
+
181
+ msgid "Username"
182
+ msgstr "Nom d'usuari"
183
+
184
+ msgid "VM Size"
185
+ msgstr ""