jenkins-bot has submitted this change and it was merged.
Change subject: AJAXify delete instance action
......................................................................
AJAXify delete instance action
Refactors delete host, delete instance, and moves some logic away
from Special:NovaInstance. Adds an AJAX call for delete in the js
and an API call to match. The delete action requires confirmation
via a jquery ui dialog.
Change-Id: Ie6dd09ce9243cf76ef86c7590306b31a2c15096f
---
M OpenStackManager.i18n.php
M OpenStackManager.php
M api/ApiNovaInstance.php
M modules/ext.openstack.Address.js
M modules/ext.openstack.Instance.js
M nova/OpenStackNovaHost.php
M nova/OpenStackNovaInstance.php
M special/SpecialNovaAddress.php
M special/SpecialNovaInstance.php
9 files changed, 122 insertions(+), 83 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/OpenStackManager.i18n.php b/OpenStackManager.i18n.php
index 73583b4..0f6dbee 100644
--- a/OpenStackManager.i18n.php
+++ b/OpenStackManager.i18n.php
@@ -127,11 +127,11 @@
'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-faileddns' => 'Successfully deleted
instance, but failed to remove $1 DNS entry.',
+ 'openstackmanager-deletedinstance' => 'Deleted instance $1 ($2).',
+ 'openstackmanager-deletedinstance-faileddns' => 'Successfully deleted
instance $1 ($2), but failed to remove its DNS entry.',
'openstackmanager-modifiedinstance' => 'Successfully modified instance
$1 ($2).',
'openstackmanager-modifyinstancefailed' => 'Failed to modify instance.',
- 'openstackmanager-deleteinstancefailed' => 'Failed to delete instance.',
+ 'openstackmanager-deleteinstancefailed' => 'Failed to delete instance
$1 ($2).',
'openstackmanager-consoleoutput' => 'Console output for $1 ($2)',
'openstackmanager-getconsoleoutput' => 'get console output',
'openstackmanager-getconsoleoutputfailed' => 'Failed to get console
output for instance $1.',
@@ -692,6 +692,7 @@
Parameters:
* $1 - instance ID
+* $2 - instance name
See also:
* {{msg-mw|Openstackmanager-deleteinstancefailed}}
@@ -703,7 +704,8 @@
An instance is a virtual machine. In this particular case, a clone of an image
for a virtual machine.
[http://docs.openstack.org/diablo/openstack-compute/starter/content/Introduction-d1e2084.html
More on OpenStack].
Parameters:
-* $1 - the specific DNS name
+* $1 - instance ID
+* $1 - instance Name
See also:
* {{msg-mw|Openstackmanager-deletedinstance}}
@@ -729,6 +731,10 @@
An instance is a virtual machine. In this particular case, a clone of an image
for a virtual machine.
[http://docs.openstack.org/diablo/openstack-compute/starter/content/Introduction-d1e2084.html
More on OpenStack].
+Parameters:
+* $1 - the instance ID
+* $2 - the instance name
+
See also:
* {{msg-mw|Openstackmanager-deletedinstance}}
* {{msg-mw|Openstackmanager-deletedinstance-faileddns}}',
diff --git a/OpenStackManager.php b/OpenStackManager.php
index fd89735..9f13896 100644
--- a/OpenStackManager.php
+++ b/OpenStackManager.php
@@ -235,7 +235,11 @@
'openstackmanager-rebootinstancefailed',
'openstackmanager-rebootedinstance',
'openstackmanager-consoleoutput',
- 'openstackmanager-getconsoleoutputfailed'
+ 'openstackmanager-getconsoleoutputfailed',
+ 'openstackmanager-deletedinstance',
+ 'openstackmanager-deleteinstancefailed',
+ 'openstackmanager-deleteinstance',
+ 'openstackmanager-deleteinstancequestion',
),
'scripts' => array(
'ext.openstack.Instance.js',
diff --git a/api/ApiNovaInstance.php b/api/ApiNovaInstance.php
index 73fd52b..62fc42f 100644
--- a/api/ApiNovaInstance.php
+++ b/api/ApiNovaInstance.php
@@ -28,7 +28,7 @@
switch( $this->params['subaction'] ) {
case 'reboot':
$success = $this->userNova->rebootInstance(
$this->params['instanceid'] );
- if ( ! $success ) {
+ if ( !$success ) {
$this->dieUsage( 'Failed to reboot instance.',
'openstackmanager-rebootinstancefailed' );
}
$instance = $this->userNova->getInstance(
$this->params['instanceid'] );
@@ -40,6 +40,22 @@
$output = $this->userNova->getConsoleOutput(
$this->params['instanceid'] );
$this->getResult()->addValue( null,
$this->getModuleName(), array ( 'consoleoutput' => $output ) );
break;
+ case 'delete':
+ $instanceOSID = $this->params['instanceid'];
+ $instance = $this->userNova->getInstance( $instanceOSID
);
+ if ( !$instance ) {
+ $this->dieUsage( 'The instance requested does
not exist.', 'openstackmanager-nonexistanthost' );
+ }
+ $instancename = $instance->getInstanceName();
+ $result = $instance->deleteInstance( $this->userNova );
+ if ( !$result ) {
+ $this->dieUsage( 'Failed to delete the
instance.', 'openstackmanager-deleteinstancefailed' );
+ }
+ $host = $instance->getHost();
+ if ( $host ) {
+ $host->deleteHost();
+ }
+ break;
}
}
@@ -50,6 +66,7 @@
ApiBase::PARAM_TYPE => array(
'reboot',
'consoleoutput',
+ 'delete',
),
ApiBase::PARAM_REQUIRED => true
),
diff --git a/modules/ext.openstack.Address.js b/modules/ext.openstack.Address.js
index 38d6286..64e405b 100644
--- a/modules/ext.openstack.Address.js
+++ b/modules/ext.openstack.Address.js
@@ -10,6 +10,7 @@
* @param {string} address
* @param {string} region
* @param {string} project
+ * @param {jQuery} $row
* @extends mw.OpenStackInterface
*/
function Address( ipAddr, addressId, region, project, $row ) {
@@ -36,7 +37,6 @@
/**
* Change a link from one state to another.
- * @param {jQuery} $link
* @param {string} fromClass
* @param {string} toClass
* @param {string} linkText Name of a message to use as the new link
text
diff --git a/modules/ext.openstack.Instance.js
b/modules/ext.openstack.Instance.js
index 7e876ba..07b107e 100644
--- a/modules/ext.openstack.Instance.js
+++ b/modules/ext.openstack.Instance.js
@@ -12,6 +12,7 @@
* @param {String} descriptor.name Instance name.
* @param {String} descriptor.project Name of project.
* @param {String} descriptor.region Instance's OpenStack region.
+ * @param {jQuery} $row
*/
function Instance( descriptor, $row ) {
$.extend( true, this, descriptor );
@@ -26,8 +27,12 @@
success : 'openstackmanager-rebootedinstance',
failure : 'openstackmanager-rebootinstancefailed'
},
- consoleoutput : {
- failure : 'openstackmanager-getconsoleoutputfailed'
+ consoleoutput: {
+ failure: 'openstackmanager-getconsoleoutputfailed'
+ },
+ 'delete': {
+ success: 'openstackmanager-deletedinstance',
+ failure: 'openstackmanager-deleteinstancefailed'
}
};
@@ -106,6 +111,31 @@
return deferred.promise();
};
+ Instance.prototype.deleteinstance = function ( params ) {
+ var deferred = $.Deferred(),
+ $table = this.$row.closest( 'table' );
+
+ this.confirm(
+ mw.msg( 'openstackmanager-deleteinstancequestion',
this.name ),
+ function () {
+ this.api( 'delete', params )
+ .done(
+ function () {
+ this.$row.remove();
+ if ( $table.find( 'tr'
).length === 1 ) {
+ $table.remove();
+ }
+ }.bind( this ),
+ deferred.resolve
+ )
+ .fail( deferred.reject );
+ }.bind( this ),
+ deferred.reject
+ );
+
+ return deferred.promise();
+ };
+
/**
* Make an 'action=novainstance' call to the MediaWiki API specifying
this
* instance and the requested subaction. If notification messages are
@@ -118,19 +148,19 @@
var self = this,
messages = self.notifications[subaction],
req = api.post( $.extend( {
- format : 'json',
- action : 'novainstance',
- instanceid : self.osid,
- project : self.project,
- region : self.region,
- token : mw.user.tokens.get( 'editToken' ),
- subaction : subaction
+ format: 'json',
+ action: 'novainstance',
+ instanceid: self.osid,
+ project: self.project,
+ region: self.region,
+ token: mw.user.tokens.get( 'editToken' ),
+ subaction: subaction
}, params ) );
if ( messages !== undefined ) {
req.then(
- this.succeed.bind( this, subaction, this.name ),
- this.fail.bind( this, subaction, this.name )
+ this.succeed.bind( this, subaction, this.name,
this.id ),
+ this.fail.bind( this, subaction, this.name,
this.id )
);
}
@@ -147,6 +177,9 @@
$row = $el.closest( 'tr' ),
instance = new mw.openStack.Instance( $el.data(), $row
);
+ if ( action === 'delete' ) {
+ action = 'deleteinstance';
+ }
if ( !$.isFunction( instance[action] ) ) {
// This action isn't supported!
return;
diff --git a/nova/OpenStackNovaHost.php b/nova/OpenStackNovaHost.php
index 8a47505..910c8ef 100644
--- a/nova/OpenStackNovaHost.php
+++ b/nova/OpenStackNovaHost.php
@@ -536,63 +536,21 @@
}
/**
- * Delete a host based on the host's shortname, and its domain.
+ * Delete this host
*
- * @static
- * @param $hostname String
- * @param $domain OpenStackNovaDomain
- * @return bool
- */
- static function deleteHost( $hostname, $domain ) {
- global $wgAuth;
-
- OpenStackNovaLdapConnection::connect();
-
- $host = OpenStackNovaHost::getHostByName( $hostname, $domain );
- if ( ! $host ) {
- $wgAuth->printDebug( "Failed to delete host $hostname
as the DNS entry does not exist", NONSENSITIVE );
- return false;
- }
- $dn = $host->hostDN;
-
- $success = LdapAuthenticationPlugin::ldap_delete(
$wgAuth->ldapconn, $dn );
- if ( $success ) {
- $domain->updateSOA();
- $wgAuth->printDebug( "Successfully deleted host
$hostname", NONSENSITIVE );
- return true;
- } else {
- $wgAuth->printDebug( "Failed to delete host $hostname",
NONSENSITIVE );
- return false;
- }
- }
-
- /**
- * Deletes a host based on its instanceid.
- *
- * @static
* @param $instanceid
* @return bool
*/
- static function deleteHostByInstanceId( $instanceid ) {
+ function deleteHost() {
global $wgAuth;
- OpenStackNovaLdapConnection::connect();
-
- $host = OpenStackNovaHost::getHostByInstanceId( $instanceid );
- if ( ! $host ) {
- $wgAuth->printDebug( "Failed to delete host $instanceid
as the DNS entry does not exist", NONSENSITIVE );
- return false;
- }
- $dn = $host->hostDN;
- $domain = $host->getDomain();
-
- $success = LdapAuthenticationPlugin::ldap_delete(
$wgAuth->ldapconn, $dn );
+ $success = LdapAuthenticationPlugin::ldap_delete(
$wgAuth->ldapconn, $this->hostDN );
if ( $success ) {
- $domain->updateSOA();
- $wgAuth->printDebug( "Successfully deleted host
$instanceid", NONSENSITIVE );
+ $this->getDomain()->updateSOA();
+ $wgAuth->printDebug( "Successfully deleted host " .
$this->getHostName(), NONSENSITIVE );
return true;
} else {
- $wgAuth->printDebug( "Failed to delete host
$instanceid", NONSENSITIVE );
+ $wgAuth->printDebug( "Failed to delete host " .
$this->getHostName(), NONSENSITIVE );
return false;
}
}
diff --git a/nova/OpenStackNovaInstance.php b/nova/OpenStackNovaInstance.php
index 4b42b77..68215aa 100644
--- a/nova/OpenStackNovaInstance.php
+++ b/nova/OpenStackNovaInstance.php
@@ -23,10 +23,14 @@
function __construct( $apiInstanceResponse, $loadhost = false ) {
$this->instance = $apiInstanceResponse;
if ( $loadhost ) {
- $this->host = OpenStackNovaHost::getHostByInstanceId(
$this->getInstanceId() );
+ $this->loadHost();
} else {
$this->host = null;
}
+ }
+
+ function loadHost() {
+ $this->host = OpenStackNovaHost::getHostByInstanceId(
$this->getInstanceId() );
}
/**
@@ -304,4 +308,16 @@
OpenStackNovaArticle::deleteArticle( $this->getInstanceId() );
}
+ function deleteInstance( $userNova ) {
+ global $wgUser;
+
+ $success = $userNova->terminateInstance(
$this->getInstanceOsId() );
+ if ( !$success ) {
+ return false;
+ }
+ OpenStackManagerEvent::createDeletionEvent(
$this->getInstanceName(), $this->getProject(), $wgUser );
+ $this->deleteArticle();
+ return true;
+ }
+
}
diff --git a/special/SpecialNovaAddress.php b/special/SpecialNovaAddress.php
index 3a60479..c5baffe 100644
--- a/special/SpecialNovaAddress.php
+++ b/special/SpecialNovaAddress.php
@@ -765,7 +765,7 @@
}
} else {
# We need to remove the host entry
- $success = OpenStackNovaHost::deleteHost(
$hostname, $domain );
+ $success = $host->deleteHost();
if ( $success ) {
$outputPage->addWikiMsg(
'openstackmanager-removedhost', $hostname, $ip );
} else {
diff --git a/special/SpecialNovaInstance.php b/special/SpecialNovaInstance.php
index 5e1c0ec..d2aa752 100644
--- a/special/SpecialNovaInstance.php
+++ b/special/SpecialNovaInstance.php
@@ -567,7 +567,10 @@
'action' => 'delete',
'instanceid' =>
$instance->getInstanceOSId(),
'project' => $projectName,
- 'region' => $region )
+ 'region' => $region
+ ),
+ null,
+ $instanceDataAttributes
);
$actions[] = $this->createActionLink(
'openstackmanager-reboot',
@@ -645,7 +648,7 @@
$this->getOutput()->addWikiMsg(
'openstackmanager-createdinstance', $instance->getInstanceID(),
$imageName,
$host->getFullyQualifiedHostName() );
} else {
- $this->userNova->terminateInstance(
$instance->getInstanceId() );
+ $instance->deleteInstance( $this->userNova );
$this->getOutput()->addWikiMsg(
'openstackmanager-createfailedldap' );
}
# TODO: also add puppet
@@ -669,26 +672,28 @@
* @return bool
*/
function tryDeleteSubmit( $formData, $entryPoint = 'internal' ) {
- $instance = $this->userNova->getInstance(
$formData['instanceid'] );
+ $instanceosid = $formData['instanceid'];
+ $instance = $this->userNova->getInstance( $instanceosid );
if ( ! $instance ) {
- $this->getOutput()->addWikiMsg(
'openstackmanager-nonexistanthost' );
- return true;
+ return false;
}
$instancename = $instance->getInstanceName();
- $instanceosid = $instance->getInstanceOSId();
- $instanceproject = $instance->getProject();
$instanceid = $instance->getInstanceId();
- $success = $this->userNova->terminateInstance( $instanceosid );
- if ( $success ) {
- OpenStackManagerEvent::createDeletionEvent(
$instancename, $instanceproject, $this->getUser() );
- $success = OpenStackNovaHost::deleteHostByInstanceId(
$instanceid );
- if ( $success ) {
- $this->getOutput()->addWikiMsg(
'openstackmanager-deletedinstance', $instanceid );
+ $host = $instance->getHost();
+ $result = $instance->deleteInstance( $this->userNova );
+ if ( $result ) {
+ if ( $host ) {
+ $result = $host->deleteHost();
+ if ( $result ) {
+ $this->getOutput()->addWikiMsg(
'openstackmanager-deletedinstance', $instanceid, $instancename );
+ } else {
+ $this->getOutput()->addWikiMsg(
'openstackmanager-deletedinstance-faileddns', $instanceid, $instancename );
+ }
} else {
- $this->getOutput()->addWikiMsg(
'openstackmanager-deletedinstance-faileddns', $instancename, $instanceid );
+ $this->getOutput()->addWikiMsg(
'openstackmanager-deletedinstance', $instanceid, $instancename );
}
} else {
- $this->getOutput()->addWikiMsg(
'openstackmanager-deleteinstancefailed' );
+ $this->getOutput()->addWikiMsg(
'openstackmanager-deleteinstancefailed', $instanceid, $instancename );
}
$out = '<br />';
--
To view, visit https://gerrit.wikimedia.org/r/65557
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie6dd09ce9243cf76ef86c7590306b31a2c15096f
Gerrit-PatchSet: 17
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: Ryan Lane <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Ryan Lane <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits