foreman_xen 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  <div class="fields">
2
2
 
3
- <%= selectable_f f, :sr_uuid, compute_resource.storage_pools.map { |item| [item[:display_name], item[:uuid]] }, { :selected => attribute_map[:volume_selected] }, :class => "span2", :label => _("Storage Repository") %>
3
+ <%= selectable_f f, :sr_uuid, compute_resource.storage_pools.map{ |item| [item[:display_name], item[:uuid]]}, { :selected => attribute_map[:volume_selected] }, :class => "span2", :label => _("Storage Repository") %>
4
4
 
5
5
  <%= text_f f, :physical_size, :class => "input-mini", :label => _("Size (GB)"), :value => attribute_map[:volume_size] %>
6
6
  </div>
@@ -16,7 +16,6 @@
16
16
 
17
17
  <div class="form-group">
18
18
  <label class="col-md-2 control-label" for="xenstore-vm-data-ifs-0-ip">vm-data/ifs/0/ip</label>
19
-
20
19
  <div class="col-md-4">
21
20
  <div class="controls">
22
21
  <input <%= disabled %> id="xenstore-vm-data-ifs-0-ip" type="text" name="host[compute_attributes][xenstore][vm-data][ifs][0][ip]" class="form-control input-mini" value="<%= vmdata[:ifs]['0'][:ip] %>">
@@ -26,7 +25,6 @@
26
25
 
27
26
  <div class="form-group">
28
27
  <label class="col-md-2 control-label" for="xenstore-vm-data-ifs-0-gateway">vm-data/ifs/0/gateway</label>
29
-
30
28
  <div class="col-md-4">
31
29
  <div class="controls">
32
30
  <input <%= disabled %> id="xenstore-vm-data-ifs-0-gateway" type="text" name="host[compute_attributes][xenstore][vm-data][ifs][0][gateway]" class="form-control input-mini" value="<%= vmdata[:ifs]['0'][:gateway] %>">
@@ -36,7 +34,6 @@
36
34
 
37
35
  <div class="form-group">
38
36
  <label class="col-md-2 control-label" for="xenstore-vm-data-ifs-0-netmask">vm-data/ifs/0/netmask</label>
39
-
40
37
  <div class="col-md-4">
41
38
  <div class="controls">
42
39
  <input <%= disabled %> id="xenstore-vm-data-ifs-0-netmask" type="text" name="host[compute_attributes][xenstore][vm-data][ifs][0][netmask]" class="form-control input-mini" value="<%= vmdata[:ifs]['0'][:netmask] %>">
@@ -46,7 +43,6 @@
46
43
 
47
44
  <div class="form-group">
48
45
  <label class="col-md-2 control-label" for="xenstore-vm-data-nameserver1">vm-data/nameserver1</label>
49
-
50
46
  <div class="col-md-4">
51
47
  <input <%= disabled %> id="xenstore-vm-data-nameserver1" type="text" name="host[compute_attributes][xenstore][vm-data][nameserver1]" class="form-control input-mini" value="<%= vmdata[:nameserver1] %>">
52
48
  </div>
@@ -54,15 +50,13 @@
54
50
 
55
51
  <div class="form-group">
56
52
  <label class="col-md-2 control-label" for="xenstore-vm-data-nameserver2">vm-data/nameserver2</label>
57
-
58
53
  <div class="col-md-4">
59
- <input <%= disabled %> id="xenstore-vm-data-nameserver2" type="text" name="host[compute_attributes][xenstore][vm-data][nameserver2]" class="form-control input-mini" value="<%= vmdata[:nameserver2] %>">
54
+ <input <%= disabled %> id="xenstore-vm-data-nameserver2" type="text" name="host[compute_attributes][xenstore][vm-data][nameserver2]" class="form-control input-mini" value="<%= vmdata[:nameserver2] %>">
60
55
  </div>
61
56
  </div>
62
57
 
63
58
  <div class="form-group">
64
59
  <label class="col-md-2 control-label" for="xenstore-vm-data-environment">vm-data/environment</label>
65
-
66
60
  <div class="col-md-4">
67
61
  <input <%= disabled %> id="xenstore-vm-data-environment" type="text" name="host[compute_attributes][xenstore][vm-data][environment]" class="form-control input-mini" value="<%= vmdata[:environment] %>">
