Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (66 sloc) 1.71 KB
<?php
require_once "phing/Task.php";
require_once "Service/Scalr.php";
class PhingScalrExecuteScript extends Task {
/**
* Authentication key from scalr
* @var string
*/
private $_key;
/**
* Authentication secret key from scalr
* @var string
*/
private $_secret_key;
/**
* scalr script id
* @var string
*/
private $_script_id;
/**
* scalr farm id
* @var string
*/
private $_farm_id;
/**
* scalr farm role id
* @var string
*/
private $_farm_role_id;
public function setKey($key) {
if(empty($key)) {
throw new BuildException("Make sure you set your authentication key", $this->location);
}
$this->_key = $key;
}
public function setSecretKey($secretKey) {
if(empty($secretKey)) {
throw new BuildException("Make sure you set your authentication secret key", $this->location);
}
$this->_secret_key = $secretKey;
}
public function setScriptId($scriptId) {
if(empty($scriptId)) {
throw new BuildException("Make sure you set a scalr script id", $this->location);
}
$this->_script_id = $scriptId;
}
public function setFarmId($farmId) {
$this->_farm_id = $farmId;
}
public function setFarmRoleId($farmRoleId) {
$this->_farm_role_id = $farmRoleId;
}
/**
* The main entry point method.
*/
public function main() {
$scalrClient = new Service_Scalr($this->_key, $this->_secret_key);
$response = $scalrClient->executeScript($this->_script_id, $this->_farm_id, $this->_farm_role_id);
if ($response->Result==1) {
$this->log('Deployed sucessfully (Transaction ID = ' . $response->TransactionID . ')' );
} else {
$this->log('Failed deploying to (Error Message = ' . $response->Message . ')', Project::MSG_ERR);
}
}
}