Krenair

partial wip oninstanceactioncompletion.php

Jan 22nd, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. class OnInstanceActionComplete extends Maintenance {
  3.     public function __construct() {
  4.         parent::__construct();
  5.         $this->addOption( 'action', 'The action which was taken.', true, true );
  6.         $this->addOption( 'instance', 'Instance name.', true, true );
  7.     }
  8.  
  9.     public function execute() {
  10.         $validActions = array(
  11.             'reboot',
  12.             'build'
  13.         );
  14.  
  15.         if ( !in_array( $this->getOption( 'action' ), $validActions ) ) {
  16.             $this->error( "Unrecognised action.\n", true );
  17.         }
  18.  
  19.         $db = $this->getDB();
  20.         $result = $db->selectRow(
  21.             'openstack_notification_event'
  22.             array( 'event_actor_id', 'event_project' ),
  23.             array(
  24.                 'event_action' => $this->getOption( 'action' ),
  25.                 'event_instance' => $this->getOption( 'instance' )
  26.             ),
  27.             __METHOD__
  28.         );
  29.  
  30.         EchoEvent::create( array(
  31.             'type' => 'osm-instance-' . $this->getOption( 'action' ) . '-completed',
  32.             'title' => Title::newFromText( $result->event_project, NS_NOVA_RESOURCE ),
  33.             'agent' => User::newFromId( $result->event_actor_id ),
  34.             'extra' => array(
  35.                 'instanceName' => $this->getOption( 'instance' ),
  36.                 'projectName' => $result->event_project
  37.             )
  38.         ) );
  39.  
  40.         $db->delete(
  41.             'openstack_notification_event',
  42.             array(
  43.                 'event_action' => $this->getOption( 'action' ),
  44.                 'event_instance' => $this->getOption( 'instance' ),
  45.                 'event_project' => $result->event_project,
  46.                 'event_actor_id' => $result->event_actor_id
  47.             ),
  48.             __METHOD__
  49.         );
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment