Index: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php |
— | — | @@ -29,8 +29,8 @@ |
30 | 30 | return true; |
31 | 31 | } |
32 | 32 | $project = $wgRequest->getVal( 'project' ); |
33 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
34 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 33 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 34 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
35 | 35 | $adminCredentials = $wgOpenStackManagerNovaAdminKeys; |
36 | 36 | $this->adminNova = new OpenStackNovaController( $adminCredentials ); |
37 | 37 | |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaSecurityGroup.php |
— | — | @@ -487,8 +487,8 @@ |
488 | 488 | $project = $formData['project']; |
489 | 489 | $groupname = $formData['groupname']; |
490 | 490 | $description = $formData['description']; |
491 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
492 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 491 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 492 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
493 | 493 | $securitygroup = $this->userNova->createSecurityGroup( $groupname, $description ); |
494 | 494 | if ( $securitygroup ) { |
495 | 495 | $wgOut->addWikiMsg( 'openstackmanager-createdsecuritygroup' ); |
— | — | @@ -512,8 +512,8 @@ |
513 | 513 | global $wgOut; |
514 | 514 | |
515 | 515 | $project = $formData['project']; |
516 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
517 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 516 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 517 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
518 | 518 | $securitygroup = $this->adminNova->getSecurityGroup( $formData['groupname'], $project ); |
519 | 519 | if ( !$securitygroup ) { |
520 | 520 | $wgOut->addWikiMsg( 'openstackmanager-nonexistantsecuritygroup' ); |
— | — | @@ -588,8 +588,8 @@ |
589 | 589 | $group = explode( ':', $group ); |
590 | 590 | $groups[] = array( 'groupname' => $group[0], 'project' => $group[1] ); |
591 | 591 | } |
592 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
593 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 592 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 593 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
594 | 594 | $securitygroup = $this->adminNova->getSecurityGroup( $formData['groupname'], $project ); |
595 | 595 | if ( ! $securitygroup ) { |
596 | 596 | $wgOut->addWikiMsg( 'openstackmanager-nonexistantsecuritygroup' ); |
— | — | @@ -636,8 +636,8 @@ |
637 | 637 | $groups[] = array( 'groupname' => $rawgroup[0], 'project' => $rawgroup[1] ); |
638 | 638 | } |
639 | 639 | } |
640 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
641 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 640 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 641 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
642 | 642 | $securitygroup = $this->adminNova->getSecurityGroup( $formData['groupname'], $project ); |
643 | 643 | if ( ! $securitygroup ) { |
644 | 644 | $wgOut->addWikiMsg( 'openstackmanager-nonexistantsecuritygroup' ); |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaAddress.php |
— | — | @@ -61,8 +61,8 @@ |
62 | 62 | $this->notInRole( 'netadmin' ); |
63 | 63 | return false; |
64 | 64 | } |
65 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
66 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 65 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 66 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
67 | 67 | if ( ! $wgRequest->wasPosted() ) { |
68 | 68 | $wgOut->addWikiMsg( 'openstackmanager-allocateaddress-confirm', $project ); |
69 | 69 | } |
— | — | @@ -101,8 +101,8 @@ |
102 | 102 | $this->notInRole( 'netadmin' ); |
103 | 103 | return false; |
104 | 104 | } |
105 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
106 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 105 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 106 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
107 | 107 | $ip = $wgRequest->getText( 'ip' ); |
108 | 108 | if ( ! $wgRequest->wasPosted() ) { |
109 | 109 | $wgOut->addWikiMsg( 'openstackmanager-releaseaddress-confirm', $ip ); |
— | — | @@ -148,8 +148,8 @@ |
149 | 149 | $this->notInRole( 'netadmin' ); |
150 | 150 | return false; |
151 | 151 | } |
152 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
153 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 152 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 153 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
154 | 154 | $instances = $this->userNova->getInstances(); |
155 | 155 | $instance_keys = array(); |
156 | 156 | foreach ( $instances as $instance ) { |
— | — | @@ -204,8 +204,8 @@ |
205 | 205 | $this->notInRole( 'netadmin' ); |
206 | 206 | return false; |
207 | 207 | } |
208 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
209 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 208 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 209 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
210 | 210 | $ip = $wgRequest->getText( 'ip' ); |
211 | 211 | if ( ! $wgRequest->wasPosted() ) { |
212 | 212 | $wgOut->addWikiMsg( 'openstackmanager-disassociateaddress-confirm', $ip ); |
— | — | @@ -309,8 +309,8 @@ |
310 | 310 | $this->notInRole( 'netadmin' ); |
311 | 311 | return false; |
312 | 312 | } |
313 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
314 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 313 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 314 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
315 | 315 | $ip = $wgRequest->getText( 'ip' ); |
316 | 316 | $domain = $wgRequest->getText( 'domain' ); |
317 | 317 | $hostname = $wgRequest->getText( 'hostname' ); |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaProject.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | class SpecialNovaProject extends SpecialNova { |
4 | 4 | |
5 | | - var $userNova, $adminNova; |
| 5 | + var $adminNova; |
6 | 6 | var $userLDAP; |
7 | 7 | |
8 | 8 | function __construct() { |
— | — | @@ -291,6 +291,7 @@ |
292 | 292 | */ |
293 | 293 | function tryCreateSubmit( $formData, $entryPoint = 'internal' ) { |
294 | 294 | global $wgOut; |
| 295 | + global $wgOpenStackManagerDefaultSecurityGroupRules; |
295 | 296 | |
296 | 297 | $success = OpenStackNovaProject::createProject( $formData['projectname'] ); |
297 | 298 | if ( ! $success ) { |
— | — | @@ -299,6 +300,49 @@ |
300 | 301 | } |
301 | 302 | $project = OpenStackNovaProject::getProjectByName( $formData['projectname'] ); |
302 | 303 | $project->editArticle(); |
| 304 | + # Create a default security group for this project, and add configured default rules |
| 305 | + $groupname = 'default'; |
| 306 | + # Change the connection to reference this project |
| 307 | + $this->adminNova->configureConnection( $formData['projectname'] ); |
| 308 | + $this->adminNova->createSecurityGroup( $groupname, '' ); |
| 309 | + foreach ( $wgOpenStackManagerDefaultSecurityGroupRules as $rule ) { |
| 310 | + $fromport = ''; |
| 311 | + $toport = ''; |
| 312 | + $protocol = ''; |
| 313 | + $ranges = array(); |
| 314 | + $groups = array(); |
| 315 | + if ( array_key_exists( 'fromport', $rule ) ) { |
| 316 | + $fromport = $rule['fromport']; |
| 317 | + } |
| 318 | + if ( array_key_exists( 'toport', $rule ) ) { |
| 319 | + $toport = $rule['toport']; |
| 320 | + } |
| 321 | + if ( array_key_exists( 'protocol', $rule ) ) { |
| 322 | + $protocol = $rule['protocol']; |
| 323 | + } |
| 324 | + if ( array_key_exists( 'ranges', $rule ) ) { |
| 325 | + $ranges = $rule['ranges']; |
| 326 | + } |
| 327 | + if ( array_key_exists( 'groups', $rule ) ) { |
| 328 | + foreach ( $rule['groups'] as $group ) { |
| 329 | + if ( !array_key_exists( 'groupname', $group ) ) { |
| 330 | + # TODO: log an error here |
| 331 | + continue; |
| 332 | + } |
| 333 | + if ( array_key_exists( 'project', $group ) ) { |
| 334 | + $groupproject = $group['project']; |
| 335 | + } else { |
| 336 | + # Assume groups with no project defined are |
| 337 | + # referencing this project's group |
| 338 | + $groupproject = $formData['projectname']; |
| 339 | + } |
| 340 | + $groups[] = array( 'groupname' => $group['groupname'], 'project' => $groupproject ); |
| 341 | + } |
| 342 | + } |
| 343 | + $this->adminNova->addSecurityGroupRule( $groupname, $fromport, $toport, $protocol, $ranges, $groups ); |
| 344 | + } |
| 345 | + # Reset connection to default |
| 346 | + $this->adminNova->configureConnection(); |
303 | 347 | $wgOut->addWikiMsg( 'openstackmanager-createdproject' ); |
304 | 348 | $sk = $wgOut->getSkin(); |
305 | 349 | $out = '<br />'; |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaDomain.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | class SpecialNovaDomain extends SpecialNova { |
4 | 4 | |
5 | | - var $userNova, $adminNova; |
| 5 | + var $adminNova; |
6 | 6 | var $userLDAP; |
7 | 7 | |
8 | 8 | function __construct() { |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaVolume.php |
— | — | @@ -29,8 +29,8 @@ |
30 | 30 | return true; |
31 | 31 | } |
32 | 32 | $project = $wgRequest->getVal( 'project' ); |
33 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
34 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 33 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 34 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
35 | 35 | $adminCredentials = $wgOpenStackManagerNovaAdminKeys; |
36 | 36 | $this->adminNova = new OpenStackNovaController( $adminCredentials ); |
37 | 37 | |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaKey.php |
— | — | @@ -49,8 +49,8 @@ |
50 | 50 | $this->notInProject(); |
51 | 51 | return true; |
52 | 52 | } |
53 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
54 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 53 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 54 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $this->setHeaders(); |
— | — | @@ -175,8 +175,8 @@ |
176 | 176 | $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-importkey' ), array(), array( 'action' => 'import' ) ); |
177 | 177 | $projects = $this->userLDAP->getProjects(); |
178 | 178 | foreach ( $projects as $project ) { |
179 | | - $userCredentials = $this->userLDAP->getCredentials( $project ); |
180 | | - $this->userNova = new OpenStackNovaController( $userCredentials ); |
| 179 | + $userCredentials = $this->userLDAP->getCredentials(); |
| 180 | + $this->userNova = new OpenStackNovaController( $userCredentials, $project ); |
181 | 181 | $keypairs = $this->userNova->getKeypairs(); |
182 | 182 | if ( ! $keypairs ) { |
183 | 183 | continue; |
Index: trunk/extensions/OpenStackManager/special/SpecialNovaRole.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | class SpecialNovaRole extends SpecialNova { |
4 | 4 | |
5 | | - var $userNova, $adminNova; |
| 5 | + var $adminNova; |
6 | 6 | var $userLDAP; |
7 | 7 | |
8 | 8 | function __construct() { |
Index: trunk/extensions/OpenStackManager/OpenStackNovaUser.php |
— | — | @@ -35,10 +35,9 @@ |
36 | 36 | * @param string $project |
37 | 37 | * @return array |
38 | 38 | */ |
39 | | - function getCredentials( $project = '' ) { |
| 39 | + function getCredentials() { |
40 | 40 | if ( isset( $this->userInfo[0]['accesskey'] ) ) { |
41 | 41 | $accessKey = $this->userInfo[0]['accesskey'][0]; |
42 | | - $accessKey = $accessKey . ':' . $project; |
43 | 42 | } else { |
44 | 43 | $accessKey = ''; |
45 | 44 | } |
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | # TODO: Make this an abstract class, and make the EC2 API a subclass |
5 | 5 | class OpenStackNovaController { |
6 | 6 | |
| 7 | + var $credentials; |
7 | 8 | var $novaConnection; |
8 | 9 | var $instances, $images, $keypairs, $availabilityZones; |
9 | 10 | var $addresses, $securityGroups; |
— | — | @@ -12,16 +13,29 @@ |
13 | 14 | /** |
14 | 15 | * @param $credentials |
15 | 16 | */ |
16 | | - function __construct( $credentials ) { |
| 17 | + function __construct( $credentials, $project='' ) { |
| 18 | + $this->credentials = $credentials; |
| 19 | + $this->configureConnection( $project ); |
| 20 | + $this->instances = array(); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * @param $project |
| 25 | + * @return null |
| 26 | + */ |
| 27 | + function configureConnection( $project='' ) { |
17 | 28 | global $wgOpenStackManagerNovaDisableSSL, $wgOpenStackManagerNovaServerName, |
18 | | - $wgOpenStackManagerNovaPort, $wgOpenStackManagerNovaResourcePrefix; |
| 29 | + $wgOpenStackManagerNovaPort, $wgOpenStackManagerNovaResourcePrefix, |
| 30 | + $wgOpenStackManagerNovaDefaultProject; |
19 | 31 | |
20 | | - $this->novaConnection = new AmazonEC2( $credentials['accessKey'], $credentials['secretKey'] ); |
| 32 | + if ( $project == '' ) { |
| 33 | + $project = $wgOpenStackManagerNovaDefaultProject; |
| 34 | + } |
| 35 | + $this->novaConnection = new AmazonEC2( $this->credentials['accessKey'] . ':' . $project, $this->credentials['secretKey'] ); |
21 | 36 | $this->novaConnection->disable_ssl( $wgOpenStackManagerNovaDisableSSL ); |
22 | 37 | $this->novaConnection->set_hostname( $wgOpenStackManagerNovaServerName, $wgOpenStackManagerNovaPort ); |
23 | 38 | $this->novaConnection->set_resource_prefix( $wgOpenStackManagerNovaResourcePrefix ); |
24 | 39 | $this->novaConnection->allow_hostname_override(false); |
25 | | - $this->instances = array(); |
26 | 40 | } |
27 | 41 | |
28 | 42 | /** |
Index: trunk/extensions/OpenStackManager/OpenStackManager.php |
— | — | @@ -80,6 +80,7 @@ |
81 | 81 | $wgOpenStackManagerCreateResourcePages = true; |
82 | 82 | $wgOpenStackManagerCreateProjectSALPages = true; |
83 | 83 | $wgOpenStackManagerLDAPUseUidAsNamingAttribute = false; |
| 84 | +$wgOpenStackManagerNovaDefaultProject = ""; |
84 | 85 | |
85 | 86 | $dir = dirname( __FILE__ ) . '/'; |
86 | 87 | |