68
62
  </div>
@@ -5,18 +5,19 @@
5
5
  if params && params['host'] && params['host']['compute_attributes'] && params['host']['compute_attributes']['custom_template_name'] != ''
6
6
  hide_raw = 'display:none;'
7
7
  end
8
-
8
+
9
9
  if controller_name == 'hosts'
10
- fields_enabled = true
11
- start_enable = true
12
- elsif controller_name == 'compute_attributes'
13
- fields_enabled = true
14
- compute_attributes = compute_resource.compute_profile_attributes_for(params['compute_profile_id'])
15
- name = compute_attributes['name']
10
+ compute_attributes = compute_resource.compute_profile_attributes_for(params['host']['compute_profile_id'])
11
+ fields_enabled = true
12
+ start_enable = true
13
+ elsif controller_name == 'compute_attributes'
14
+ fields_enabled = true
15
+ compute_attributes = compute_resource.compute_profile_attributes_for(params['compute_profile_id'])
16
+ name = compute_attributes['name']
16
17
  else
17
18
  fields_enabled = false
18
19
  end
19
-
20
+
20
21
  -%>
21
22
 
22
23
  <!-- VM Initial Settings -->
@@ -25,9 +26,9 @@
25
26
  <legend>VM Profile</legend>
26
27
  <div class="fields">
27
28
  <!--<%= text_f f, :name, :disabled => !fields_enabled, :value => name, :label => 'Name' if controller_name != 'hosts' %>-->
28
- <%= selectable_f f, :vcpus_max, 1..compute_resource.max_cpu_count, { :selected => attribute_map[:cpu_count] }, :class => 'input-mini', :disabled => !fields_enabled, :label => 'vCPUs' %>
29
- <%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), { :selected => attribute_map[:memory_min] }, :class => 'form-control span2', :disabled => !fields_enabled, :label => 'Memory Min' %>
30
- <%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), { :selected => attribute_map[:memory_max] }, :class => 'form-control span2', :disabled => !fields_enabled, :label => 'Memory Max' %>
29
+ <%= selectable_f f, :vcpus_max, 1..compute_resource.max_cpu_count, {:selected => attribute_map[:cpu_count]}, :class => 'input-mini', :disabled => !fields_enabled, :label => 'vCPUs' %>
30
+ <%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), {:selected => attribute_map[:memory_min]}, :class => 'form-control span2', :disabled => !fields_enabled, :label => 'Memory Min' %>
31
+ <%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), {:selected => attribute_map[:memory_max]}, :class => 'form-control span2', :disabled => !fields_enabled, :label => 'Memory Max' %>
31
32
  </div>
32
33
  </fieldset>
33
34
  </div>
@@ -72,53 +73,53 @@
72
73
 
73
74
  <!-- Startup -->
74
75
  <div class="children_fields" id="xenserver-vm-start" style="<%= hide_raw %>">
75
- <%= field_set_tag 'VM Startup Options', :id => 'vm_startup_options', :title => _('Power ON VM') do -%>
76
- <%= checkbox_f f, :start, :checked => (attribute_map[:power_on] == '1' || start_enable), :label => _("Power ON VM") %>
76
+ <%= field_set_tag 'VM Startup Options', :id => 'vm_starup_options', :title => _('Power ON VM') do -%>
77
+ <%= checkbox_f f, :start, :checked => (compute_attributes['start'] == '1' || start_enable), :label => _("Power ON VM") %>
77
78
  <% end -%>
78
79
  </div>
79
80
 
80
81
  <script type="text/javascript">
