Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class OnInstanceActionComplete extends Maintenance {
- public function __construct() {
- parent::__construct();
- $this->addOption( 'action', 'The action which was taken.', true, true );
- $this->addOption( 'instance', 'Instance name.', true, true );
- }
- public function execute() {
- $validActions = array(
- 'reboot',
- 'build'
- );
- if ( !in_array( $this->getOption( 'action' ), $validActions ) ) {
- $this->error( "Unrecognised action.\n", true );
- }
- $db = $this->getDB();
- $result = $db->selectRow(
- 'openstack_notification_event'
- array( 'event_actor_id', 'event_project' ),
- array(
- 'event_action' => $this->getOption( 'action' ),
- 'event_instance' => $this->getOption( 'instance' )
- ),
- __METHOD__
- );
- EchoEvent::create( array(
- 'type' => 'osm-instance-' . $this->getOption( 'action' ) . '-completed',
- 'title' => Title::newFromText( $result->event_project, NS_NOVA_RESOURCE ),
- 'agent' => User::newFromId( $result->event_actor_id ),
- 'extra' => array(
- 'instanceName' => $this->getOption( 'instance' ),
- 'projectName' => $result->event_project
- )
- ) );
- $db->delete(
- 'openstack_notification_event',
- array(
- 'event_action' => $this->getOption( 'action' ),
- 'event_instance' => $this->getOption( 'instance' ),
- 'event_project' => $result->event_project,
- 'event_actor_id' => $result->event_actor_id
- ),
- __METHOD__
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment