foreman_azure_rm 1.1.1 → 1.2.0
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.
- checksums.yaml +4 -4
- data/app/controllers/foreman_azure_rm/concerns/compute_resources_controller_extensions.rb +23 -0
- data/app/models/concerns/fog_extensions/azurerm/compute.rb +10 -3
- data/app/models/foreman_azure_rm/azure_rm.rb +39 -35
- data/app/views/api/v1/compute_resources/azurerm.json.rabl +1 -0
- data/app/views/api/v2/compute_resources/available_resource_groups.rabl +3 -0
- data/app/views/api/v2/compute_resources/azurerm.json.rabl +1 -0
- data/config/routes.rb +11 -4
- data/lib/foreman_azure_rm/engine.rb +2 -0
- data/lib/foreman_azure_rm/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ead0b87ab5585d6ade5849a45df0b613e7edc967
|
4
|
+
data.tar.gz: 007eb0bd6ac272f7f6811107dbb3555241f1ea23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f17f319bddd0a45e85f367d732f231b912e70d4032815f4eeece960996855e6b2f80c9e7b7b366787dbdbdb70f5a9a449e2bc9b10d76a876c1336f73df0cbe75
|
7
|
+
data.tar.gz: 4690f001b5e4f8efd443a1e531f0011be8a5b78f562f2fa2b909567a12701e76eba913fa08aaa4ba7d8d5854e82d4b1f7d4e1a9c1da20b099ad613e0a85e4143
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ForemanAzureRM
|
2
|
+
module Concerns
|
3
|
+
module ComputeResourcesControllerExtensions
|
4
|
+
include Api::Version2
|
5
|
+
include Foreman::Controller::Parameters::ComputeResource
|
6
|
+
|
7
|
+
def available_resource_groups
|
8
|
+
compute_resource = ComputeResource.find_by_id(params[:id])
|
9
|
+
@available_resource_groups = compute_resource.available_resource_groups
|
10
|
+
render :available_resource_groups, :layout => 'api/v2/layouts/index_layout'
|
11
|
+
end
|
12
|
+
|
13
|
+
def action_permission
|
14
|
+
case params[:action]
|
15
|
+
when 'available_resource_groups'
|
16
|
+
:view
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -140,9 +140,16 @@ module FogExtensions
|
|
140
140
|
def create_vm_extension(vm)
|
141
141
|
if vm[:script_command].present? && vm[:script_uris].present?
|
142
142
|
extension = Azure::ARM::Compute::Models::VirtualMachineExtension.new
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
if vm[:platform] == 'Linux'
|
144
|
+
extension.publisher = 'Microsoft.Azure.Extensions'
|
145
|
+
extension.virtual_machine_extension_type = 'CustomScript'
|
146
|
+
extension.type_handler_version = '2.0'
|
147
|
+
elsif vm[:platform] == 'Windows'
|
148
|
+
extension.publisher = 'Microsoft.Compute'
|
149
|
+
extension.virtual_machine_extension_type = 'CustomScriptExtension'
|
150
|
+
extension.type_handler_version = '1.7'
|
151
|
+
end
|
152
|
+
|
146
153
|
extension.auto_upgrade_minor_version = true
|
147
154
|
extension.location = vm['location'].gsub(/\s+/, '').downcase
|
148
155
|
extension.settings = {
|
@@ -57,6 +57,10 @@ module ForemanAzureRM
|
|
57
57
|
rg_names
|
58
58
|
end
|
59
59
|
|
60
|
+
def available_resource_groups
|
61
|
+
rg_client.list_resource_groups
|
62
|
+
end
|
63
|
+
|
60
64
|
def storage_accts(location = nil)
|
61
65
|
stripped_location = location.gsub(/\s+/, '').downcase
|
62
66
|
acct_names = []
|
@@ -82,6 +86,14 @@ module ForemanAzureRM
|
|
82
86
|
end
|
83
87
|
end
|
84
88
|
|
89
|
+
def available_networks(attr = {})
|
90
|
+
networks
|
91
|
+
end
|
92
|
+
|
93
|
+
def networks
|
94
|
+
subnets
|
95
|
+
end
|
96
|
+
|
85
97
|
def virtual_networks(location = nil)
|
86
98
|
if location.nil?
|
87
99
|
azure_network_service.virtual_networks
|
@@ -91,7 +103,7 @@ module ForemanAzureRM
|
|
91
103
|
end
|
92
104
|
end
|
93
105
|
|
94
|
-
def subnets(location)
|
106
|
+
def subnets(location = nil)
|
95
107
|
vnets = virtual_networks(location)
|
96
108
|
subnets = []
|
97
109
|
vnets.each do |vnet|
|
@@ -108,14 +120,6 @@ module ForemanAzureRM
|
|
108
120
|
super(options)
|
109
121
|
end
|
110
122
|
|
111
|
-
def networks
|
112
|
-
subnets = []
|
113
|
-
virtual_networks.each do |vnet|
|
114
|
-
subnets << subnets(vnet.id)
|
115
|
-
end
|
116
|
-
subnets
|
117
|
-
end
|
118
|
-
|
119
123
|
def new_interface(attr = {})
|
120
124
|
azure_network_service.network_interfaces.new(attr)
|
121
125
|
end
|
@@ -148,24 +152,24 @@ module ForemanAzureRM
|
|
148
152
|
end
|
149
153
|
|
150
154
|
def create_nics(args = {})
|
151
|
-
nics
|
155
|
+
nics = []
|
152
156
|
formatted_location = args[:location].gsub(/\s+/, '').downcase
|
153
157
|
args[:interfaces_attributes].each do |nic, attrs|
|
154
|
-
attrs[:pubip_alloc]
|
158
|
+
attrs[:pubip_alloc] = attrs[:bridge]
|
155
159
|
attrs[:privip_alloc] = (attrs[:name] == 'false') ? false : true
|
156
|
-
pip_alloc
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
priv_ip_alloc
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
160
|
+
pip_alloc = case attrs[:pubip_alloc]
|
161
|
+
when 'Static'
|
162
|
+
Fog::ARM::Network::Models::IPAllocationMethod::Static
|
163
|
+
when 'Dynamic'
|
164
|
+
Fog::ARM::Network::Models::IPAllocationMethod::Dynamic
|
165
|
+
when 'None'
|
166
|
+
nil
|
167
|
+
end
|
168
|
+
priv_ip_alloc = if attrs[:priv_ip_alloc]
|
169
|
+
Fog::ARM::Network::Models::IPAllocationMethod::Static
|
170
|
+
else
|
171
|
+
Fog::ARM::Network::Models::IPAllocationMethod::Dynamic
|
172
|
+
end
|
169
173
|
if pip_alloc.present?
|
170
174
|
pip = azure_network_service.public_ips.create(
|
171
175
|
name: "#{args[:vm_name]}-pip#{nic}",
|
@@ -192,7 +196,7 @@ module ForemanAzureRM
|
|
192
196
|
# does not currently support creating managed VMs
|
193
197
|
def create_vm(args = {})
|
194
198
|
args[:vm_name] = args[:name].split('.')[0]
|
195
|
-
nics
|
199
|
+
nics = create_nics(args)
|
196
200
|
if args[:ssh_key_data].present?
|
197
201
|
disable_password_auth = true
|
198
202
|
ssh_key_path = "/home/#{args[:username]}/.ssh/authorized_keys"
|
@@ -200,7 +204,7 @@ module ForemanAzureRM
|
|
200
204
|
disable_password_auth = false
|
201
205
|
ssh_key_path = nil
|
202
206
|
end
|
203
|
-
vm
|
207
|
+
vm = client.create_managed_virtual_machine(
|
204
208
|
name: args[:vm_name],
|
205
209
|
location: args[:location],
|
206
210
|
resource_group: args[:resource_group],
|
@@ -218,15 +222,15 @@ module ForemanAzureRM
|
|
218
222
|
os_disk_size: args[:os_disk_size],
|
219
223
|
premium_os_disk: args[:premium_os_disk],
|
220
224
|
)
|
221
|
-
vm_hash
|
222
|
-
vm_hash[:password]
|
223
|
-
vm_hash[:platform]
|
224
|
-
vm_hash[:puppet_master]
|
225
|
-
vm_hash[:script_command]
|
226
|
-
vm_hash[:script_uris]
|
225
|
+
vm_hash = Fog::Compute::AzureRM::Server.parse(vm)
|
226
|
+
vm_hash[:password] = args[:password]
|
227
|
+
vm_hash[:platform] = args[:platform]
|
228
|
+
vm_hash[:puppet_master] = args[:puppet_master]
|
229
|
+
vm_hash[:script_command] = args[:script_command]
|
230
|
+
vm_hash[:script_uris] = args[:script_uris]
|
227
231
|
client.create_vm_extension(vm_hash)
|
228
232
|
client.servers.new vm_hash
|
229
|
-
|
233
|
+
# fog-azure-rm raises all ARM errors as RuntimeError
|
230
234
|
rescue Fog::Errors::Error, RuntimeError => e
|
231
235
|
Foreman::Logging.exception('Unhandled Azure RM error', e)
|
232
236
|
destroy_vm vm.id if vm
|
@@ -242,8 +246,8 @@ module ForemanAzureRM
|
|
242
246
|
# In ARM things must be deleted in order
|
243
247
|
vm.destroy
|
244
248
|
nic_ids.each do |id|
|
245
|
-
nic
|
246
|
-
|
249
|
+
nic = azure_network_service.network_interfaces.get(id.split('/')[4],
|
250
|
+
id.split('/')[-1])
|
247
251
|
ip_id = nic.public_ip_address_id
|
248
252
|
nic.destroy
|
249
253
|
if ip_id.present?
|
@@ -0,0 +1 @@
|
|
1
|
+
attributes :user
|
@@ -0,0 +1 @@
|
|
1
|
+
attributes :user, :uuid
|
data/config/routes.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
scope :azure_rm, :path => '/azure_rm' do
|
3
|
-
get :sizes,
|
4
|
-
get :subnets,
|
5
|
-
get :storage_accts,
|
6
|
-
get :vnets,
|
3
|
+
get :sizes, :controller => :hosts
|
4
|
+
get :subnets, :controller => :hosts
|
5
|
+
get :storage_accts, :controller => :hosts
|
6
|
+
get :vnets, :controller => :hosts
|
7
|
+
end
|
8
|
+
namespace :api, :defaults => { :format => 'json' } do
|
9
|
+
scope "(:apiv)", :module => :v2, :defaults => { :apiv => 'v2' }, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
|
10
|
+
resources :compute_resources, :except => [:new, :edit] do
|
11
|
+
get :available_resource_groups, :on => :member
|
12
|
+
end
|
13
|
+
end
|
7
14
|
end
|
8
15
|
end
|
@@ -60,6 +60,8 @@ module ForemanAzureRM
|
|
60
60
|
|
61
61
|
::HostsController.send(:include, ForemanAzureRM::Concerns::HostsControllerExtensions)
|
62
62
|
|
63
|
+
Api::V2::ComputeResourcesController.send(:include, ForemanAzureRM::Concerns::ComputeResourcesControllerExtensions)
|
64
|
+
|
63
65
|
require 'fog/azurerm/models/network/network_interface'
|
64
66
|
require File.expand_path(
|
65
67
|
'../../../app/models/concerns/fog_extensions/azurerm/network_interface',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_azure_rm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Gregory
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-azure-rm-downgraded
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- app/assets/javascripts/foreman_azure_rm/azure_rm_location_callbacks.js
|
53
53
|
- app/assets/javascripts/foreman_azure_rm/azure_rm_size_from_location.js
|
54
54
|
- app/assets/javascripts/foreman_azure_rm/azure_rm_subnet_from_vnet.js
|
55
|
+
- app/controllers/foreman_azure_rm/concerns/compute_resources_controller_extensions.rb
|
55
56
|
- app/controllers/foreman_azure_rm/concerns/hosts_controller_extensions.rb
|
56
57
|
- app/models/concerns/fog_extensions/azurerm/compute.rb
|
57
58
|
- app/models/concerns/fog_extensions/azurerm/data_disk.rb
|
@@ -63,6 +64,9 @@ files:
|
|
63
64
|
- app/models/concerns/fog_extensions/azurerm/servers.rb
|
64
65
|
- app/models/foreman_azure_rm/azure_rm.rb
|
65
66
|
- app/overrides/add_location_size_js.rb
|
67
|
+
- app/views/api/v1/compute_resources/azurerm.json.rabl
|
68
|
+
- app/views/api/v2/compute_resources/available_resource_groups.rabl
|
69
|
+
- app/views/api/v2/compute_resources/azurerm.json.rabl
|
66
70
|
- app/views/compute_resources/form/_azurerm.html.erb
|
67
71
|
- app/views/compute_resources/show/_azurerm.html.erb
|
68
72
|
- app/views/compute_resources_vms/form/azurerm/_base.html.erb
|