81
-
82
- // Check if its a computer resource template then just do not show the form of XenStore
83
- if ($("#compute_attribute_compute_profile_id").length > 0) {
84
- $('#xenserver-xenstore-data').hide(1)
85
- }
86
-
87
- // Check if custom template in use then do now show SR settings
88
- if ($("#compute_attribute_vm_attrs_builtin_template_name").val() == "" && $("#compute_attribute_vm_attrs_custom_template_name").val() != "") {
89
- $('.xenserver-raw').hide(1);
90
- }
91
-
92
- // Check which template are in use
93
- if ($("#compute_attribute_vm_attrs_builtin_template_name").val() != "") {
94
- $('#compute_attribute_vm_attrs_custom_template_name').val($("#compute_attribute_vm_attrs_custom_template_name option:contains('No template')").val());
95
- // IE and Chrome
96
- $('#compute_attribute_vm_attrs_custom_template_name').attr("disabled", 'disabled');
97
- $('.custom_template_name').prop("disabled", true);
98
- }
99
-
100
- if ($("#compute_attribute_vm_attrs_custom_template_name").val() != "") {
101
- $('#compute_attribute_vm_attrs_builtin_template_name').val($("#compute_attribute_vm_attrs_custom_template_name option:contains('No template')").val());
102
- // IE and Chrome
103
- $('#compute_attribute_vm_attrs_builtin_template_name').attr("disabled", 'disabled');
104
- $('.builtin_templates').prop("disabled", true);
105
- }
106
-
107
- // Computer Profile Templates
82
+
83
+ // Check if its a computer resource template then just do not show the form of XenStore
84
+ if ($("#compute_attribute_compute_profile_id").length > 0){
85
+ $('#xenserver-xenstore-data').hide(1)
86
+ }
87
+
88
+ // Check if custom template in use then do now show SR settings
89
+ if ($("#compute_attribute_vm_attrs_builtin_template_name").val() == "" && $("#compute_attribute_vm_attrs_custom_template_name").val() != ""){
90
+ $('.xenserver-raw').hide(1);
91
+ }
92
+
93
+ // Check which template are in use
94
+ if ($("#compute_attribute_vm_attrs_builtin_template_name").val() != "" ){
95
+ $('#compute_attribute_vm_attrs_custom_template_name').val($("#compute_attribute_vm_attrs_custom_template_name option:contains('No template')").val());
96
+ // IE and Chrome
97
+ $('#compute_attribute_vm_attrs_custom_template_name').attr("disabled", 'disabled');
98
+ $('.custom_template_name').prop("disabled", true);
99
+ }
100
+
101
+ if ($("#compute_attribute_vm_attrs_custom_template_name").val() != "" ){
102
+ $('#compute_attribute_vm_attrs_builtin_template_name').val($("#compute_attribute_vm_attrs_custom_template_name option:contains('No template')").val());
103
+ // IE and Chrome
104
+ $('#compute_attribute_vm_attrs_builtin_template_name').attr("disabled", 'disabled');
105
+ $('.buildin_templates').prop("disabled", true);
106
+ }
107
+
108
+ // Computer Profile Templates
108
109
  $(document).off('change.xenserver', '#compute_attribute_vm_attrs_custom_template_name');
109
110
  $(document).on('change.xenserver', '#compute_attribute_vm_attrs_custom_template_name', function (data) {
110
111
  if ($('option:selected', data.target).val() == "") {
111
- $('.xenserver-raw').show(1000);
112
- // IE and Chrome
113
- $('.builtin_templates').prop("disabled", false);
114
- $('#compute_attribute_vm_attrs_builtin_template_name').removeAttr('disabled');
112
+ $('.xenserver-raw').show(1000)
113
+ // IE and Chrome
114
+ $('.buildin_templates').prop("disabled", false);
115
+ $('#compute_attribute_vm_attrs_builtin_template_name').removeAttr('disabled');
115
116
  } else {
116
- $('.xenserver-raw').hide(1000);
117
- $('#compute_attribute_vm_attrs_builtin_template_name').val($("#compute_attribute_vm_attrs_builtin_template_name option:contains('No template')").val());
118
- // IE and Chrome
119
- $('#compute_attribute_vm_attrs_builtin_template_name').attr("disabled", 'disabled');
120
- $('.builtin_templates').prop("disabled", true);
121
-
117
+ $('.xenserver-raw').hide(1000)
118
+ $('#compute_attribute_vm_attrs_builtin_template_name').val($("#compute_attribute_vm_attrs_builtin_template_name option:contains('No template')").val());
119
+ // IE and Chrome
120
+ $('#compute_attribute_vm_attrs_builtin_template_name').attr("disabled", 'disabled');
121
+ $('.buildin_templates').prop("disabled", true);
122
+
122
123
  }
123
124
 
124
125
  });
