foreman_xen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ <div class="fields">
2
+ <%
3
+ selected = ""
4
+ size = ""
5
+ if params && params['host'] && params['host']['compute_attributes']
6
+ selected = params['host']['compute_attributes']['VBDs']['print']
7
+ size = params['host']['compute_attributes']['VBDs']['physical_size']
8
+ end
9
+ -%>
10
+ <%= selectable_f f, :print, compute_resource.storage_pools.map(&:name), { :selected => selected }, :class => "span2", :label => _("Storage Repository") %>
11
+ <%= text_f f, :physical_size, :class => "input-mini", :label => _("Size (GB)"), :value => size %>
12
+ </div>
@@ -0,0 +1,74 @@
1
+ <% new = f.object
2
+ hide_raw = ''
3
+ if params && params['host'] && params['host']['compute_attributes'] && params['host']['compute_attributes']['custom_template_name'] != ''
4
+ hide_raw = 'display:none;'
5
+ end
6
+ -%>
7
+
8
+ <div class="children_fields">
9
+ <fieldset id="vm_profile">
10
+ <legend>VM Profile</legend>
11
+ <div class="fields">
12
+ <%= text_f f, :name, :disabled => !new if controller_name != 'hosts' %>
13
+ <%= selectable_f f, :vcpus_max, 1..compute_resource.max_cpu_count, {}, :class => 'input-mini', :disabled => !new, :label => 'vCPUs' %>
14
+ <%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), {}, :class => 'span2', :disabled => !new %>
15
+ <%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), {}, :class => 'span2', :disabled => !new %>
16
+ </div>
17
+ </fieldset>
18
+ </div>
19
+ <!--Templates -->
20
+ <div class="children_fields">
21
+ <%= field_set_tag 'VM Template', :id => 'xen_templates', :title => _('Template') do -%>
22
+ <%= render 'compute_resources_vms/form/templates', :f => f, :compute_resource => compute_resource %>
23
+ <% end -%>
24
+ </div>
25
+
26
+ <!-- XenStore Data -->
27
+ <div class="children_fields" id="xenserver-xenstore-data">
28
+ <%= field_set_tag 'Xen Store Data', :id => 'xen_store_data', :title => _('Xen Store Data') do -%>
29
+ <%= render 'compute_resources_vms/form/xenstore', :f => f, :compute_resource => compute_resource, :new => new %>
30
+ <% end %>
31
+ </div>
32
+
33
+
34
+ <!--Storage-->
35
+ <div class="children_fields xenserver-raw" id="xenserver-storage" style="<%= hide_raw %>">
36
+ <%= new_child_fields_template(f, :VBDs, {
37
+ :object => compute_resource.new_volume,
38
+ :partial => 'compute_resources_vms/form/volume', :form_builder_attrs => { :compute_resource => compute_resource } }) %>
39
+ <%= field_set_tag 'Storage', :id => 'storage_volumes', :title => _('Storage') do -%>
40
+ <%= f.fields_for :VBDs do |i| %>
41
+ <%= render 'compute_resources_vms/form/volume', :f => i, :compute_resource => compute_resource %>
42
+ <% end -%>
43
+ <% end -%>
44
+ </div>
45
+
46
+ <div class="children_fields" id="xenserver-network" style="<%= hide_raw %>">
47
+ <%= field_set_tag 'Network interfaces', :id => 'network_interfaces', :title => _('Networks') do -%>
48
+ <%= f.fields_for :VIFs do |i| %>
49
+ <%= render 'compute_resources_vms/form/network', :f => i, :compute_resource => compute_resource %>
50
+ <% end -%>
51
+ <% end -%>
52
+ </div>
53
+
54
+ <% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
55
+ <%= checkbox_f f, :start, { :checked => (checked == '1'), :help_inline => _('Power ON this machine') } if new %>
56
+
57
+
58
+ <script type="text/javascript">
59
+
60
+ $(document).off('change.xenserver', '#host_compute_attributes_custom_template_name');
61
+ $(document).on('change.xenserver', '#host_compute_attributes_custom_template_name', function (data) {
62
+ if ($('option:selected', data.target).val() == "") {
63
+ $('.xenserver-raw').show(1000)
64
+ } else {
65
+ $('.xenserver-raw').hide(1000)
66
+ }
67
+
68
+ });
69
+
70
+ $(document).off('change.xenserver', '#host_compute_attributes_builtin_template_name');
71
+ $(document).on('change.xenserver', '#host_compute_attributes_builtin_template_name', function (data) {
72
+ $('.xenserver-raw').show(1000)
73
+ })
74
+ </script>
@@ -0,0 +1,128 @@
1
+ <%
2
+ vmdata = { :ifs =>
3
+ { '0' => {
4
+ :ip => '',
5
+ :gateway => '',
6
+ :netmask => ''
7
+ }
8
+ },
9
+ :nameserver1 => '',
10
+ :nameserver2 => '',
11
+ :environment => ''
12
+ }
13
+
14
+
15
+ if params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:xenstore]
16
+ vmdata = params[:host][:compute_attributes][:xenstore]['vm-data']
17
+ end
18
+
19
+ ip = vmdata[:ifs]['0'][:ip]
20
+ gateway = vmdata[:ifs]['0'][:gateway]
21
+ netmask = vmdata[:ifs]['0'][:netmask]
22
+ nameserver1 = vmdata[:nameserver1]
23
+ nameserver2 = vmdata[:nameserver2]
24
+ environment = vmdata[:environment]
25
+
26
+ disabled = 'readonly'
27
+
28
+ %>
29
+
30
+ <div class="children_fields">
31
+
32
+ <div class="fields"/>
33
+ <div class="control-group "><label class="control-label" for="xenstore-vm-data-ifs-0-ip">vm-data/ifs/0/ip</label>
34
+
35
+ <div class="controls">
36
+ <input <%= disabled %> id="xenstore-vm-data-ifs-0-ip" type="text" name="host[compute_attributes][xenstore][vm-data][ifs][0][ip]" class="input" value="<%= ip %>">
37
+ </div>
38
+ </div>
39
+
40
+ <div class="control-group ">
41
+ <label class="control-label" for="xenstore-vm-data-ifs-0-gateway">vm-data/ifs/0/gateway</label>
42
+
43
+ <div class="controls">
44
+ <input <%= disabled %> id="xenstore-vm-data-ifs-0-gateway" type="text" name="host[compute_attributes][xenstore][vm-data][ifs][0][gateway]" class="input" value="<%= gateway %>">
45
+ </div>
46
+ </div>
47
+
48
+ <div class="control-group ">
49
+ <label class="control-label" for="xenstore-vm-data-ifs-0-netmask">vm-data/ifs/0/netmask</label>
50
+
51
+ <div class="controls">
52
+ <input <%= disabled %> id="xenstore-vm-data-ifs-0-netmask" type="text" name="host[compute_attributes][xenstore][vm-data][ifs][0][netmask]" class="input" value="<%= netmask %>">
53
+ </div>
54
+ </div>
55
+
56
+ <div class="control-group ">
57
+ <label class="control-label" for="xenstore-vm-data-nameserver1">vm-data/nameserver1</label>
58
+
59
+ <div class="controls">
60
+ <input <%= disabled %> id="xenstore-vm-data-nameserver1" type="text" name="host[compute_attributes][xenstore][vm-data][nameserver1]" class="input" value="<%= nameserver1 %>">
61
+ </div>
62
+ </div>
63
+
64
+ <div class="control-group ">
65
+ <label class="control-label" for="xenstore-vm-data-nameserver2">vm-data/nameserver2</label>
66
+
67
+ <div class="controls">
68
+ <input <%= disabled %> id="xenstore-vm-data-nameserver2" type="text" name="host[compute_attributes][xenstore][vm-data][nameserver2]" class="input" value="<%= nameserver2 %>">
69
+ </div>
70
+ </div>
71
+
72
+ <div class="control-group ">
73
+ <label class="control-label" for="xenstore-vm-data-environment">vm-data/environment</label>
74
+
75
+ <div class="controls">
76
+ <input <%= disabled %> id="xenstore-vm-data-environment" type="text" name="host[compute_attributes][xenstore][vm-data][environment]" class="input" value="<%= environment %>">
77
+ </div>
78
+ </div>
79
+
80
+ </div>
81
+
82
+
83
+ <script type="text/javascript">
84
+ function autocomplete_xenstore(subnet_id) {
85
+ url = "/subnets/" + subnet_id + "/edit";
86
+ $.get(url, function (data) {
87
+ fields = $('#primary', data);
88
+ $('#xenstore-vm-data-ifs-0-gateway').val($('#subnet_gateway', fields).val());
89
+ $('#xenstore-vm-data-ifs-0-netmask').val($('#subnet_mask', fields).val());
90
+ $('#xenstore-vm-data-nameserver1').val($('#subnet_dns_primary', fields).val());
91
+ $('#xenstore-vm-data-nameserver2').val($('#subnet_dns_secondary', fields).val());
92
+ $('#xenstore-vm-data-ifs-0-ip').val($('#host_ip').val());
93
+ $('#xenstore-vm-data-environment').val($('#host_environment_id option:selected').text())
94
+ })
95
+ }
96
+
97
+ subnet_id = $('#host_subnet_id option:selected').val();
98
+
99
+ if (subnet_id) {
100
+ autocomplete_xenstore(subnet_id)
101
+ }
102
+
103
+ $(document).off('change.xenstore', '#host_subnet_id');
104
+ $(document).on('change.xenstore', '#host_subnet_id', function (data) {
105
+ subnet_id = $('option:selected', data.target).val();
106
+ if (subnet_id) {
107
+ autocomplete_xenstore(subnet_id)
108
+ }
109
+ });
110
+
111
+ $('#xenstore-vm-data-environment').val($('#host_environment_id option:selected').text());
112
+
113
+ $(document).off('change.xenstore', '#host_environment_id');
114
+ $(document).on('change.xenstore', '#host_environment_id', function (data) {
115
+ env = $('option:selected', data.target).text();
116
+ $('#xenstore-vm-data-environment').val(env)
117
+ });
118
+
119
+ $(document).off('click.xenstore', '#compute_resource_tab a');
120
+ $(document).on('click.xenstore', '#compute_resource_tab a', function (data) {
121
+ subnet_id = $('#host_subnet_id option:selected').val();
122
+
123
+ if (subnet_id) {
124
+ autocomplete_xenstore(subnet_id)
125
+ }
126
+ })
127
+
128
+ </script>
@@ -0,0 +1,23 @@
1
+ <table class="table table-bordered" data-table='inline'>
2
+ <thead>
3
+ <tr>
4
+ <th><%= _('Name') -%></th>
5
+ <th><%= _('CPUs') -%></th>
6
+ <th><%= _('Memory') -%></th>
7
+ <th><%= _('Power') -%></th>
8
+ <th><%= _('DomID') -%></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% @vms.each do |vm| -%>
13
+ <tr>
14
+ <td><%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity) %></td>
15
+ <td><%= vm.vcpus_max %></td>
16
+ <td><%= (vm.memory_static_max.to_i / 1073741824).to_s %> GB</td>
17
+ <td><%= vm.power_state %> </td>
18
+ <td><%= vm.domid %></td>
19
+
20
+ </tr>
21
+ <% end -%>
22
+ </tbody>
23
+ </table>
@@ -0,0 +1,17 @@
1
+ <% title @vm.name %>
2
+ <div class='span12'>
3
+ <table class="table table-bordered table-striped">
4
+ <tr>
5
+ <th colspan="2">Properties</th>
6
+ </tr>
7
+
8
+ <%= prop :name %>
9
+ <%= prop :address %>
10
+ <%= prop :memory %>
11
+ <%= prop :uuid %>
12
+ <%= prop :hostname %>
13
+ <%= prop :edition %>
14
+ <%= prop :software_version %>
15
+ <%= prop :name_description %>
16
+ </table>
17
+ </div>
@@ -0,0 +1,3 @@
1
+ require 'foreman_xen/engine'
2
+ module ForemanXen
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'fast_gettext'
2
+ require 'gettext_i18n_rails'
3
+ require 'fog'
4
+
5
+ module ForemanXen
6
+ #Inherit from the Rails module of the parent app (Foreman), not the plugin.
7
+ #Thus, inherits from ::Rails::Engine and not from Rails::Engine
8
+ class Engine < ::Rails::Engine
9
+
10
+ initializer 'foreman_xen.register_gettext', :after => :load_config_initializers do |app|
11
+ locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
12
+ locale_domain = 'foreman-xen'
13
+
14
+ Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
15
+ end
16
+
17
+ initializer 'foreman_xen.register_plugin', :after => :finisher_hook do |app|
18
+ Foreman::Plugin.register :foreman_xen do
19
+ requires_foreman '>= 1.5'
20
+ # Register xen compute resource in foreman
21
+ compute_resource ForemanXen::Xenserver
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ # extend fog xen server and image models.
29
+ require 'fog/xenserver/models/compute/server'
30
+ require File.expand_path('../../../app/models/concerns/fog_extensions/xenserver/server', __FILE__)
31
+ Fog::Compute::XenServer::Server.send(:include, ::FogExtensions::Xenserver::Server)
32
+ end
@@ -0,0 +1,3 @@
1
+ module ForemanXen
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,90 @@
1
+ module ForemanXen
2
+
3
+ class VNCTunnel
4
+ attr_accessor :host, :port
5
+
6
+ def initialize(fullURL)
7
+ @uri = URI(fullURL)
8
+ logger.info(fullURL)
9
+ self.host = 'localhost'
10
+ s = TCPServer.new('127.0.0.1', 0)
11
+ self.port = s.addr[1]
12
+ s.close
13
+ @read_from_server = true
14
+ end
15
+
16
+ def start
17
+ client_srv = TCPServer.new('127.0.0.1', self.port)
18
+ Thread.new do
19
+ req = "CONNECT #{@uri.path}?#{@uri.query} HTTP/1.1\r\n\r\n"
20
+ @srv_socket = TCPSocket.open(@uri.host, 80)
21
+ @srv_socket.print req
22
+ header = @srv_socket.readline
23
+ if header == "HTTP/1.1 200 OK\r\n"
24
+ @srv_socket.each_line do |line|
25
+ break if line == "\r\n"
26
+ end
27
+ listen client_srv
28
+ else
29
+ logger.error "Cannot connect to the console located at #{uri.to_s} reason: #{header}"
30
+ raise "Cannot connect to the console located at #{uri.to_s} reason: #{header}"
31
+ end
32
+ end
33
+ end
34
+
35
+ def logger
36
+ Rails.logger
37
+ end
38
+
39
+ private
40
+
41
+ def listen(client_srv)
42
+ @client_socket = client_srv.accept
43
+ logger.debug 'VNCTunnel Client: client accepted'
44
+
45
+ begin
46
+ while true
47
+ begin
48
+ data = @client_socket.read_nonblock(1024)
49
+ break if data == nil
50
+ @srv_socket.write(data)
51
+ rescue IO::WaitReadable => e
52
+ IO.select([@client_socket])
53
+ retry
54
+ end
55
+ end
56
+ rescue EOFError
57
+ # ignored
58
+ rescue Exception => e
59
+ logger.error "VNCTunnel Client: unexpected exception #{e}"
60
+ ensure
61
+ @read_from_server = false
62
+ @client_socket.close
63
+ @srv_socket.close
64
+ end
65
+ logger.debug 'VNCTunnel Client is stopping'
66
+ end
67
+
68
+ def listen_from_server
69
+ logger.debug 'VNCTunnel Server is listening'
70
+ begin
71
+ while @read_from_server do
72
+ begin
73
+ data = @srv_socket.read_nonblock(1024)
74
+ @client_socket.write(data)
75
+ rescue IO::WaitReadable => e
76
+ if IO.select([@srv_socket], nil, nil, 60) != nil
77
+ retry
78
+ end
79
+ end
80
+ end
81
+ rescue EOFError
82
+ # ignored
83
+ rescue Exception => e
84
+ logger.error "VNCTunnel Server: unexpected exception #{e}"
85
+ end
86
+ logger.debug('VNCTunnel Server is stopping')
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :foreman_xen do
3
+ # # Task goes here
4
+ # end
data/locale/Makefile ADDED
@@ -0,0 +1,6 @@
1
+ #
2
+ # Makefile for PO merging and MO generation. For more info see
3
+ # locale/README in the Foreman Core.
4
+ #
5
+ include ../.foreman_app/locale/Makefile
6
+ DOMAIN = foreman-xen
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ForemanXenTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, ForemanXen
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foreman_xen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michał Piotrowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Provision and manage XEN Server from Foreman.
42
+ email:
43
+ - michal.piotrowski@erlang-solutions.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/models/concerns/fog_extensions/xenserver/server.rb
52
+ - app/models/foreman_xen/xenserver.rb
53
+ - app/views/compute_resources/form/_xenserver.html.erb
54
+ - app/views/compute_resources/show/_xenserver.html.erb
55
+ - app/views/compute_resources_vms/form/_network.html.erb
56
+ - app/views/compute_resources_vms/form/_templates.html.erb
57
+ - app/views/compute_resources_vms/form/_volume.html.erb
58
+ - app/views/compute_resources_vms/form/_xenserver.html.erb
59
+ - app/views/compute_resources_vms/form/_xenstore.html.erb
60
+ - app/views/compute_resources_vms/index/_xenserver.html.erb
61
+ - app/views/compute_resources_vms/show/_xenserver.html.erb
62
+ - lib/foreman_xen.rb
63
+ - lib/foreman_xen/engine.rb
64
+ - lib/foreman_xen/version.rb
65
+ - lib/foreman_xen/vnc_tunnel.rb
66
+ - lib/tasks/foreman_xen_tasks.rake
67
+ - locale/Makefile
68
+ - test/foreman_xen_test.rb
69
+ - test/test_helper.rb
70
+ homepage: http://github.com/theforeman/foreman-xen
71
+ licenses:
72
+ - GPL-3
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Provision and manage XEN Server from Foreman
94
+ test_files:
95
+ - test/test_helper.rb
96
+ - test/foreman_xen_test.rb