Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/165772
Change subject: Add API list=novainstances
......................................................................
Add API list=novainstances
Change-Id: I9dedd527bd7a4ca611fb1aa85bf73dd202a679f2
---
M OpenStackManager.php
A api/ApiListNovaInstances.php
M nova/OpenStackNovaController.php
M nova/OpenStackNovaProject.php
4 files changed, 79 insertions(+), 1 deletion(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OpenStackManager
refs/changes/72/165772/1
diff --git a/OpenStackManager.php b/OpenStackManager.php
index e341810..bf503df 100644
--- a/OpenStackManager.php
+++ b/OpenStackManager.php
@@ -196,6 +196,7 @@
$wgAutoloadClasses['ApiNovaProjectLimits'] = $dir .
'api/ApiNovaProjectLimits.php';
$wgAutoloadClasses['ApiNovaServiceGroups'] = $dir .
'api/ApiNovaServiceGroups.php';
$wgAutoloadClasses['ApiListNovaProjects'] = $dir .
'api/ApiListNovaProjects.php';
+$wgAutoloadClasses['ApiListNovaInstances'] = $dir .
'api/ApiListNovaInstances.php';
$wgAutoloadClasses['Spyc'] = $dir . 'Spyc.php';
$wgAutoloadClasses['OpenStackManagerNotificationFormatter'] = $dir .
'OpenStackManagerNotificationFormatter.php';
$wgAutoloadClasses['OpenStackManagerEvent'] = $dir .
'OpenStackManagerEvent.php';
@@ -302,6 +303,7 @@
$wgAPIModules['novaservicegroups'] = 'ApiNovaServiceGroups';
$wgAPIModules['novaprojectlimits'] = 'ApiNovaProjectLimits';
$wgAPIListModules['novaprojects'] = 'ApiListNovaProjects';
+$wgAPIListModules['novainstances'] = 'ApiListNovaInstances';
# Schema changes
$wgHooks['LoadExtensionSchemaUpdates'][] = 'efOpenStackSchemaUpdates';
diff --git a/api/ApiListNovaInstances.php b/api/ApiListNovaInstances.php
new file mode 100644
index 0000000..f3a077d
--- /dev/null
+++ b/api/ApiListNovaInstances.php
@@ -0,0 +1,61 @@
+<?php
+
+class ApiListNovaInstances extends ApiQueryGeneratorBase {
+
+ public function __construct( ApiQuery $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'ni' );
+ }
+
+ public function execute() {
+ $this->run();
+ }
+
+ public function executeGenerator( $resultPageSet ) {
+ $this->run();
+ }
+
+ public function run() {
+ $params = $this->extractRequestParams();
+ $project = OpenStackNovaProject::getProjectByName(
$params['project'] );
+ if ( !$project ) {
+ $this->dieUsage( 'Invalid project specified.',
'badproject' );
+ }
+
+ $controller = OpenStackNovaController::newFromUser( new
OpenStackNovaUser() );
+ $controller->setProject( $project );
+ $instances = $controller->getInstances();
+ foreach ( $instances as $instance ) {
+ $info = array(
+ 'name' => $instance->getInstanceName(),
+ 'state' => $instance->getInstanceState(),
+ 'ip' => $instance->getInstancePrivateIPs(),
+ 'id' => $instance->getInstanceId(),
+ 'floatingip' =>
$instance->getInstancePublicIPs(),
+ 'securitygroups' =>
$instance->getSecurityGroups(),
+ 'imageid' => $instance->getImageId(),
+ );
+ $this->getResult()->addValue( array( 'query',
$this->getModuleName() ), null, $info );
+ }
+
+ $this->getResult()->setIndexedTagName_internal( array( 'query',
$this->getModuleName() ), 'instance' );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'project' => array(
+ ApiBase::PARAM_TYPE =>
OpenStackNovaProject::getAllProjectNames(),
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ );
+ }
+
+ public function getDescription() {
+ return array(
+ 'Returns a list of instances for the given project'
+ );
+ }
+
+ public function getExamples() {
+ return 'api.php?action=query&list=novainstance&project=cvn';
+ }
+}
diff --git a/nova/OpenStackNovaController.php b/nova/OpenStackNovaController.php
index 55d337d..df8b74b 100644
--- a/nova/OpenStackNovaController.php
+++ b/nova/OpenStackNovaController.php
@@ -238,7 +238,7 @@
}
/**
- * @return array
+ * @return OpenStackNovaInstance[]
*/
function getInstances() {
$instancesarr = array();
diff --git a/nova/OpenStackNovaProject.php b/nova/OpenStackNovaProject.php
index 9bd8d3b..511b67f 100644
--- a/nova/OpenStackNovaProject.php
+++ b/nova/OpenStackNovaProject.php
@@ -668,6 +668,21 @@
}
/**
+ * Get all project names
+ *
+ * @return string[]
+ */
+ static function getAllProjectNames() {
+ $projects = self::getAllProjects();
+ $names = array();
+ foreach ( $projects as $project ) {
+ $names[] = $project->getName();
+ }
+
+ return $names;
+ }
+
+ /**
* Return all existing projects. Returns an empty array if no projects
exist. This function
* lazy loads the projects. Objects will be returned unloaded. If you
wish to receive more
* than just the project's name, you'll need to call the project's
fetchProjectInfo() function.
--
To view, visit https://gerrit.wikimedia.org/r/165772
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9dedd527bd7a4ca611fb1aa85bf73dd202a679f2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits