Ryan Lane has uploaded a new change for review.
https://gerrit.wikimedia.org/r/60783
Change subject: Add api action for get console output
......................................................................
Add api action for get console output
Use ajax to load the console output from instances and stick it
into a jquery ui dialog. Stack the dialogs next to each other
when showing multiple.
This change also cleans up some of the reboot code and css.
Change-Id: Iaa82800b602ccafd67812752808354044949634a
---
M OpenStackManager.i18n.php
M OpenStackManager.php
M api/ApiNovaInstance.php
M modules/ext.openstack.css
M modules/ext.openstack.js
M special/SpecialNovaInstance.php
6 files changed, 97 insertions(+), 37 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OpenStackManager
refs/changes/83/60783/1
diff --git a/OpenStackManager.i18n.php b/OpenStackManager.i18n.php
index 25af0e4..8e3ab4d 100644
--- a/OpenStackManager.i18n.php
+++ b/OpenStackManager.i18n.php
@@ -134,6 +134,7 @@
'openstackmanager-deleteinstancefailed' => 'Failed to delete instance.',
'openstackmanager-consoleoutput' => 'Console output for $1 ($2)',
'openstackmanager-getconsoleoutput' => 'get console output',
+ 'openstackmanager-getconsoleoutputfailed' => 'Failed to get console
output for instance $1.',
'openstackmanager-createvolume' => 'Create volume',
'openstackmanager-volumename' => 'Volume name',
@@ -715,6 +716,10 @@
* $1 - an alphanumeric instance id for the instance
* $2 - the human-readable name for the same instance',
'openstackmanager-getconsoleoutput' => 'Used as action link label in
Special:NovaInstance.',
+ 'openstackmanager-getconsoleoutputfailed' => 'Notification shown when
ajax call failed after the user clicks the openstackmanager-getconsoleoutput
label.
+
+Parameters:
+* $1 - the human-readable name for the instance.',
'openstackmanager-createvolume' => 'Used as page title and as action
link text, in Special:NovaVolume.',
'openstackmanager-volumename' => 'Used as label for input box and as
heading cell in "resource" table, in Special:NovaVolume.',
'openstackmanager-volumeid' => '"ID" stands for "Identifier".',
diff --git a/OpenStackManager.php b/OpenStackManager.php
index 5954b77..b296144 100644
--- a/OpenStackManager.php
+++ b/OpenStackManager.php
@@ -213,8 +213,8 @@
$wgResourceModules['ext.openstack'] = array(
'styles' => 'ext.openstack.css',
'scripts' => 'ext.openstack.js',
- 'dependencies' => array( 'jquery.spinner' ),
- 'messages' => array( 'openstackmanager-rebootinstancefailed',
'openstackmanager-rebootedinstance' ),
+ 'dependencies' => array( 'jquery.spinner', 'jquery.ui.dialog' ),
+ 'messages' => array( 'openstackmanager-rebootinstancefailed',
'openstackmanager-rebootedinstance', 'openstackmanager-consoleoutput',
'openstackmanager-getconsoleoutputfailed' ),
) + $commonModuleInfo;
$wgAPIModules['novainstance'] = 'ApiNovaInstance';
diff --git a/api/ApiNovaInstance.php b/api/ApiNovaInstance.php
index d2772ac..d2370bc 100644
--- a/api/ApiNovaInstance.php
+++ b/api/ApiNovaInstance.php
@@ -33,6 +33,9 @@
}
$this->getResult()->addValue( null,
$this->getModuleName(), array ( 'instancestate' => 'rebooting' ) );
break;
+ case 'consoleoutput':
+ $output = $this->userNova->getConsoleOutput(
$this->params['instanceid'] );
+ $this->getResult()->addValue( null,
$this->getModuleName(), array ( 'consoleoutput' => $output ) );
}
}
diff --git a/modules/ext.openstack.css b/modules/ext.openstack.css
index 30adad1..26c3475 100644
--- a/modules/ext.openstack.css
+++ b/modules/ext.openstack.css
@@ -1,35 +1,17 @@
.Nova_col {
-max-width: 50em;
-overflow: hidden;
+ max-width: 50em;
+ overflow: hidden;
}
.Nova_cell {
-vertical-align: top;
+ vertical-align: top;
}
-#novaaction {
-font-size: 67%;
+#novaaction {
+ font-size: 67%;
}
-.OpenStack_warning {
-/* @embed */
-background-image: url(images/warning-32.png);
- background-position: center center;
- background-repeat: no-repeat;
- padding: 16px;
- position: relative;
- top: -16px;
-}
-.OpenStack_error {
-/* @embed */
-background-image: url(images/critical-32.png);
- background-position: center center;
- background-repeat: no-repeat;
- padding: 16px;
- position: relative;
- top: -16px;
-}
-.OpenStack_success {
-/* @embed */
-background-image: url(images/tick-32.png);
-display: inline-block;
-height: 20px;
-width: 20px;
+.osm-consoleoutput {
+ white-space: pre-wrap;
+ white-space: -moz-pre-wrap;
+ white-space: -pre-wrap;
+ white-space: -o-pre-wrap;
+ word-wrap: break-word;
}
diff --git a/modules/ext.openstack.js b/modules/ext.openstack.js
index e78353b..5737d59 100644
--- a/modules/ext.openstack.js
+++ b/modules/ext.openstack.js
@@ -1,4 +1,5 @@
( function ( mw, $ ) {
+ var consoledialogs = {};
$( '.novainstanceaction' ).click( function( event ) {
var api = new mw.Api(),
$actionLink = $(this),
@@ -19,7 +20,7 @@
case 'reboot':
event.preventDefault();
$state = $( event.target ).closest( 'tr'
).find( '.novainstancestate' );
- $instancename = $( event.target ).closest( 'tr'
).find( '.novainstancename' );
+ $instancename = $( event.target ).closest( 'tr'
).find( '.novainstancename' ).text();
$.ajax({
url: mw.config.get( 'wgServer' ) +
mw.config.get( 'wgScriptPath' ) + '/api.php?',
data: {
@@ -35,20 +36,87 @@
success: function( data ) {
$spinner.remove();
if ( 'error' in data ) {
- mw.notify( mw.msg(
'openstackmanager-rebootinstancefailed', $instancename.text() ) );
+ mw.notify( mw.msg(
'openstackmanager-rebootinstancefailed', $instancename ) );
} else {
- mw.notify( mw.msg(
'openstackmanager-rebootedinstance', $instancename.text() ) );
+ mw.notify( mw.msg(
'openstackmanager-rebootedinstance', $instancename ) );
$state.text(
data.novainstance.instancestate );
}
$actionLink.show();
},
error: function( data ) {
$spinner.remove();
- mw.notify( mw.msg(
'openstackmanager-rebootinstancefailed', $instancename.text() ) );
+ mw.notify( mw.msg(
'openstackmanager-rebootinstancefailed', $instancename ) );
+ $actionLink.show();
+ }
+ });
+ break;
+ case 'consoleoutput':
+ event.preventDefault();
+ $instancename = $( event.target ).closest( 'tr'
).find( '.novainstancename' ).text();
+ $instanceid = $( event.target ).closest( 'tr'
).find( '.novainstanceid' ).text();
+ $.ajax({
+ url: mw.config.get( 'wgServer' ) +
mw.config.get( 'wgScriptPath' ) + '/api.php?',
+ data: {
+ 'action' : 'novainstance',
+ 'subaction' : 'consoleoutput',
+ 'format' : 'json',
+ 'instanceid' : args.instanceid,
+ 'project' : args.project,
+ 'region' : args.region
+ },
+ dataType: 'json',
+ type: 'POST',
+ success: function( data ) {
+ $spinner.remove();
+ if ( 'error' in data ) {
+ mw.notify( mw.msg(
'openstackmanager-getconsoleoutputfailed', $instancename ) );
+ $actionLink.show();
+ return;
+ }
+ if ( $instanceid in
consoledialogs ) {
+ $actionLink.show();
+ return;
+ }
+ $consoleoutput = $( '<pre>' );
+ consoledialogs[ $instanceid ] =
$consoleoutput;
+ $consoleoutput.attr( 'title',
mw.msg( 'openstackmanager-consoleoutput', $instancename, $instanceid ) );
+ $consoleoutput.addClass(
'osm-consoleoutput' );
+ $consoleoutput.text(
data.novainstance.consoleoutput );
+ if ( $( '.osm-consoleoutput'
).length ) {
+ // position this dialog
next to the last
+ ofloc = $(
'.osm-consoleoutput' ).filter( ':last' );
+ atloc = "right top";
+ myloc = "left top";
+ } else {
+ // this is the first
dialog, position it left bottom
+ ofloc = window;
+ atloc = "left bottom";
+ myloc = "left bottom";
+ }
+ $consoleoutput.dialog({
+ // remove the element,
or it'll screw up positioning
+ close: function( event,
ui ) {
+ $(this).dialog(
'destroy' ).remove();
+ delete
consoledialogs[ $instanceid ];
+ },
+ modal: false,
+ draggable: true,
+ resizable: true,
+ height: 500,
+ width: 400,
+ position: { my: myloc,
at: atloc, of: ofloc },
+ autoOpen: false
+ }).parent().css({ position:
'fixed' }).end().dialog( 'open' );
+ $actionLink.show();
+ },
+ error: function( data ) {
+ $spinner.remove();
+ mw.notify( mw.msg(
'openstackmanager-getconsoleoutputfailed', $instancename ) );
$actionLink.show();
}
});
break;
}
} );
+
}( mediaWiki, jQuery ) );
diff --git a/special/SpecialNovaInstance.php b/special/SpecialNovaInstance.php
index 190b547..a0ca0a6 100644
--- a/special/SpecialNovaInstance.php
+++ b/special/SpecialNovaInstance.php
@@ -528,7 +528,7 @@
foreach ( $instances as $instance ) {
$instanceRow = array();
$this->pushResourceColumn( $instanceRow,
$instance->getInstanceName(), array( 'class' => 'novainstancename' ) );
- $this->pushRawResourceColumn( $instanceRow,
$this->createResourceLink( $instance->getInstanceId() ) );
+ $this->pushRawResourceColumn( $instanceRow,
$this->createResourceLink( $instance->getInstanceId() ), array( 'class' =>
'novainstanceid' ) );
$this->pushResourceColumn( $instanceRow,
$instance->getInstanceState(), array( 'class' => 'novainstancestate' ) );
$this->pushRawResourceColumn( $instanceRow,
$this->createResourceList( $instance->getInstancePrivateIPs() ) );
$this->pushRawResourceColumn( $instanceRow,
$this->createResourceList( $instance->getInstancePublicIPs() ) );
@@ -582,7 +582,9 @@
'project' => $projectName,
'instanceid' =>
$instance->getInstanceOSId(),
'region' => $region
- )
+ ),
+ null,
+ array( 'class' => 'novainstanceaction' )
);
}
$this->pushRawResourceColumn( $instanceRow,
$this->createResourceList( $actions ) );
--
To view, visit https://gerrit.wikimedia.org/r/60783
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa82800b602ccafd67812752808354044949634a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: Ryan Lane <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits