foreman_xen 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/controllers/foreman_xen/snapshots_controller.rb +78 -74
- data/app/helpers/xen_compute_helper.rb +35 -34
- data/app/models/concerns/fog_extensions/xenserver/server.rb +7 -6
- data/app/models/concerns/foreman_xen/host_helper_extensions.rb +17 -40
- data/app/models/foreman_xen/xenserver.rb +152 -113
- data/app/views/compute_resources/form/_xenserver.html.erb +2 -2
- data/app/views/compute_resources_vms/form/_hypervisors.html.erb +4 -4
- data/app/views/compute_resources_vms/form/_templates.html.erb +2 -2
- data/app/views/compute_resources_vms/form/_volume.html.erb +1 -1
- data/app/views/compute_resources_vms/form/_xenstore.html.erb +7 -1
- data/app/views/compute_resources_vms/form/xenserver/_base.html.erb +95 -95
- data/app/views/compute_resources_vms/index/_xenserver.html.erb +7 -7
- data/app/views/foreman_xen/snapshots/new.html.erb +14 -14
- data/app/views/foreman_xen/snapshots/show.html.erb +4 -4
- data/config/routes.rb +0 -2
- data/lib/foreman_xen/engine.rb +3 -11
- data/lib/foreman_xen/version.rb +1 -1
- data/lib/foreman_xen/vnc_tunnel.rb +28 -30
- data/test/foreman_xen_test.rb +1 -1
- data/test/test_helper.rb +4 -4
- metadata +5 -19
- data/app/overrides/hosts/show/snapshot_override.html.erb.deface +0 -2
- data/app/overrides/hosts/show/snapshot_override_legacy.html.erb.deface +0 -2
@@ -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,6 +16,7 @@
|
|
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
|
+
|
19
20
|
<div class="col-md-4">
|
20
21
|
<div class="controls">
|
21
22
|
<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] %>">
|
@@ -25,6 +26,7 @@
|
|
25
26
|
|
26
27
|
<div class="form-group">
|
27
28
|
<label class="col-md-2 control-label" for="xenstore-vm-data-ifs-0-gateway">vm-data/ifs/0/gateway</label>
|
29
|
+
|
28
30
|
<div class="col-md-4">
|
29
31
|
<div class="controls">
|
30
32
|
<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] %>">
|
@@ -34,6 +36,7 @@
|
|
34
36
|
|
35
37
|
<div class="form-group">
|
36
38
|
<label class="col-md-2 control-label" for="xenstore-vm-data-ifs-0-netmask">vm-data/ifs/0/netmask</label>
|
39
|
+
|
37
40
|
<div class="col-md-4">
|
38
41
|
<div class="controls">
|
39
42
|
<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] %>">
|
@@ -43,6 +46,7 @@
|
|
43
46
|
|
44
47
|
<div class="form-group">
|
45
48
|
<label class="col-md-2 control-label" for="xenstore-vm-data-nameserver1">vm-data/nameserver1</label>
|
49
|
+
|
46
50
|
<div class="col-md-4">
|
47
51
|
<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] %>">
|
48
52
|
</div>
|
@@ -50,13 +54,15 @@
|
|
50
54
|
|
51
55
|
<div class="form-group">
|
52
56
|
<label class="col-md-2 control-label" for="xenstore-vm-data-nameserver2">vm-data/nameserver2</label>
|
57
|
+
|
53
58
|
<div class="col-md-4">
|
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]
|
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] %>">
|
55
60
|
</div>
|
56
61
|
</div>
|
57
62
|
|
58
63
|
<div class="form-group">
|
59
64
|
<label class="col-md-2 control-label" for="xenstore-vm-data-environment">vm-data/environment</label>
|
65
|
+
|
60
66
|
<div class="col-md-4">
|
61
67
|
<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] %>">
|
62
68
|
</div>
|
@@ -5,18 +5,18 @@
|
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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']
|
16
16
|
else
|
17
17
|
fields_enabled = false
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
-%>
|
21
21
|
|
22
22
|
<!-- VM Initial Settings -->
|
@@ -25,9 +25,9 @@
|
|
25
25
|
<legend>VM Profile</legend>
|
26
26
|
<div class="fields">
|
27
27
|
<!--<%= 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
|
29
|
-
<%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), {:selected
|
30
|
-
<%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), {:selected
|
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' %>
|
31
31
|
</div>
|
32
32
|
</fieldset>
|
33
33
|
</div>
|
@@ -72,53 +72,53 @@
|
|
72
72
|
|
73
73
|
<!-- Startup -->
|
74
74
|
<div class="children_fields" id="xenserver-vm-start" style="<%= hide_raw %>">
|
75
|
-
<%= field_set_tag 'VM Startup Options', :id => '
|
76
|
-
|
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") %>
|
77
77
|
<% end -%>
|
78
78
|
</div>
|
79
79
|
|
80
80
|
<script type="text/javascript">
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
108
108
|
$(document).off('change.xenserver', '#compute_attribute_vm_attrs_custom_template_name');
|
109
109
|
$(document).on('change.xenserver', '#compute_attribute_vm_attrs_custom_template_name', function (data) {
|
110
110
|
if ($('option:selected', data.target).val() == "") {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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');
|
115
115
|
} else {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
+
|
122
122
|
}
|
123
123
|
|
124
124
|
});
|
@@ -126,51 +126,51 @@
|
|
126
126
|
$(document).off('change.xenserver', '#compute_attribute_vm_attrs_builtin_template_name');
|
127
127
|
$(document).on('change.xenserver', '#compute_attribute_vm_attrs_builtin_template_name', function (data) {
|
128
128
|
if ($('option:selected', data.target).val() == "") {
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
// IE and Chrome
|
130
|
+
$('.builtin_templates').prop("disabled", false);
|
131
|
+
$('#compute_attribute_vm_attrs_custom_template_name').removeAttr('disabled');
|
132
132
|
} else {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
+
|
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
|
-
// 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
|
-
$('.buildin_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
|
-
}
|
159
|
-
|
160
160
|
$(document).off('change.xenserver', '#host_compute_attributes_custom_template_name');
|
161
161
|
$(document).on('change.xenserver', '#host_compute_attributes_custom_template_name', function (data) {
|
162
162
|
if ($('option:selected', data.target).val() == "") {
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
163
|
+
$('.xenserver-raw').show(1000);
|
164
|
+
// IE and Chrome
|
165
|
+
$('.builtin_templates').prop("disabled", false);
|
166
|
+
$('#host_compute_attributes_builtin_template_name').removeAttr('disabled');
|
167
167
|
} else {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|
+
|
174
174
|
}
|
175
175
|
|
176
176
|
});
|
@@ -178,15 +178,15 @@
|
|
178
178
|
$(document).off('change.xenserver', '#host_compute_attributes_builtin_template_name');
|
179
179
|
$(document).on('change.xenserver', '#host_compute_attributes_builtin_template_name', function (data) {
|
180
180
|
if ($('option:selected', data.target).val() == "") {
|
181
|
-
|
182
|
-
|
183
|
-
|
181
|
+
// IE and Chrome
|
182
|
+
$('.builtin_templates').prop("disabled", false);
|
183
|
+
$('#host_compute_attributes_custom_template_name').removeAttr('disabled');
|
184
184
|
} else {
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
+
|
190
190
|
}
|
191
191
|
})
|
192
192
|
</script>
|
@@ -10,14 +10,14 @@
|
|
10
10
|
</thead>
|
11
11
|
<tbody>
|
12
12
|
<% @vms.each do |vm| -%>
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
11
|
+
<div class="col-md-8">
|
12
12
|
|
13
|
+
</div>
|
13
14
|
</div>
|
14
15
|
</div>
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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>
|
21
22
|
</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
|
-
|
22
|
+
</tr>
|
23
23
|
<% end %>
|
24
24
|
</tbody>
|
25
25
|
</table>
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
2
|
namespace :foreman_xen do
|
4
3
|
match 'snapshots/:id', :to => 'snapshots#show', :via => 'get'
|
5
4
|
match 'snapshots/:id/revert/:ref', :to => 'snapshots#revert', :via => 'get'
|
@@ -8,5 +7,4 @@ Rails.application.routes.draw do
|
|
8
7
|
|
9
8
|
match 'snapshots/:id/create', :to => 'snapshots#create', :via => 'post'
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
data/lib/foreman_xen/engine.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'fast_gettext'
|
2
2
|
require 'gettext_i18n_rails'
|
3
3
|
require 'fog/xenserver'
|
4
|
-
require 'deface'
|
5
4
|
|
6
5
|
module ForemanXen
|
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
|
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
|
9
8
|
class Engine < ::Rails::Engine
|
10
|
-
|
11
9
|
initializer 'foreman_xen.register_gettext', :after => :load_config_initializers do |app|
|
12
10
|
locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
|
13
11
|
locale_domain = 'foreman-xen'
|
@@ -21,7 +19,6 @@ module ForemanXen
|
|
21
19
|
# Register xen compute resource in foreman
|
22
20
|
compute_resource ForemanXen::Xenserver
|
23
21
|
end
|
24
|
-
|
25
22
|
end
|
26
23
|
|
27
24
|
config.to_prepare do
|
@@ -34,13 +31,8 @@ module ForemanXen
|
|
34
31
|
Fog::Compute::XenServer::Server.send(:include, ::FogExtensions::Xenserver::Server)
|
35
32
|
::HostsHelper.send(:include, ForemanXen::HostHelperExtensions)
|
36
33
|
rescue => e
|
37
|
-
|
34
|
+
Rails.logger.warn "Foreman-Xen: skipping engine hook (#{e})"
|
38
35
|
end
|
39
36
|
end
|
40
|
-
|
41
37
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
38
|
end
|
data/lib/foreman_xen/version.rb
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
class VNCTunnel
|
2
2
|
attr_accessor :host, :port
|
3
|
-
@uri
|
4
|
-
@srv_socket
|
5
|
-
@client_socket
|
3
|
+
@uri = nil
|
4
|
+
@srv_socket = nil
|
5
|
+
@client_socket = nil
|
6
6
|
@read_from_server = nil
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
|
8
|
+
def initialize(full_url)
|
9
|
+
@uri = URI(full_url)
|
10
|
+
logger.info(full_url)
|
10
11
|
self.host = 'localhost'
|
11
|
-
s
|
12
|
+
s = TCPServer.new('127.0.0.1', 0)
|
12
13
|
self.port = s.addr[1]
|
13
14
|
s.close
|
14
15
|
@read_from_server = true
|
15
16
|
end
|
16
17
|
|
17
18
|
def start
|
18
|
-
client_srv = TCPServer.new(
|
19
|
-
thr
|
20
|
-
req
|
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"
|
21
22
|
@srv_socket = TCPSocket.open(@uri.host, 80)
|
22
23
|
@srv_socket.print req
|
23
24
|
header = @srv_socket.readline
|
24
|
-
if header == "HTTP/1.1 200 OK\r\n"
|
25
|
+
if header == "HTTP/1.1 200 OK\r\n"
|
25
26
|
@srv_socket.each_line do |line|
|
26
27
|
break if line == "\r\n"
|
27
28
|
end
|
28
29
|
listen client_srv
|
29
30
|
else
|
30
|
-
logger.error "Cannot connect to the conosle located at #{uri
|
31
|
-
|
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}"
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -39,17 +40,17 @@ class VNCTunnel
|
|
39
40
|
|
40
41
|
private
|
41
42
|
|
42
|
-
def listen
|
43
|
+
def listen(client_srv)
|
43
44
|
@client_socket = client_srv.accept
|
44
|
-
logger.debug
|
45
|
+
logger.debug 'VNCTunnel Client: client accepted'
|
45
46
|
server_listen_thr = Thread.new do
|
46
47
|
listen_from_server
|
47
48
|
end
|
48
49
|
begin
|
49
|
-
|
50
|
+
loop do
|
50
51
|
begin
|
51
52
|
data = @client_socket.read_nonblock(1024)
|
52
|
-
break if data
|
53
|
+
break if data.nil?
|
53
54
|
@srv_socket.write(data)
|
54
55
|
rescue IO::WaitReadable => e
|
55
56
|
IO.select([@client_socket])
|
@@ -64,27 +65,24 @@ class VNCTunnel
|
|
64
65
|
@client_socket.close
|
65
66
|
@srv_socket.close
|
66
67
|
end
|
67
|
-
logger.debug
|
68
|
+
logger.debug 'VNCTunnel Client is stopping'
|
68
69
|
end
|
69
70
|
|
70
71
|
def listen_from_server
|
71
|
-
logger.debug
|
72
|
+
logger.debug 'VNCTunnel Server is listening'
|
72
73
|
begin
|
73
|
-
while @read_from_server
|
74
|
+
while @read_from_server
|
74
75
|
begin
|
75
76
|
data = @srv_socket.read_nonblock(1024)
|
76
77
|
@client_socket.write(data)
|
77
78
|
rescue IO::WaitReadable => e
|
78
|
-
|
79
|
-
retry
|
80
|
-
end
|
79
|
+
retry unless (IO.select([@srv_socket], nil, nil, 60)).nil?
|
81
80
|
end
|
82
81
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
rescue EOFError
|
83
|
+
rescue Exception => e
|
84
|
+
logger.error "VNCTunnel Server: unexpected exception #{e}"
|
85
|
+
end
|
86
|
+
logger.debug('VNCTunnel Server is stopping')
|
88
87
|
end
|
89
|
-
|
90
|
-
end
|
88
|
+
end
|