/extensions/OpenStackManager/special/SpecialNovaAddress.php

https://github.com/ChuguluGames/mediawiki-svn · PHP · 670 lines · 555 code · 53 blank · 62 comment · 61 complexity · bf61fb1c40415fa232d13b240dc4b592 MD5 · raw file

  1. <?php
  2. class SpecialNovaAddress extends SpecialNova {
  3. var $adminNova;
  4. var $userNova;
  5. /**
  6. * @var OpenStackNovaUser
  7. */
  8. var $userLDAP;
  9. function __construct() {
  10. parent::__construct( 'NovaAddress' );
  11. }
  12. function execute( $par ) {
  13. global $wgRequest, $wgUser;
  14. global $wgOpenStackManagerNovaAdminKeys;
  15. if ( ! $wgUser->isLoggedIn() ) {
  16. $this->notLoggedIn();
  17. return false;
  18. }
  19. $this->userLDAP = new OpenStackNovaUser();
  20. if ( ! $this->userLDAP->exists() ) {
  21. $this->noCredentials();
  22. return true;
  23. }
  24. $adminCredentials = $wgOpenStackManagerNovaAdminKeys;
  25. $this->adminNova = new OpenStackNovaController( $adminCredentials );
  26. $action = $wgRequest->getVal( 'action' );
  27. if ( $action == "allocate" ) {
  28. $this->allocateAddress();
  29. } elseif ( $action == "release" ) {
  30. $this->releaseAddress();
  31. } elseif ( $action == "associate" ) {
  32. $this->associateAddress();
  33. } elseif ( $action == "disassociate" ) {
  34. $this->disassociateAddress();
  35. } elseif ( $action == "addhost" ) {
  36. $this->addHost();
  37. } elseif ( $action == "removehost" ) {
  38. $this->removehost();
  39. } else {
  40. $this->listAddresses();
  41. }
  42. }
  43. /**
  44. * @return bool
  45. */
  46. function allocateAddress() {
  47. global $wgRequest, $wgOut;
  48. $this->setHeaders();
  49. $wgOut->setPagetitle( wfMsg( 'openstackmanager-allocateaddress' ) );
  50. $project = $wgRequest->getText( 'project' );
  51. if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
  52. $this->notInRole( 'netadmin' );
  53. return false;
  54. }
  55. $userCredentials = $this->userLDAP->getCredentials( $project );
  56. $this->userNova = new OpenStackNovaController( $userCredentials );
  57. if ( ! $wgRequest->wasPosted() ) {
  58. $wgOut->addWikiMsg( 'openstackmanager-allocateaddress-confirm', $project );
  59. }
  60. $addressInfo = array();
  61. $addressInfo['project'] = array(
  62. 'type' => 'hidden',
  63. 'default' => $project,
  64. 'name' => 'project',
  65. );
  66. $addressInfo['action'] = array(
  67. 'type' => 'hidden',
  68. 'default' => 'allocate',
  69. 'name' => 'action',
  70. );
  71. $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
  72. $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
  73. $addressForm->setSubmitID( 'novaaddress-form-allocateaddresssubmit' );
  74. $addressForm->setSubmitCallback( array( $this, 'tryAllocateSubmit' ) );
  75. $addressForm->show();
  76. return true;
  77. }
  78. /**
  79. * @return bool
  80. */
  81. function releaseAddress() {
  82. global $wgOut, $wgRequest;
  83. $this->setHeaders();
  84. $wgOut->setPagetitle( wfMsg( 'openstackmanager-releaseaddress' ) );
  85. $project = $wgRequest->getText( 'project' );
  86. if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
  87. $this->notInRole( 'netadmin' );
  88. return false;
  89. }
  90. $userCredentials = $this->userLDAP->getCredentials( $project );
  91. $this->userNova = new OpenStackNovaController( $userCredentials );
  92. $ip = $wgRequest->getText( 'ip' );
  93. if ( ! $wgRequest->wasPosted() ) {
  94. $wgOut->addWikiMsg( 'openstackmanager-releaseaddress-confirm', $ip );
  95. }
  96. $addressInfo = array();
  97. $addressInfo['project'] = array(
  98. 'type' => 'hidden',
  99. 'default' => $project,
  100. 'name' => 'project',
  101. );
  102. $addressInfo['ip'] = array(
  103. 'type' => 'hidden',
  104. 'default' => $ip,
  105. 'name' => 'ip',
  106. );
  107. $addressInfo['action'] = array(
  108. 'type' => 'hidden',
  109. 'default' => 'release',
  110. 'name' => 'action',
  111. );
  112. $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
  113. $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
  114. $addressForm->setSubmitID( 'novaaddress-form-releaseaddresssubmit' );
  115. $addressForm->setSubmitCallback( array( $this, 'tryReleaseSubmit' ) );
  116. $addressForm->setSubmitText( 'confirm' );
  117. $addressForm->show();
  118. return true;
  119. }
  120. /**
  121. * @return bool
  122. */
  123. function associateAddress() {
  124. global $wgOut, $wgRequest;
  125. $this->setHeaders();
  126. $wgOut->setPagetitle( wfMsg( 'openstackmanager-associateaddress' ) );
  127. $ip = $wgRequest->getText( 'ip' );
  128. $project = $wgRequest->getText( 'project' );
  129. if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
  130. $this->notInRole( 'netadmin' );
  131. return false;
  132. }
  133. $userCredentials = $this->userLDAP->getCredentials( $project );
  134. $this->userNova = new OpenStackNovaController( $userCredentials );
  135. $instances = $this->userNova->getInstances();
  136. $instance_keys = array();
  137. foreach ( $instances as $instance ) {
  138. if ( $instance->getOwner() == $project ) {
  139. $instancename = $instance->getInstanceName();
  140. $instanceid = $instance->getInstanceId();
  141. $instance_keys["$instancename"] = $instanceid;
  142. }
  143. }
  144. $addressInfo = array();
  145. $addressInfo['project'] = array(
  146. 'type' => 'hidden',
  147. 'default' => $project,
  148. 'name' => 'project',
  149. );
  150. $addressInfo['ip'] = array(
  151. 'type' => 'hidden',
  152. 'default' => $ip,
  153. 'name' => 'ip',
  154. );
  155. $addressInfo['instanceid'] = array(
  156. 'type' => 'select',
  157. 'label-message' => 'openstackmanager-instancename',
  158. 'options' => $instance_keys,
  159. 'name' => 'instanceid',
  160. );
  161. $addressInfo['action'] = array(
  162. 'type' => 'hidden',
  163. 'default' => 'associate',
  164. 'name' => 'action',
  165. );
  166. $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
  167. $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
  168. $addressForm->setSubmitID( 'novaaddress-form-releaseaddresssubmit' );
  169. $addressForm->setSubmitCallback( array( $this, 'tryAssociateSubmit' ) );
  170. $addressForm->show();
  171. return true;
  172. }
  173. /**
  174. * @return bool
  175. */
  176. function disassociateAddress() {
  177. global $wgOut, $wgRequest;
  178. $this->setHeaders();
  179. $wgOut->setPagetitle( wfMsg( 'openstackmanager-disassociateaddress' ) );
  180. $project = $wgRequest->getText( 'project' );
  181. if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
  182. $this->notInRole( 'netadmin' );
  183. return false;
  184. }
  185. $userCredentials = $this->userLDAP->getCredentials( $project );
  186. $this->userNova = new OpenStackNovaController( $userCredentials );
  187. $ip = $wgRequest->getText( 'ip' );
  188. if ( ! $wgRequest->wasPosted() ) {
  189. $wgOut->addWikiMsg( 'openstackmanager-disassociateaddress-confirm', $ip );
  190. }
  191. $addressInfo = array();
  192. $addressInfo['project'] = array(
  193. 'type' => 'hidden',
  194. 'default' => $project,
  195. 'name' => 'project',
  196. );
  197. $addressInfo['ip'] = array(
  198. 'type' => 'hidden',
  199. 'default' => $ip,
  200. 'name' => 'ip',
  201. );
  202. $addressInfo['action'] = array(
  203. 'type' => 'hidden',
  204. 'default' => 'disassociate',
  205. 'name' => 'action',
  206. );
  207. $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
  208. $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
  209. $addressForm->setSubmitID( 'novaaddress-form-disassociateaddresssubmit' );
  210. $addressForm->setSubmitCallback( array( $this, 'tryDisassociateSubmit' ) );
  211. $addressForm->setSubmitText( 'confirm' );
  212. $addressForm->show();
  213. return true;
  214. }
  215. /**
  216. * @return bool
  217. */
  218. function addHost() {
  219. global $wgOut, $wgRequest;
  220. $this->setHeaders();
  221. $wgOut->setPagetitle( wfMsg( 'openstackmanager-addhost' ) );
  222. $project = $wgRequest->getText( 'project' );
  223. if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
  224. $this->notInRole( 'netadmin' );
  225. return false;
  226. }
  227. $ip = $wgRequest->getText( 'ip' );
  228. $addressInfo = array();
  229. $addressInfo['project'] = array(
  230. 'type' => 'hidden',
  231. 'default' => $project,
  232. 'name' => 'project',
  233. );
  234. $addressInfo['ip'] = array(
  235. 'type' => 'hidden',
  236. 'default' => $ip,
  237. 'name' => 'ip',
  238. );
  239. $addressInfo['hostname'] = array(
  240. 'type' => 'text',
  241. 'default' => '',
  242. 'validation-callback' => array( $this, 'validateText' ),
  243. 'label-message' => 'openstackmanager-hostname',
  244. 'name' => 'hostname',
  245. );
  246. $domains = OpenStackNovaDomain::getAllDomains( 'public' );
  247. $domain_keys = array();
  248. foreach ( $domains as $domain ) {
  249. $domainname = $domain->getDomainName();
  250. $domain_keys["$domainname"] = $domainname;
  251. }
  252. $addressInfo['domain'] = array(
  253. 'type' => 'select',
  254. 'options' => $domain_keys,
  255. 'label-message' => 'openstackmanager-dnsdomain',
  256. 'name' => 'domain',
  257. );
  258. $addressInfo['action'] = array(
  259. 'type' => 'hidden',
  260. 'default' => 'addhost',
  261. 'name' => 'action',
  262. );
  263. $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
  264. $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
  265. $addressForm->setSubmitID( 'novaaddress-form-addhostsubmit' );
  266. $addressForm->setSubmitCallback( array( $this, 'tryAddHostSubmit' ) );
  267. $addressForm->show();
  268. return true;
  269. }
  270. /**
  271. * @return bool
  272. */
  273. function removeHost() {
  274. global $wgOut, $wgRequest;
  275. $this->setHeaders();
  276. $wgOut->setPagetitle( wfMsg( 'openstackmanager-removehost' ) );
  277. $project = $wgRequest->getText( 'project' );
  278. if ( ! $this->userLDAP->inRole( 'netadmin', $project ) ) {
  279. $this->notInRole( 'netadmin' );
  280. return false;
  281. }
  282. $userCredentials = $this->userLDAP->getCredentials( $project );
  283. $this->userNova = new OpenStackNovaController( $userCredentials );
  284. $ip = $wgRequest->getText( 'ip' );
  285. $domain = $wgRequest->getText( 'domain' );
  286. $hostname = $wgRequest->getText( 'hostname' );
  287. if ( ! $wgRequest->wasPosted() ) {
  288. $wgOut->addWikiMsg( 'openstackmanager-removehost-confirm', $hostname, $ip );
  289. }
  290. $addressInfo = array();
  291. $addressInfo['project'] = array(
  292. 'type' => 'hidden',
  293. 'default' => $project,
  294. 'name' => 'project',
  295. );
  296. $addressInfo['ip'] = array(
  297. 'type' => 'hidden',
  298. 'default' => $ip,
  299. 'name' => 'ip',
  300. );
  301. $addressInfo['domain'] = array(
  302. 'type' => 'hidden',
  303. 'default' => $domain,
  304. 'name' => 'domain',
  305. );
  306. $addressInfo['hostname'] = array(
  307. 'type' => 'hidden',
  308. 'default' => $hostname,
  309. 'name' => 'hostname',
  310. );
  311. $addressInfo['action'] = array(
  312. 'type' => 'hidden',
  313. 'default' => 'removehost',
  314. 'name' => 'action',
  315. );
  316. $addressForm = new SpecialNovaAddressForm( $addressInfo, 'openstackmanager-novaaddress' );
  317. $addressForm->setTitle( SpecialPage::getTitleFor( 'NovaAddress' ) );
  318. $addressForm->setSubmitID( 'novaaddress-form-removehostsubmit' );
  319. $addressForm->setSubmitCallback( array( $this, 'tryRemoveHostSubmit' ) );
  320. $addressForm->setSubmitText( 'confirm' );
  321. $addressForm->show();
  322. return true;
  323. }
  324. /**
  325. * @return bool
  326. */
  327. function listAddresses() {
  328. global $wgOut;
  329. $this->setHeaders();
  330. $wgOut->setPagetitle( wfMsg( 'openstackmanager-addresslist' ) );
  331. $userProjects = $this->userLDAP->getProjects();
  332. $out = '';
  333. $sk = $wgOut->getSkin();
  334. $header = Html::element( 'th', array(), wfMsg( 'openstackmanager-address' ) );
  335. $header .= Html::element( 'th', array(), wfMsg( 'openstackmanager-instanceid' ) );
  336. $header .= Html::element( 'th', array(), wfMsg( 'openstackmanager-instancename' ) );
  337. $header .= Html::element( 'th', array(), wfMsg( 'openstackmanager-hostnames' ) );
  338. $header .= Html::element( 'th', array(), wfMsg( 'openstackmanager-actions' ) );
  339. $addresses = $this->adminNova->getAddresses();
  340. $projectArr = array();
  341. foreach ( $addresses as $address ) {
  342. $ip = $address->getPublicIP();
  343. $instanceid = $address->getInstanceId();
  344. $project = $address->getProject();
  345. $addressOut = Html::element( 'td', array(), $ip );
  346. if ( $instanceid ) {
  347. $addressOut .= Html::element( 'td', array(), $instanceid );
  348. $instance = $this->adminNova->getInstance( $instanceid );
  349. $instancename = $instance->getInstanceName();
  350. $addressOut .= Html::element( 'td', array(), $instancename );
  351. } else {
  352. $addressOut .= Html::element( 'td', array(), '' );
  353. $addressOut .= Html::element( 'td', array(), '' );
  354. }
  355. $hosts = OpenStackNovaHost::getHostsByIP( $ip );
  356. if ( $hosts ) {
  357. $hostsOut = '';
  358. $msg = wfMsgHtml( 'openstackmanager-removehost-action' );
  359. foreach ( $hosts as $host ) {
  360. $domain = $host->getDomain();
  361. $fqdns = $host->getAssociatedDomains();
  362. foreach ( $fqdns as $fqdn ) {
  363. $hostname = explode( '.', $fqdn );
  364. $hostname = $hostname[0];
  365. $link = $sk->link( $this->getTitle(), $msg, array(),
  366. array( 'action' => 'removehost', 'ip' => $ip, 'project' => $project, 'domain' => $domain->getDomainName(), 'hostname' => $hostname ) );
  367. $hostOut = htmlentities( $fqdn ) . ' ' . $link;
  368. $hostsOut .= Html::rawElement( 'li', array(), $hostOut );
  369. }
  370. }
  371. $hostsOut = Html::rawElement( 'ul', array(), $hostsOut );
  372. $addressOut .= Html::rawElement( 'td', array(), $hostsOut );
  373. } else {
  374. $addressOut .= Html::element( 'td', array(), '' );
  375. }
  376. $actions = '';
  377. if ( $instanceid ) {
  378. $msg = wfMsgHtml( 'openstackmanager-reassociateaddress' );
  379. } else {
  380. $msg = wfMsgHtml( 'openstackmanager-releaseaddress' );
  381. $link = $sk->link( $this->getTitle(), $msg, array(),
  382. array( 'action' => 'release', 'ip' => $ip, 'project' => $project ) );
  383. $actions = Html::rawElement( 'li', array(), $link );
  384. $msg = wfMsgHtml( 'openstackmanager-associateaddress' );
  385. }
  386. $link = $sk->link( $this->getTitle(), $msg, array(),
  387. array( 'action' => 'associate', 'ip' => $ip, 'project' => $project ) );
  388. $actions .= Html::rawElement( 'li', array(), $link );
  389. if ( $instanceid ) {
  390. $msg = wfMsgHtml( 'openstackmanager-disassociateaddress' );
  391. $link = $sk->link( $this->getTitle(), $msg, array(),
  392. array( 'action' => 'disassociate', 'ip' => $ip, 'project' => $project ) );
  393. $actions .= Html::rawElement( 'li', array(), $link );
  394. }
  395. $msg = wfMsgHtml( 'openstackmanager-addhost' );
  396. $link = $sk->link( $this->getTitle(), $msg, array(),
  397. array( 'action' => 'addhost', 'ip' => $ip, 'project' => $project ) );
  398. $actions .= Html::rawElement( 'li', array(), $link );
  399. $actions = Html::rawElement( 'ul', array(), $actions );
  400. $addressOut .= Html::rawElement( 'td', array(), $actions );
  401. $projectArr["$project"] = Html::rawElement( 'tr', array(), $addressOut );
  402. }
  403. foreach ( $userProjects as $project ) {
  404. $out .= Html::element( 'h2', array(), $project );
  405. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-allocateaddress' ), array(), array( 'action' => 'allocate', 'project' => $project ) );
  406. if ( isset( $projectArr["$project"] ) ) {
  407. $projectOut = $header;
  408. $projectOut .= $projectArr["$project"];
  409. $out .= Html::rawElement( 'table',
  410. array( 'id' => 'novainstancelist', 'class' => 'wikitable sortable collapsible' ), $projectOut );
  411. }
  412. }
  413. $wgOut->addHTML( $out );
  414. return true;
  415. }
  416. /**
  417. * @param $formData
  418. * @param string $entryPoint
  419. * @return bool
  420. */
  421. function tryAllocateSubmit( $formData, $entryPoint = 'internal' ) {
  422. global $wgOut;
  423. $address = $this->userNova->allocateAddress();
  424. if ( ! $address ) {
  425. $wgOut->addWikiMsg( 'openstackmanager-allocateaddressfailed' );
  426. return true;
  427. }
  428. $ip = $address->getPublicIP();
  429. $wgOut->addWikiMsg( 'openstackmanager-allocatedaddress', $ip );
  430. $sk = $wgOut->getSkin();
  431. $out = '<br />';
  432. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backaddresslist' ) );
  433. $wgOut->addHTML( $out );
  434. return true;
  435. }
  436. /**
  437. * @param $formData
  438. * @param string $entryPoint
  439. * @return bool
  440. */
  441. function tryReleaseSubmit( $formData, $entryPoint = 'internal' ) {
  442. global $wgOut;
  443. $ip = $formData['ip'];
  444. #TODO: Instead of throwing an error when host exist or the IP
  445. # is associated, remove all host entries and disassociate the IP
  446. # then release the address
  447. $hosts = OpenStackNovaHost::getHostsByIP( $ip );
  448. if ( $hosts ) {
  449. $wgOut->addWikiMsg( 'openstackmanager-cannotreleaseaddress', $ip );
  450. return true;
  451. }
  452. $address = $this->adminNova->getAddress( $ip );
  453. if ( $address->getInstanceId() ) {
  454. $wgOut->addWikiMsg( 'openstackmanager-cannotreleaseaddress', $ip );
  455. return true;
  456. }
  457. $success = $this->userNova->releaseAddress( $ip );
  458. if ( $success ) {
  459. $wgOut->addWikiMsg( 'openstackmanager-releasedaddress', $ip );
  460. } else {
  461. $wgOut->addWikiMsg( 'openstackmanager-releasedaddressfailed', $ip );
  462. }
  463. $sk = $wgOut->getSkin();
  464. $out = '<br />';
  465. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backaddresslist' ) );
  466. $wgOut->addHTML( $out );
  467. return true;
  468. }
  469. /**
  470. * @param $formData
  471. * @param string $entryPoint
  472. * @return bool
  473. */
  474. function tryAssociateSubmit( $formData, $entryPoint = 'internal' ) {
  475. global $wgOut;
  476. $instanceid = $formData['instanceid'];
  477. $ip = $formData['ip'];
  478. $address = $this->userNova->associateAddress( $instanceid, $ip );
  479. if ( $address ) {
  480. $wgOut->addWikiMsg( 'openstackmanager-associatedaddress', $ip, $instanceid );
  481. } else {
  482. $wgOut->addWikiMsg( 'openstackmanager-associatedaddressfailed', $ip, $instanceid );
  483. }
  484. $sk = $wgOut->getSkin();
  485. $out = '<br />';
  486. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backaddresslist' ) );
  487. $wgOut->addHTML( $out );
  488. return true;
  489. }
  490. /**
  491. * @param $formData
  492. * @param string $entryPoint
  493. * @return bool
  494. */
  495. function tryDisassociateSubmit( $formData, $entryPoint = 'internal' ) {
  496. global $wgOut;
  497. $ip = $formData['ip'];
  498. $address = $this->userNova->disassociateAddress( $ip );
  499. if ( $address ) {
  500. $wgOut->addWikiMsg( 'openstackmanager-disassociatedaddress', $ip );
  501. } else {
  502. $wgOut->addWikiMsg( 'openstackmanager-disassociatedaddressfailed', $ip );
  503. }
  504. $sk = $wgOut->getSkin();
  505. $out = '<br />';
  506. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backaddresslist' ) );
  507. $wgOut->addHTML( $out );
  508. return true;
  509. }
  510. /**
  511. * @param $formData
  512. * @param string $entryPoint
  513. * @return bool
  514. */
  515. function tryAddHostSubmit( $formData, $entryPoint = 'internal' ) {
  516. global $wgOut;
  517. $ip = $formData['ip'];
  518. $project = $formData['project'];
  519. $address = $this->adminNova->getAddress( $ip );
  520. if ( ! $address ) {
  521. $wgOut->addWikiMsg( 'openstackmanager-invalidaddress', $ip );
  522. return true;
  523. }
  524. if ( $address->getProject() != $project ) {
  525. $wgOut->addWikiMsg( 'openstackmanager-invalidaddressforproject', $ip );
  526. return true;
  527. }
  528. $hostname = $formData['hostname'];
  529. $domain = $formData['domain'];
  530. $domain = OpenStackNovaDomain::getDomainByName( $domain );
  531. $hostbyname = OpenStackNovaHost::getHostByName( $hostname, $domain );
  532. $hostbyip = OpenStackNovaHost::getHostByIP( $ip );
  533. if ( $hostbyname ) {
  534. # We need to add an arecord, if the arecord doesn't already exist
  535. $success = $hostbyname->addARecord( $ip );
  536. if ( $success ) {
  537. $wgOut->addWikiMsg( 'openstackmanager-addedhost', $hostname, $ip );
  538. } else {
  539. $wgOut->addWikiMsg( 'openstackmanager-addhostfailed', $ip, $hostname );
  540. }
  541. } elseif ( $hostbyip ) {
  542. # We need to add an associateddomain, if the associateddomain doesn't already exist
  543. $success = $hostbyip->addAssociatedDomain( $hostname . '.' . $domain->getFullyQualifiedDomainName() );
  544. if ( $success ) {
  545. $wgOut->addWikiMsg( 'openstackmanager-addedhost', $hostname, $ip );
  546. } else {
  547. $wgOut->addWikiMsg( 'openstackmanager-addhostfailed', $ip, $hostname );
  548. }
  549. } else {
  550. # This is a new host entry
  551. $host = OpenStackNovaHost::addPublicHost( $hostname, $ip, $domain );
  552. if ( $host ) {
  553. $wgOut->addWikiMsg( 'openstackmanager-addedhost', $hostname, $ip );
  554. } else {
  555. $wgOut->addWikiMsg( 'openstackmanager-addhostfailed', $ip, $hostname );
  556. }
  557. }
  558. $sk = $wgOut->getSkin();
  559. $out = '<br />';
  560. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backaddresslist' ) );
  561. $wgOut->addHTML( $out );
  562. return true;
  563. }
  564. /**
  565. * @param $formData
  566. * @param string $entryPoint
  567. * @return bool
  568. */
  569. function tryRemoveHostSubmit( $formData, $entryPoint = 'internal' ) {
  570. global $wgOut;
  571. $ip = $formData['ip'];
  572. $project = $formData['project'];
  573. $address = $this->adminNova->getAddress( $ip );
  574. if ( ! $address ) {
  575. $wgOut->addWikiMsg( 'openstackmanager-invalidaddress', $ip );
  576. return true;
  577. }
  578. if ( $address->getProject() != $project ) {
  579. $wgOut->addWikiMsg( 'openstackmanager-invalidaddressforproject', $ip );
  580. return true;
  581. }
  582. $hostname = $formData['hostname'];
  583. $domain = $formData['domain'];
  584. $domain = OpenStackNovaDomain::getDomainByName( $domain );
  585. $host = OpenStackNovaHost::getHostByName( $hostname, $domain );
  586. if ( $host ) {
  587. $fqdn = $hostname . '.' . $domain->getFullyQualifiedDomainName();
  588. $records = $host->getAssociatedDomains();
  589. if ( count( $records ) > 1 ) {
  590. # We need to keep the host, but remove the fqdn
  591. $success = $host->deleteAssociatedDomain( $fqdn );
  592. if ( $success ) {
  593. $wgOut->addWikiMsg( 'openstackmanager-removedhost', $hostname, $ip );
  594. } else {
  595. $wgOut->addWikiMsg( 'openstackmanager-removehostfailed', $ip, $hostname );
  596. }
  597. } else {
  598. # We need to remove the host entry
  599. $success = OpenStackNovaHost::deleteHost( $hostname, $domain );
  600. if ( $success ) {
  601. $wgOut->addWikiMsg( 'openstackmanager-removedhost', $hostname, $ip );
  602. } else {
  603. $wgOut->addWikiMsg( 'openstackmanager-removehostfailed', $ip, $hostname );
  604. }
  605. }
  606. } else {
  607. $wgOut->addWikiMsg( 'openstackmanager-nonexistenthost' );
  608. }
  609. $out = '<br />';
  610. $sk = $wgOut->getSkin();
  611. $out .= $sk->link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backaddresslist' ) );
  612. $wgOut->addHTML( $out );
  613. return true;
  614. }
  615. }
  616. class SpecialNovaAddressForm extends HTMLForm {
  617. }