foreman_xen 0.1.8 → 0.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/Rakefile +1 -1
- data/app/controllers/foreman_xen/snapshots_controller.rb +74 -78
- data/app/helpers/xen_compute_helper.rb +45 -42
- data/app/models/concerns/fog_extensions/xenserver/server.rb +6 -7
- data/app/models/concerns/foreman_xen/host_helper_extensions.rb +40 -17
- data/app/models/foreman_xen/xenserver.rb +113 -153
- data/app/overrides/hosts/show/snapshot_override.html.erb.deface +2 -0
- data/app/overrides/hosts/show/snapshot_override_legacy.html.erb.deface +2 -0
- 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 +1 -7
- data/app/views/compute_resources_vms/form/xenserver/_base.html.erb +96 -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 +2 -0
- data/lib/foreman_xen/engine.rb +11 -3
- data/lib/foreman_xen/version.rb +1 -1
- data/lib/foreman_xen/vnc_tunnel.rb +30 -28
- data/test/foreman_xen_test.rb +1 -1
- data/test/test_helper.rb +4 -4
- metadata +20 -6
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class="fields">
|
2
2
|
|
3
|
-
<%= selectable_f f, :sr_uuid, compute_resource.storage_pools.map
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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, {
|
29
|
-
<%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), {
|
30
|
-
<%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), {
|
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 => '
|
76
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
130
|
+
// IE and Chrome
|
131
|
+
$('.buildin_templates').prop("disabled", false);
|
132
|
+
$('#compute_attribute_vm_attrs_custom_template_name').removeAttr('disabled');
|
132
133
|
} else {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
-
|
182
|
-
|
183
|
-
|
182
|
+
// IE and Chrome
|
183
|
+
$('.buildin_templates').prop("disabled", false);
|
184
|
+
$('#host_compute_attributes_custom_template_name').removeAttr('disabled');
|
184
185
|
} else {
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
-
|
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>
|
14
13
|
</div>
|
15
14
|
</div>
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|
data/lib/foreman_xen/engine.rb
CHANGED
@@ -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
|
-
#
|
7
|
-
#
|
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
|
-
|
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
|
data/lib/foreman_xen/version.rb
CHANGED
@@ -1,35 +1,34 @@
|
|
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
|
-
|
10
|
-
logger.info(full_url)
|
7
|
+
def initialize(fullURL)
|
8
|
+
@uri = URI(fullURL)
|
9
|
+
logger.info(fullURL)
|
11
10
|
self.host = 'localhost'
|
12
|
-
s
|
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(
|
20
|
-
thr
|
21
|
-
req
|
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
|
-
|
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
|
42
|
+
def listen client_srv
|
44
43
|
@client_socket = client_srv.accept
|
45
|
-
logger.debug
|
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
|
-
|
49
|
+
while true
|
51
50
|
begin
|
52
51
|
data = @client_socket.read_nonblock(1024)
|
53
|
-
break if data
|
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
|
67
|
+
logger.debug "VNCTunnel Client is stopping"
|
69
68
|
end
|
70
69
|
|
71
70
|
def listen_from_server
|
72
|
-
logger.debug
|
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
|
-
|
78
|
+
if IO.select([@srv_socket], nil, nil, 60) != nil then
|
79
|
+
retry
|
80
|
+
end
|
80
81
|
end
|
81
82
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
89
|
+
|
90
|
+
end
|