@@ -126,51 +127,51 @@
126
127
  $(document).off('change.xenserver', '#compute_attribute_vm_attrs_builtin_template_name');
127
128
  $(document).on('change.xenserver', '#compute_attribute_vm_attrs_builtin_template_name', function (data) {
128
129
  if ($('option:selected', data.target).val() == "") {
129
- // IE and Chrome
130
- $('.builtin_templates').prop("disabled", false);
131
- $('#compute_attribute_vm_attrs_custom_template_name').removeAttr('disabled');
130
+ // IE and Chrome
131
+ $('.buildin_templates').prop("disabled", false);
132
+ $('#compute_attribute_vm_attrs_custom_template_name').removeAttr('disabled');
132
133
  } else {
133
- $('#compute_attribute_vm_attrs_custom_template_name').val($("#compute_attribute_vm_attrs_custom_template_name option:contains('No template')").val());
134
- // IE and Chrome
135
- $('#compute_attribute_vm_attrs_custom_template_name').attr("disabled", 'disabled');
136
- $('.custom_template_name').prop("disabled", true);
137
-
134
+ $('#compute_attribute_vm_attrs_custom_template_name').val($("#compute_attribute_vm_attrs_custom_template_name option:contains('No template')").val());
135
+ // IE and Chrome
136
+ $('#compute_attribute_vm_attrs_custom_template_name').attr("disabled", 'disabled');
137
+ $('.custom_template_name').prop("disabled", true);
138
+
138
139
  }
139
140
 
140
- });
141
-
142
-
143
- // Host Profile Forms
144
-
145
- // Check which template are in use
146
- if ($("#host_compute_attributes_custom_template_name").val() != "") {
147
- $('#host_compute_attributes_builtin_template_name').val($("#host_compute_attributes_builtin_template_name option:contains('No template')").val());
148
- // IE and Chrome
149
- $('#host_compute_attributes_builtin_template_name').attr("disabled", 'disabled');
150
- $('.builtin_templates').prop("disabled", true);
151
- }
152
-
153
- if ($("#host_compute_attributes_builtin_template_name").val() != "") {
154
- $('#host_compute_attributes_custom_template_name').val($("#host_compute_attributes_custom_template_name option:contains('No template')").val());
155
- // IE and Chrome
156
- $('#host_compute_attributes_custom_template_name').attr("disabled", 'disabled');
157
- $('.custom_template_name').prop("disabled", true);
158
- }
141
+ })
159
142
 
143
+
144
+ // Host Profile Forms
145
+
146
+ // Check which template are in use
147
+ if ($("#host_compute_attributes_custom_template_name").val() != "" ){
148
+ $('#host_compute_attributes_builtin_template_name').val($("#host_compute_attributes_builtin_template_name option:contains('No template')").val());
149
+ // IE and Chrome
150
+ $('#host_compute_attributes_builtin_template_name').attr("disabled", 'disabled');
151
+ $('.buildin_templates').prop("disabled", true);
152
+ }
153
+
154
+ if ($("#host_compute_attributes_builtin_template_name").val() != "" ){
155
+ $('#host_compute_attributes_custom_template_name').val($("#host_compute_attributes_custom_template_name option:contains('No template')").val());
156
+ // IE and Chrome
157
+ $('#host_compute_attributes_custom_template_name').attr("disabled", 'disabled');
158
+ $('.custom_template_name').prop("disabled", true);
159
+ }
160
+
160
161
  $(document).off('change.xenserver', '#host_compute_attributes_custom_template_name');
161
162
  $(document).on('change.xenserver', '#host_compute_attributes_custom_template_name', function (data) {
162
163
  if ($('option:selected', data.target).val() == "") {
163
- $('.xenserver-raw').show(1000);
164
- // IE and Chrome
165
- $('.builtin_templates').prop("disabled", false);
166
- $('#host_compute_attributes_builtin_template_name').removeAttr('disabled');
164
+ $('.xenserver-raw').show(1000)
165
+ // IE and Chrome
166
+ $('.buildin_templates').prop("disabled", false);
167
+ $('#host_compute_attributes_builtin_template_name').removeAttr('disabled');
167
168
  } else {
168
- $('.xenserver-raw').hide(1000);
169
- $('#host_compute_attributes_builtin_template_name').val($("#host_compute_attributes_builtin_template_name option:contains('No template')").val());
170
- // IE and Chrome
171
- $('#host_compute_attributes_builtin_template_name').attr("disabled", 'disabled');
172
- $('.builtin_templates').prop("disabled", true);
173
-
169
+ $('.xenserver-raw').hide(1000)
170
+ $('#host_compute_attributes_builtin_template_name').val($("#host_compute_attributes_builtin_template_name option:contains('No template')").val());
171
+ // IE and Chrome
172
+ $('#host_compute_attributes_builtin_template_name').attr("disabled", 'disabled');
173
+ $('.buildin_templates').prop("disabled", true);
174
+
174
175
  }
175
176
 
176
177
  });
@@ -178,15 +179,15 @@
178
179
  $(document).off('change.xenserver', '#host_compute_attributes_builtin_template_name');
179
180
  $(document).on('change.xenserver', '#host_compute_attributes_builtin_template_name', function (data) {
180
181
  if ($('option:selected', data.target).val() == "") {
181
- // IE and Chrome
182
- $('.builtin_templates').prop("disabled", false);
183
- $('#host_compute_attributes_custom_template_name').removeAttr('disabled');
182
+ // IE and Chrome
183
+ $('.buildin_templates').prop("disabled", false);
184
+ $('#host_compute_attributes_custom_template_name').removeAttr('disabled');
184
185
  } else {
185
- $('#host_compute_attributes_custom_template_name').val($("#host_compute_attributes_builtin_template_name option:contains('No template')").val());
186
- // IE and Chrome
187
- $('#host_compute_attributes_custom_template_name').attr("disabled", 'disabled');
188
- $('.custom_template_name').prop("disabled", true);
189
-
186
+ $('#host_compute_attributes_custom_template_name').val($("#host_compute_attributes_builtin_template_name option:contains('No template')").val());
187
+ // IE and Chrome
188
+ $('#host_compute_attributes_custom_template_name').attr("disabled", 'disabled');
189
+ $('.custom_template_name').prop("disabled", true);
190
+
190
191
  }
191
192
  })
192
193
  </script>
@@ -10,14 +10,14 @@
10
10
  </thead>
11
11
  <tbody>
12
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>
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
19
 
20
- </tr>
20
+ </tr>
21
21
  <% end -%>
22
22
  </tbody>
23
23
  </table>
@@ -1,23 +1,23 @@
1
1
  <% title _("Create Snapshot") %>
2
2
 
3
3
  <%= form_tag("create", method: "post") do %>
4
- <div class="clearfix">
5
- <div class="form-group">
6
- <%= label_tag 'name', 'Name:', class: 'col-md-2 control-label' %>
7
- <div class="col-md-8">
8
- <%= text_field_tag(:name, nil, class: "form-control") %>
9
- </div>
4
+ <div class="clearfix">
5
+ <div class="form-group">
6
+ <%= label_tag 'name', 'Name:', class: 'col-md-2 control-label' %>
7
+ <div class="col-md-8">
8
+ <%= text_field_tag(:name, nil, class: "form-control") %>
9
+ </div>
10
10
 
11
- <div class="col-md-8">
11
+ <div class="col-md-8">
12
12
 
13
- </div>
14
13
  </div>
15
14
  </div>
16
- <div class="row form-group"></div>
17
- <div class="clearfix">
18
- <div class="form-actions">
19
- <%= link_to("Cancel", "/foreman_xen/snapshots/#{@host.id}", :id => "cancel_button", :class => "btn btn-danger") %>
20
- <%= submit_tag("Create", class: "btn btn-primary") %>
21
- </div>
15
+ </div>
16
+ <div class = "row form-group"></div>
17
+ <div class="clearfix">
18
+ <div class="form-actions">
19
+ <%= link_to("Cancel", "/foreman_xen/snapshots/#{@host.id}", :id => "cancel_button", :class => "btn btn-danger") %>
20
+ <%= submit_tag("Create", class: "btn btn-primary") %>
22
21
  </div>
22
+ </div>
23
23
  <% end %>
