Skip to content

Instantly share code, notes, and snippets.

/foo.diff
Created May 15, 2014

Embed
What would you like to do?
diff --git a/app/models/compute_resources/foreman/model/openstack.rb b/app/models/compute_resources/foreman/model/openstack.rb
index 0b4918d..4414622 100644
--- a/app/models/compute_resources/foreman/model/openstack.rb
+++ b/app/models/compute_resources/foreman/model/openstack.rb
@@ -49,8 +49,15 @@ module Foreman::Model
client.addresses.get_address_pools.map { |p| p["name"] }
end
+ def internal_networks
+ network_client.networks.all.select { |net| !net.router_external }
+ end
+
def create_vm(args = {})
network = args.delete(:network)
+ # fix internal network format for fog.
+ args[:nics].delete("")
+ args[:nics].map! {|nic| { 'net_id' => nic } }
vm = super(args)
if network.present?
address = allocate_address(network)
@@ -94,16 +101,35 @@ module Foreman::Model
"OpenStack"
end
+ def neutron_supported?
+ if @neutron_supported.nil?
+ network_client
+ @neutron_supported = true
+ end
+ @neutron_supported
+ rescue => e
+ @neutron_supported = false
+ end
+
private
def client
@client ||= ::Fog::Compute.new(:provider => :openstack,
- :openstack_api_key => password ,
- :openstack_username => user ,
- :openstack_auth_url => url ,
+ :openstack_api_key => password,
+ :openstack_username => user,
+ :openstack_auth_url => url,
:openstack_tenant => tenant)
end
+ def network_client
+ @networkeclient ||= ::Fog::Network.new(:provider => :openstack,
+ :openstack_api_key => password,
+ :openstack_username => user,
+ :openstack_auth_url => url,
+ :openstack_tenant => tenant)
+
+ end
+
def setup_key_pair
key = client.key_pairs.create :name => "foreman-#{id}#{Foreman.uuid}"
KeyPair.create! :name => key.name, :compute_resource_id => self.id, :secret => key.private_key
diff --git a/app/models/concerns/fog_extensions/openstack/server.rb b/app/models/concerns/fog_extensions/openstack/server.rb
index 1b60f1a..53117a8 100644
--- a/app/models/concerns/fog_extensions/openstack/server.rb
+++ b/app/models/concerns/fog_extensions/openstack/server.rb
@@ -5,6 +5,7 @@ module FogExtensions
included do
alias_method_chain :security_groups, :no_id
+ attr_reader :nics
attr_writer :security_group, :network # floating IP
end
diff --git a/app/views/compute_resources_vms/form/_openstack.html.erb b/app/views/compute_resources_vms/form/_openstack.html.erb
index 43de731..f6b0ff0 100644
--- a/app/views/compute_resources_vms/form/_openstack.html.erb
+++ b/app/views/compute_resources_vms/form/_openstack.html.erb
@@ -12,6 +12,9 @@
</div>
<%= select_f f, :tenant_id, compute_resource.tenants, :id, :name, {}, :label => _('Tenant') %>
-<%= select_f f, :security_group, compute_resource.security_groups, :name, :name, { :include_blank => _("None") }, :label => _("Security group") %>
+<%= select_f f, :security_groups, compute_resource.security_groups, :name, :name, {}, :label => _("Security group") %>
<%= selectable_f f, :network, compute_resource.address_pools, { :include_blank => _("None") }, { :label => _("Floating IP network") } %>
-
+<% if compute_resource.neutron_supported? %>
+<%= select_f f, :nics, compute_resource.internal_networks, :id, :name,
+ {}, { :label => _('Internal Network'), :multiple => true } %>
+<% end %>
@iakogan

This comment has been minimized.

Copy link

commented Jul 4, 2014

Thanks
I'll just leave here the commands i used to install this:

# curl https://gist.githubusercontent.com/anonymous/67e5c3f6d3cdd1f444cd/raw/6052ea3f817359062905f0b941b3e7aaa5fdf1c8/foo.diff -o /tmp/cloudwatt_issue.diff
# patch -p1 --verbose -d /usr/share/foreman -i /tmp/cloudwatt_issue.diff --backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.