http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84645

Revision: 84645
Author:   laner
Date:     2011-03-23 23:52:52 +0000 (Wed, 23 Mar 2011)
Log Message:
-----------
Added a reboot action for instances

Modified Paths:
--------------
    trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
    trunk/extensions/OpenStackManager/OpenStackNovaController.php
    trunk/extensions/OpenStackManager/OpenStackNovaInstance.php
    trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php

Modified: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
===================================================================
--- trunk/extensions/OpenStackManager/OpenStackManager.i18n.php 2011-03-23 
22:35:36 UTC (rev 84644)
+++ trunk/extensions/OpenStackManager/OpenStackManager.i18n.php 2011-03-23 
23:52:52 UTC (rev 84645)
@@ -42,6 +42,7 @@
        'openstackmanager-configure' => 'configure',
        'openstackmanager-modify' => 'modify',
        'openstackmanager-rename' => 'rename',
+       'openstackmanager-reboot' => 'reboot',
        'openstackmanager-actions' => 'Actions',
        'openstackmanager-notloggedin' => 'Login required',
        'openstackmanager-mustbeloggedin' => 'You must be logged in to perform 
this action.',
@@ -89,6 +90,12 @@
        'openstackmanager-imageid' => 'Image ID',
        'openstackmanager-imagetype' => 'Image type',
        'openstackmanager-instancetypelabel' => '{{PLURAL:$1|$1 CPU|$1 CPUs}}, 
$2 MB RAM, $3 GB storage',
+
+       'openstackmanager-rebootinstance' => 'Reboot Instance',
+       'openstackmanager-rebootinstancequestion' => 'Are you sure you wish to 
reboot instance "$1"?',
+       'openstackmanager-rebootedinstance' => 'Rebooted instance $1.',
+       'openstackmanager-rebootinstancefailed' => 'Failed to reboot instance.',
+
        'openstackmanager-launchtime' => 'Launch time',
        'openstackmanager-createinstance' => 'Create a new instance',
        'openstackmanager-invaliddomain' => 'Requested domain is invalid.',
@@ -96,7 +103,7 @@
        'openstackmanager-createfailedldap' => 'Failed to create instance as 
the host could not be added to LDAP.',
        'openstackmanager-createinstancefailed' => 'Failed to create instance.',
        'openstackmanager-backinstancelist' => 'Back to instance list',
-       'openstackmanager-deletedinstance' => 'Deleted instance $1',
+       'openstackmanager-deletedinstance' => 'Deleted instance $1.',
        'openstackmanager-deletedinstance-faileddns' => 'Successfully deleted 
instance, but failed to remove $1 DNS entry.',
        'openstackmanager-modifiedinstance' => 'Successfully modified 
instance.',
        'openstackmanager-modifyinstancefailed' => 'Failed to modify instance.',

Modified: trunk/extensions/OpenStackManager/OpenStackNovaController.php
===================================================================
--- trunk/extensions/OpenStackManager/OpenStackNovaController.php       
2011-03-23 22:35:36 UTC (rev 84644)
+++ trunk/extensions/OpenStackManager/OpenStackNovaController.php       
2011-03-23 23:52:52 UTC (rev 84645)
@@ -574,4 +574,16 @@
                return $response->isOK();
        }
 
+       /**
+        * Reboots an instance
+        *
+        * @param instanceid
+        * @return boolean
+        */
+       function rebootInstance( $instanceid ) {
+               $response = $this->novaConnection->rebootInstances( $instanceid 
);
+
+               return $response->isOK();
+       }
+
 }

Modified: trunk/extensions/OpenStackManager/OpenStackNovaInstance.php
===================================================================
--- trunk/extensions/OpenStackManager/OpenStackNovaInstance.php 2011-03-23 
22:35:36 UTC (rev 84644)
+++ trunk/extensions/OpenStackManager/OpenStackNovaInstance.php 2011-03-23 
23:52:52 UTC (rev 84645)
@@ -188,7 +188,26 @@
 
                $title = Title::newFromText( $this->getInstanceId(), 
NS_NOVA_RESOURCE );
                $article = new Article( $title );
-               $format = "{{Nova 
Resource|resourcetype=instance|name=%s|reservationid=%s|instanceid={{PAGENAME}}|privateip=%s|publicip=%s|instancestate=%s|instancetype=%s|imageid=%s|project=%s|availabilityzone=%s|region=%s|securitygroups=%s|launchtime=%s|fqdn=%s|puppetclass=%s|puppetvar=%s}}";
+               $format = <<<RESOURCEINFO
+{{Nova Resource
+|Resource Type=instance
+|Instance Name=%s
+|Reservation Id=%s
+|Instance Id={{PAGENAME}}
+|Private IP=%s
+|Public IP=%s
+|Instance State=%s
+|Instance Type=%s
+|Image Id=%s
+|Project=%s
+|Availability Zone=%s
+|Region=%s
+|Security Group=%s
+|Launch Time=%s
+|FQDN=%s
+|Puppet Class=%s
+|Puppet Var=%s}}
+RESOURCEINFO;
                $host = $this->getHost();
                $puppetinfo = $host->getPuppetConfiguration();
                if ( $puppetinfo['puppetclass'] ) {
@@ -225,7 +244,7 @@
                        $puppetclasses,
                        $puppetvars
                );
-               $article->doEdit( $text, '', EDIT_SUPPRESS_RC );
+               $article->doEdit( $text, '' );
        }
 
        function deleteArticle() {
@@ -237,8 +256,7 @@
 
                $title = Title::newFromText( $this->getInstanceId(), 
NS_NOVA_RESOURCE );
                $article = new Article( $title );
-               $suppress = Revision::DELETED_TEXT && Revision::DELETED_COMMENT 
&& Revision::DELETED_USER && Revision::DELETED_RESTRICTED;
-               $article->doDeleteArticle( '', $suppress );
+               $article->doDeleteArticle( '' );
        }
 
 }

Modified: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php
===================================================================
--- trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php   
2011-03-23 22:35:36 UTC (rev 84644)
+++ trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php   
2011-03-23 23:52:52 UTC (rev 84645)
@@ -54,6 +54,12 @@
                                return true;
                        }
                        $this->configureInstance();
+               } else if ( $action == "reboot" ) {
+                       if ( ! $this->userLDAP->inProject( $project ) ) {
+                               $this->notInProject();
+                               return true;
+                       }
+                       $this->rebootInstance();
                } else if ( $action == "consoleoutput" ) {
                        if ( ! $this->userLDAP->inProject( $project ) ) {
                                $this->notInProject();
@@ -378,6 +384,48 @@
        /**
         * @return bool
         */
+       function rebootInstance() {
+               global $wgOut, $wgRequest;
+
+               $this->setHeaders();
+               $wgOut->setPagetitle( wfMsg( 'openstackmanager-rebootinstance' 
) );
+
+               $project = $wgRequest->getText( 'project' );
+               if ( ! $this->userLDAP->inRole( 'sysadmin', $project ) ) {
+                       $this->notInRole( 'sysadmin' );
+                       return false;
+               }
+               $instanceid = $wgRequest->getText( 'instanceid' );
+               if ( ! $wgRequest->wasPosted() ) {
+                       $wgOut->addWikiMsg( 
'openstackmanager-rebootinstancequestion', $instanceid );
+               }
+               $instanceInfo = array();
+               $instanceInfo['instanceid'] = array(
+                       'type' => 'hidden',
+                       'default' => $instanceid,
+                       'name' => 'instanceid',
+               );
+               $instanceInfo['project'] = array(
+                       'type' => 'hidden',
+                       'default' => $project,
+                       'name' => 'project',
+               );
+               $instanceInfo['action'] = array(
+                       'type' => 'hidden',
+                       'default' => 'reboot',
+                       'name' => 'action',
+               );
+               $instanceForm = new SpecialNovaInstanceForm( $instanceInfo, 
'openstackmanager-novainstance' );
+               $instanceForm->setTitle( SpecialPage::getTitleFor( 
'NovaInstance' ) );
+               $instanceForm->setSubmitID( 
'novainstance-form-deleteinstancesubmit' );
+               $instanceForm->setSubmitCallback( array( $this, 
'tryRebootSubmit' ) );
+               $instanceForm->show();
+
+               return true;
+       }
+       /**
+        * @return bool
+        */
        function getConsoleOutput() {
                global $wgOut, $wgRequest;
                global $wgUser;
@@ -459,11 +507,12 @@
                                                                           
'project' => $project,
                                                                           
'instanceid' => $instance->getInstanceId() ) );
                        $actions = Html::rawElement( 'li', array(), $link );
-                       #$msg = wfMsgHtml( 'openstackmanager-rename' );
-                       #$actions .= $sk->link( $this->getTitle(), $msg, 
array(),
-                       #                                          array( 
'action' => 'rename',
-                       #                                                       
'project' => $project,
-                       #                                                       
'instanceid' => $instance->getInstanceId() ) );
+                       $msg = wfMsgHtml( 'openstackmanager-reboot' );
+                       $link = $sk->link( $this->getTitle(), $msg, array(),
+                                                                  array( 
'action' => 'reboot',
+                                                                               
'project' => $project,
+                                                                               
'instanceid' => $instance->getInstanceId() ) );
+                       $actions .= Html::rawElement( 'li', array(), $link );
                        $msg = wfMsgHtml( 'openstackmanager-configure' );
                        $link = $sk->link( $this->getTitle(), $msg, array(),
                                                                   array( 
'action' => 'configure',
@@ -591,6 +640,29 @@
         * @param string $entryPoint
         * @return bool
         */
+       function tryRebootSubmit( $formData, $entryPoint = 'internal' ) {
+               global $wgOut, $wgUser;
+
+               $instanceid = $formData['instanceid'];
+               $success = $this->userNova->rebootInstance( $instanceid );
+               if ( $success ) {
+                       $wgOut->addWikiMsg( 
'openstackmanager-rebootedinstance', $instanceid );
+               } else {
+                       $wgOut->addWikiMsg( 
'openstackmanager-rebootinstancefailed' );
+               }
+               $sk = $wgUser->getSkin();
+               $out = '<br />';
+               $out .= $sk->link( $this->getTitle(), wfMsgHtml( 
'openstackmanager-backinstancelist' ) );
+
+               $wgOut->addHTML( $out );
+               return true;
+       }
+
+       /**
+        * @param  $formData
+        * @param string $entryPoint
+        * @return bool
+        */
        function tryConfigureSubmit( $formData, $entryPoint = 'internal' ) {
                global $wgOut, $wgUser;
                global $wgOpenStackManagerPuppetOptions;


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to