@@ -2,7 +2,7 @@
2
2
  <%= title_actions(
3
3
  button_group(link_to("Take Snapshot", "/foreman_xen/snapshots/#{@host.id}/new", :id => "takeSnapshotButton", :class => "btn btn-success"),
4
4
  link_to_if_authorized(_("Back to host"), hash_for_host_path(:id => @host), :title => _("Back to host"), :class => 'btn btn-default')
5
- )) %>
5
+ ) ) %>
6
6
 
7
7
  <table class="table table-hover">
8
8
  <tbody>
@@ -15,11 +15,11 @@
15
15
  <td><%= h "#{snapshot.snapshot_time.to_date} #{snapshot.snapshot_time.to_time} " %></a></td>
16
16
  <td>
17
17
  <div class="form-group">
18
- <%= link_to("Revert", "/foreman_xen/snapshots/#{@host.id}/revert/#{snapshot.reference}", :id => "revertSnapshotButton", :class => "btn btn-danger", data: { confirm: "Confirm revert to #{snapshot.name}? Please note that all changes since the snapshot time will be lost, and the system will be restarted." }) %>
19
- <%= link_to("Delete", "/foreman_xen/snapshots/#{@host.id}/delete/#{snapshot.reference}", :id => "deleteSnapshotButton", :class => "btn btn-danger", data: { confirm: "Delete snapshot #{snapshot.name}?" }) %>
18
+ <%= link_to("Revert", "/foreman_xen/snapshots/#{@host.id}/revert/#{snapshot.reference}", :id => "revertSnapshotButton", :class => "btn btn-danger", data: { confirm: "Confirm revert to #{snapshot.name}? Please note that all changes since the snapshot time will be lost, and the system will be restarted."})%>
19
+ <%= link_to("Delete", "/foreman_xen/snapshots/#{@host.id}/delete/#{snapshot.reference}", :id => "deleteSnapshotButton", :class => "btn btn-danger", data: { confirm: "Delete snapshot #{snapshot.name}?"})%>
20
20
  </div>
21
21
  </td>
22
- </tr>
22
+ </tr>
23
23
  <% end %>
24
24
  </tbody>
25
25
  </table>
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
+
2
3
  namespace :foreman_xen do
3
4
  match 'snapshots/:id', :to => 'snapshots#show', :via => 'get'
4
5
  match 'snapshots/:id/revert/:ref', :to => 'snapshots#revert', :via => 'get'
@@ -7,4 +8,5 @@ Rails.application.routes.draw do
7
8
 
8
9
  match 'snapshots/:id/create', :to => 'snapshots#create', :via => 'post'
9
10
  end
11
+
10
12
  end
@@ -1,11 +1,13 @@
1
1
  require 'fast_gettext'
2
2
  require 'gettext_i18n_rails'
3
3
  require 'fog/xenserver'
4
+ require 'deface'
4
5
 
5
6
  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
7
+ #Inherit from the Rails module of the parent app (Foreman), not the plugin.
8
+ #Thus, inherits from ::Rails::Engine and not from Rails::Engine
8
9
  class Engine < ::Rails::Engine
10
+
9
11
  initializer 'foreman_xen.register_gettext', :after => :load_config_initializers do |app|
10
12
  locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
11
13
  locale_domain = 'foreman-xen'
@@ -19,6 +21,7 @@ module ForemanXen
19
21
  # Register xen compute resource in foreman
20
22
  compute_resource ForemanXen::Xenserver
21
23
  end
24
+
22
25
  end
23
26
 
24
27
  config.to_prepare do
@@ -31,8 +34,13 @@ module ForemanXen
31
34
  Fog::Compute::XenServer::Server.send(:include, ::FogExtensions::Xenserver::Server)
32
35
  ::HostsHelper.send(:include, ForemanXen::HostHelperExtensions)
33
36
  rescue => e
34
- Rails.logger.warn "Foreman-Xen: skipping engine hook (#{e})"
37
+ puts "Foreman-Xen: skipping engine hook (#{e.to_s})"
35
38
  end
36
39
  end
40
+
37
41
  end
42
+
43
+
44
+
45
+
38
46
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanXen
2
- VERSION = '0.1.8'
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,35 +1,34 @@
1
1
  class VNCTunnel
2
2
  attr_accessor :host, :port
3
- @uri = nil
4
- @srv_socket = nil
5
- @client_socket = nil
3
+ @uri = nil
4
+ @srv_socket = nil
5
+ @client_socket = nil
6
6
  @read_from_server = nil
7
-
8
- def initialize(full_url)
9
- @uri = URI(full_url)
10
- logger.info(full_url)
7
+ def initialize(fullURL)
8
+ @uri = URI(fullURL)
9
+ logger.info(fullURL)
11
10
  self.host = 'localhost'
12
- s = TCPServer.new('127.0.0.1', 0)
11
+ s = TCPServer.new("127.0.0.1", 0)
13
12
  self.port = s.addr[1]
14
13
  s.close
15
14
  @read_from_server = true
16
15
  end
17
16
 
18
17
  def start
19
- client_srv = TCPServer.new('127.0.0.1', port)
20
- thr = Thread.new do
21
- req = "CONNECT #{@uri.path}?#{@uri.query} HTTP/1.1\r\n\r\n"
18
+ client_srv = TCPServer.new("127.0.0.1", self.port)
19
+ thr = Thread.new do
20
+ req = "CONNECT #{@uri.path}?#{@uri.query} HTTP/1.1\r\n\r\n"
22
21
  @srv_socket = TCPSocket.open(@uri.host, 80)
23
22
  @srv_socket.print req
24
23
  header = @srv_socket.readline
25
- if header == "HTTP/1.1 200 OK\r\n"
24
+ if header == "HTTP/1.1 200 OK\r\n" then
26
25
  @srv_socket.each_line do |line|
27
26
  break if line == "\r\n"
28
27
  end
29
28
  listen client_srv
30
29
  else
31
- logger.error "Cannot connect to the conosle located at #{uri} reason: #{header}"
32
- fail "Cannot connect to the console located at #{uri} reason: #{header}"
30
+ logger.error "Cannot connect to the conosle located at #{uri.to_s} reason: #{header}"
31
+ raise "Cannot connect to the console located at #{uri.to_s} reason: #{header}"
33
32
  end
34
33
  end
35
34
  end
@@ -40,17 +39,17 @@ class VNCTunnel
40
39
 
41
40
  private
42
41
 
43
- def listen(client_srv)
42
+ def listen client_srv
44
43
  @client_socket = client_srv.accept
45
- logger.debug 'VNCTunnel Client: client accepted'
44
+ logger.debug "VNCTunnel Client: client accepted"
46
45
  server_listen_thr = Thread.new do
47
46
  listen_from_server
48
47
  end
49
48
  begin
50
- loop do
49
+ while true
51
50
  begin
52
51
  data = @client_socket.read_nonblock(1024)
53
- break if data.nil?
52
+ break if data == nil
54
53
  @srv_socket.write(data)
55
54
  rescue IO::WaitReadable => e
56
55
  IO.select([@client_socket])
@@ -65,24 +64,27 @@ class VNCTunnel
65
64
  @client_socket.close
66
65
  @srv_socket.close
67
66
  end
68
- logger.debug 'VNCTunnel Client is stopping'
67
+ logger.debug "VNCTunnel Client is stopping"
69
68
  end
70
69
 
71
70
  def listen_from_server
72
- logger.debug 'VNCTunnel Server is listening'
71
+ logger.debug "VNCTunnel Server is listening"
73
72
  begin
74
- while @read_from_server
73
+ while @read_from_server do
75
74
  begin
76
75
  data = @srv_socket.read_nonblock(1024)
77
76
  @client_socket.write(data)
78
77
  rescue IO::WaitReadable => e
79
- retry unless (IO.select([@srv_socket], nil, nil, 60)).nil?
78
+ if IO.select([@srv_socket], nil, nil, 60) != nil then
79
+ retry
80
+ end
80
81
  end
81
82
  end
82
- rescue EOFError
83
- rescue Exception => e
84
- logger.error "VNCTunnel Server: unexpected exception #{e}"
85
- end
86
- logger.debug('VNCTunnel Server is stopping')
83
+ rescue EOFError
84
+ rescue Exception => e
85
+ logger.error "VNCTunnel Server: unexpected exception #{e}"
86
+ end
87
+ logger.debug("VNCTunnel Server is stopping")
87
88
  end
88
- end
89
+
90
+ end