Create() public static method

public static Create ( ServerSnapshotCreateInfo $ServerSnapshotCreateInfo, $isRoleBuilder = false ) : BundleTask
$ServerSnapshotCreateInfo ServerSnapshotCreateInfo
return BundleTask
Exemplo n.º 1
0
 public function ServerImageCreate($ServerID, $RoleName)
 {
     $this->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE);
     $DBServer = DBServer::LoadByID($ServerID);
     // Validate client and server
     if ($DBServer->envId != $this->Environment->id) {
         throw new Exception(sprintf("Server ID #%s not found", $ServerID));
     }
     $this->user->getPermissions()->validate($DBServer);
     //Check for already running bundle on selected instance
     $chk = $this->DB->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($ServerID));
     if ($chk) {
         throw new Exception(sprintf(_("Server '%s' is already synchonizing."), $ServerID));
     }
     //Check is role already synchronizing...
     $chk = $this->DB->GetOne("SELECT server_id FROM bundle_tasks WHERE prototype_role_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($DBServer->GetFarmRoleObject()->RoleID));
     if ($chk && $chk != $DBServer->serverId) {
         try {
             $bDBServer = DBServer::LoadByID($chk);
             if ($bDBServer->farmId == $DBServer->farmId) {
                 throw new Exception(sprintf(_("Role '%s' is already synchonizing."), $DBServer->GetFarmRoleObject()->GetRoleObject()->name));
             }
         } catch (Exception $e) {
         }
     }
     try {
         $DBRole = DBRole::loadByFilter(array("name" => $RoleName, "env_id" => $DBServer->envId));
     } catch (Exception $e) {
     }
     if (!$DBRole) {
         $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($DBServer, $RoleName, SERVER_REPLACEMENT_TYPE::NO_REPLACE, BundleTask::BUNDLETASK_OBJECT_ROLE, 'Bundled via API');
         $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
         $BundleTask->createdById = $this->user->id;
         $BundleTask->createdByEmail = $this->user->getEmail();
         $BundleTask->save();
         $response = $this->CreateInitialResponse();
         $response->BundleTaskID = $BundleTask->id;
         return $response;
     } else {
         throw new Exception(_("Specified role name is already used by another role"));
     }
 }
Exemplo n.º 2
0
 private function onHello($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::TEMPORARY) {
         $bundleTask = BundleTask::LoadById($dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID));
         $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PENDING;
         $bundleTask->Log("Received Hello message from scalarizr on server. Creating image");
         $bundleTask->save();
     }
     if ($dbserver->status == SERVER_STATUS::IMPORTING) {
         switch ($dbserver->platform) {
             case SERVER_PLATFORMS::EC2:
                 $dbserver->SetProperties(array(EC2_SERVER_PROPERTIES::AMIID => $message->awsAmiId, EC2_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EC2_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EC2_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, EC2_SERVER_PROPERTIES::REGION => substr($message->awsAvailZone, 0, -1), SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::EUCALYPTUS:
                 $dbserver->SetProperties(array(EUCA_SERVER_PROPERTIES::EMIID => $message->awsAmiId, EUCA_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EUCA_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EUCA_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::NIMBULA:
                 $dbserver->SetProperties(array(NIMBULA_SERVER_PROPERTIES::NAME => $message->serverName, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::CLOUDSTACK:
                 $dbserver->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID => $message->cloudstack->instanceId, CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $message->cloudstack->availZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::RACKSPACE:
                 $env = $dbserver->GetEnvironmentObject();
                 $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(Modules_Platforms_Rackspace::USERNAME, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $env->getPlatformConfigValue(Modules_Platforms_Rackspace::API_KEY, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
                 $csServer = null;
                 $list = $cs->listServers(true);
                 if ($list) {
                     foreach ($list->servers as $_tmp) {
                         if ($_tmp->addresses->public && in_array($message->remoteIp, $_tmp->addresses->public)) {
                             $csServer = $_tmp;
                         }
                     }
                 }
                 if (!$csServer) {
                     $this->logger->error(sprintf("Server not found on CloudServers (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $message->remoteIp, $message->localIp));
                     return;
                 }
                 $dbserver->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::SERVER_ID => $csServer->id, RACKSPACE_SERVER_PROPERTIES::NAME => $csServer->name, RACKSPACE_SERVER_PROPERTIES::IMAGE_ID => $csServer->imageId, RACKSPACE_SERVER_PROPERTIES::FLAVOR_ID => $csServer->flavorId, RACKSPACE_SERVER_PROPERTIES::HOST_ID => $csServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
             case SERVER_PLATFORMS::OPENSTACK:
                 $env = $dbserver->GetEnvironmentObject();
                 $os = Scalr_Service_Cloud_Openstack::newNovaCC($env->getPlatformConfigValue(Modules_Platforms_Openstack::API_URL, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)), $env->getPlatformConfigValue(Modules_Platforms_Openstack::USERNAME, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)), $env->getPlatformConfigValue(Modules_Platforms_Openstack::API_KEY, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)), $env->getPlatformConfigValue(Modules_Platforms_Openstack::PROJECT_NAME, true, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)));
                 $csServer = null;
                 $list = $os->serversList(true);
                 if ($list) {
                     foreach ($list->servers as $_tmp) {
                         $ipaddresses = array();
                         if ($_tmp->addresses->private) {
                             foreach ($_tmp->addresses->private as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if ($_tmp->addresses->internet) {
                             foreach ($_tmp->addresses->internet as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if (in_array($message->localIp, $ipaddresses) || in_array($message->remoteIp, $ipaddresses)) {
                             $osServer = $_tmp;
                         }
                     }
                 }
                 if (!$osServer) {
                     $this->logger->error(sprintf("Server not found on Openstack (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $message->remoteIp, $message->localIp));
                     return;
                 }
                 $dbserver->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::SERVER_ID => $osServer->id, OPENSTACK_SERVER_PROPERTIES::NAME => $osServer->name, OPENSTACK_SERVER_PROPERTIES::IMAGE_ID => $osServer->image->id, OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID => $osServer->flavor->id, OPENSTACK_SERVER_PROPERTIES::HOST_ID => $osServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                 break;
         }
         // Bundle image
         $creInfo = new ServerSnapshotCreateInfo($dbserver, $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
         $bundleTask = BundleTask::Create($creInfo);
     }
 }
Exemplo n.º 3
0
 private function onHello($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::TEMPORARY) {
         $bundleTask = BundleTask::LoadById($dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID));
         $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PENDING;
         $bundleTask->Log("Received Hello message from scalarizr on server. Creating image");
         $bundleTask->osFamily = $message->dist->distributor;
         $bundleTask->osName = $message->dist->codename;
         $bundleTask->osVersion = $message->dist->release;
         if (in_array($message->dist->distributor, array('redhat', 'oel', 'scientific')) && $dbserver->platform == SERVER_PLATFORMS::EC2) {
             $bundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
         }
         $bundleTask->save();
     }
     if ($dbserver->status == SERVER_STATUS::IMPORTING) {
         if (!$dbserver->remoteIp || !$dbserver->localIp) {
             if (!$dbserver->remoteIp && $message->remoteIp && $dbserver->platform != SERVER_PLATFORMS::IDCF) {
                 $dbserver->remoteIp = $message->remoteIp;
             }
             if (!$dbserver->localIp && $message->localIp) {
                 $dbserver->localIp = $message->localIp;
             }
             if (!$message->behaviour) {
                 $message->behaviour = array('base');
             }
             if ((!$dbserver->remoteIp || $dbserver->localIp == $dbserver->remoteIp) && $message->messageIpAddress != $dbserver->remoteIp) {
                 $dbserver->remoteIp = $message->messageIpAddress;
             }
         }
         if (count($message->behaviour) == 1 && $message->behaviour[0] == ROLE_BEHAVIORS::CHEF) {
             $message->behaviour[] = ROLE_BEHAVIORS::BASE;
         }
         $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR, @implode(",", $message->behaviour));
         $dbserver->save();
         $importVersion = $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_VERSION);
         if ($importVersion == 2) {
             $dbserver->SetProperties(array(SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
         } else {
             if ($dbserver->isOpenstack()) {
                 $env = $dbserver->GetEnvironmentObject();
                 $os = $env->openstack($dbserver->platform, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
                 $csServer = null;
                 $list = $os->servers->list(true);
                 do {
                     foreach ($list as $_tmp) {
                         $ipaddresses = array();
                         if (!is_array($_tmp->addresses)) {
                             $_tmp->addresses = (array) $_tmp->addresses;
                         }
                         foreach ($_tmp->addresses as $net => $addresses) {
                             foreach ($addresses as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if ($_tmp->accessIPv4) {
                             array_push($ipaddresses, $_tmp->accessIPv4);
                         }
                         if (in_array($dbserver->localIp, $ipaddresses) || in_array($dbserver->remoteIp, $ipaddresses)) {
                             $osServer = $_tmp;
                         }
                     }
                 } while (false !== ($list = $list->getNextPage()));
                 if (!$osServer) {
                     $this->logger->error(sprintf("Server not found on Openstack (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $dbserver->remoteIp, $dbserver->localIp));
                     return;
                 }
                 $dbserver->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::SERVER_ID => $osServer->id, OPENSTACK_SERVER_PROPERTIES::NAME => $osServer->name, OPENSTACK_SERVER_PROPERTIES::IMAGE_ID => $osServer->image->id, OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID => $osServer->flavor->id, OPENSTACK_SERVER_PROPERTIES::HOST_ID => $osServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
             } elseif ($dbserver->isCloudstack()) {
                 $dbserver->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID => $message->cloudstack->instanceId, CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $message->cloudstack->availZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
             } else {
                 switch ($dbserver->platform) {
                     case SERVER_PLATFORMS::EC2:
                         $dbserver->SetProperties(array(EC2_SERVER_PROPERTIES::AMIID => $message->awsAmiId, EC2_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EC2_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EC2_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, EC2_SERVER_PROPERTIES::REGION => substr($message->awsAvailZone, 0, -1), SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::EUCALYPTUS:
                         $dbserver->SetProperties(array(EUCA_SERVER_PROPERTIES::EMIID => $message->awsAmiId, EUCA_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EUCA_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EUCA_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::GCE:
                         $dbserver->SetProperties(array(GCE_SERVER_PROPERTIES::CLOUD_LOCATION => $message->{$dbserver->platform}->cloudLocation, GCE_SERVER_PROPERTIES::SERVER_ID => $message->{$dbserver->platform}->serverId, GCE_SERVER_PROPERTIES::SERVER_NAME => $message->{$dbserver->platform}->serverName, GCE_SERVER_PROPERTIES::MACHINE_TYPE => $message->{$dbserver->platform}->machineType, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::NIMBULA:
                         $dbserver->SetProperties(array(NIMBULA_SERVER_PROPERTIES::NAME => $message->serverName, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::RACKSPACE:
                         $env = $dbserver->GetEnvironmentObject();
                         $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(RackspacePlatformModule::USERNAME, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $env->getPlatformConfigValue(RackspacePlatformModule::API_KEY, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
                         $csServer = null;
                         $list = $cs->listServers(true);
                         if ($list) {
                             foreach ($list->servers as $_tmp) {
                                 if ($_tmp->addresses->public && in_array($message->remoteIp, $_tmp->addresses->public)) {
                                     $csServer = $_tmp;
                                 }
                             }
                         }
                         if (!$csServer) {
                             $this->logger->error(sprintf("Server not found on CloudServers (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $message->remoteIp, $message->localIp));
                             return;
                         }
                         $dbserver->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::SERVER_ID => $csServer->id, RACKSPACE_SERVER_PROPERTIES::NAME => $csServer->name, RACKSPACE_SERVER_PROPERTIES::IMAGE_ID => $csServer->imageId, RACKSPACE_SERVER_PROPERTIES::FLAVOR_ID => $csServer->flavorId, RACKSPACE_SERVER_PROPERTIES::HOST_ID => $csServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                 }
             }
         }
         //TODO: search for existing bundle task
         // Bundle image
         $creInfo = new ServerSnapshotCreateInfo($dbserver, $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
         $bundleTask = BundleTask::Create($creInfo);
         $bundleTask->osFamily = $message->dist->distributor;
         $bundleTask->osName = $message->dist->codename;
         $bundleTask->osVersion = $message->dist->release;
         if (in_array($message->dist->distributor, array('oel', 'redhat', 'scientific')) && $dbserver->platform == SERVER_PLATFORMS::EC2) {
             $bundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
         }
         $bundleTask->setDate("started");
         $bundleTask->createdByEmail = $dbserver->GetProperty(SERVER_PROPERTIES::LAUNCHED_BY_EMAIL);
         $bundleTask->createdById = $dbserver->GetProperty(SERVER_PROPERTIES::LAUNCHED_BY_ID);
         if ($importVersion == 2) {
             $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::ESTABLISHING_COMMUNICATION;
         }
         $bundleTask->Save();
         $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     }
 }
Exemplo n.º 4
0
 public function ServerImageCreate($ServerID, $RoleName)
 {
     $this->restrictAccess(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE);
     $this->restrictAccess(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE);
     $DBServer = DBServer::LoadByID($ServerID);
     // Validate client and server
     if ($DBServer->envId != $this->Environment->id) {
         throw new Exception(sprintf("Server ID #%s not found", $ServerID));
     }
     $this->user->getPermissions()->validate($DBServer);
     //Check for already running bundle on selected instance
     $chk = $this->DB->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($ServerID));
     if ($chk) {
         throw new Exception(sprintf(_("Server '%s' is already synchonizing."), $ServerID));
     }
     if (!Role::isValidName($RoleName)) {
         throw new Exception(_("Role name is incorrect"));
     }
     if (Role::isNameUsed($RoleName, $this->user->getAccountId(), $this->Environment->id)) {
         throw new Exception("Specified role name is already used by another role");
     }
     if ($btId = BundleTask::getActiveTaskIdByName($RoleName, $this->user->getAccountId(), $this->Environment->id)) {
         throw new Exception(sprintf("Specified role name is already reserved for BundleTask with ID: %d.", $btId));
     }
     $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($DBServer, $RoleName, SERVER_REPLACEMENT_TYPE::NO_REPLACE, BundleTask::BUNDLETASK_OBJECT_ROLE, 'Bundled via API');
     $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
     $BundleTask->createdById = $this->user->id;
     $BundleTask->createdByEmail = $this->user->getEmail();
     $BundleTask->save();
     $response = $this->CreateInitialResponse();
     $response->BundleTaskID = $BundleTask->id;
     return $response;
 }
Exemplo n.º 5
0
 /**
  * @param   string  $serverId
  * @param   string  $name
  * @param   string  $description
  * @param   bool    $createRole
  * @param   string  $scope
  * @param   string  $replaceRole
  * @param   bool    $replaceImage
  * @param   int     $rootVolumeSize
  * @param   string  $rootVolumeType
  * @param   int     $rootVolumeIops
  * @throws  Exception
  */
 public function xServerCreateSnapshotAction($serverId, $name = '', $description = '', $createRole = false, $scope = '', $replaceRole = '', $replaceImage = false, $rootVolumeSize = 0, $rootVolumeType = '', $rootVolumeIops = 0)
 {
     $this->request->restrictAccess(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE);
     $server = $this->getServerEntity($serverId);
     $this->request->checkPermissions($server, true);
     $farm = $server->getFarm();
     $role = $server->getFarmRole()->getRole();
     //Check for already running bundle on selected instance
     if ($this->db->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($server->serverId))) {
         throw new Exception(sprintf(_("Server '%s' is already synchonizing."), $server->serverId));
     }
     $validator = new Validator();
     $validator->addErrorIf(!Entity\Role::isValidName($name), 'name', "Role name is incorrect");
     $validator->addErrorIf(!in_array($replaceRole, ['farm', 'all', '']), 'replaceRole', 'Invalid value');
     $object = $createRole ? BundleTask::BUNDLETASK_OBJECT_ROLE : BundleTask::BUNDLETASK_OBJECT_IMAGE;
     $replaceType = SERVER_REPLACEMENT_TYPE::NO_REPLACE;
     $createScope = ScopeInterface::SCOPE_ENVIRONMENT;
     if ($createRole) {
         $this->request->restrictAccess(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE);
         if ($replaceRole == 'farm') {
             if ($farm->hasAccessPermissions($this->getUser(), $this->getEnvironment(), Acl::PERM_FARMS_UPDATE)) {
                 $replaceType = SERVER_REPLACEMENT_TYPE::REPLACE_FARM;
             } else {
                 $validator->addError('replaceRole', "You don't have permissions to update farm");
             }
         } else {
             if ($replaceRole == 'all') {
                 if ($this->request->isAllowed([Acl::RESOURCE_FARMS, Acl::RESOURCE_TEAM_FARMS, Acl::RESOURCE_OWN_FARMS], Acl::PERM_FARMS_UPDATE)) {
                     $replaceType = SERVER_REPLACEMENT_TYPE::REPLACE_ALL;
                 } else {
                     $validator->addError('replaceRole', "You don't have permissions to update farms");
                 }
             }
         }
         /* @var $existRole Entity\Role */
         $existRole = Entity\Role::findOne([['name' => $name], ['$or' => [['accountId' => null], ['$and' => [['accountId' => $this->getUser()->accountId], ['$or' => [['envId' => null], ['envId' => $this->getEnvironment()->id]]]]]]]]);
         if ($existRole) {
             if (empty($existRole->accountId)) {
                 $validator->addError('name', _("Selected role name is reserved and cannot be used for custom role"));
             } else {
                 if ($replaceType != SERVER_REPLACEMENT_TYPE::REPLACE_ALL) {
                     $validator->addError('name', _("Specified role name is already used by another role. You can use this role name only if you will replace old one on ALL your farms."));
                 } else {
                     if ($replaceType == SERVER_REPLACEMENT_TYPE::REPLACE_ALL && $existRole->id != $role->id) {
                         $validator->addError('name', _("Specified role name is already in use. You cannot replace a Role different from the one you are currently snapshotting."));
                     }
                 }
             }
         }
         if ($btId = BundleTask::getActiveTaskIdByName($name, $this->getUser()->accountId, $this->getEnvironment()->id)) {
             $validator->addError('name', sprintf("Specified role name is already reserved for BundleTask with ID: %d.", $btId));
         }
         if ($replaceType != SERVER_REPLACEMENT_TYPE::NO_REPLACE) {
             $chk = BundleTask::getActiveTaskIdByRoleId($role->id, $this->getEnvironment()->id, BundleTask::BUNDLETASK_OBJECT_ROLE);
             $validator->addErrorIf($chk, 'replaceRole', sprintf("Role is already synchronizing in BundleTask: %d.", $chk));
         }
     } else {
         $sc = $role->getScope();
         if ($replaceImage) {
             if ($sc == ScopeInterface::SCOPE_ENVIRONMENT && $this->request->isAllowed(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE) || $sc == ScopeInterface::SCOPE_ACCOUNT && $this->request->isAllowed(Acl::RESOURCE_ROLES_ACCOUNT, Acl::PERM_ROLES_ACCOUNT_MANAGE)) {
                 $replaceType = SERVER_REPLACEMENT_TYPE::REPLACE_ALL;
                 $chk = BundleTask::getActiveTaskIdByRoleId($role->id, $this->getEnvironment()->id, BundleTask::BUNDLETASK_OBJECT_IMAGE);
                 $validator->addErrorIf($chk, 'replaceImage', sprintf("Role is already synchronizing in BundleTask: %d.", $chk));
             } else {
                 $validator->addError('replaceImage', "You don't have permissions to replace image in role");
             }
         }
     }
     if ($scope && ($createRole || $scope != $createScope)) {
         if ($createRole) {
             $c = $scope == ScopeInterface::SCOPE_ENVIRONMENT && $this->request->isAllowed(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE) || $scope == ScopeInterface::SCOPE_ACCOUNT && $this->request->isAllowed(Acl::RESOURCE_ROLES_ACCOUNT, Acl::PERM_ROLES_ACCOUNT_MANAGE);
             $validator->addErrorIf(!$c, 'scope', sprintf("You don't have permissions to create role in scope %s", $scope));
         }
         $c = $scope == ScopeInterface::SCOPE_ENVIRONMENT && $this->request->isAllowed(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE) || $scope == ScopeInterface::SCOPE_ACCOUNT && $this->request->isAllowed(Acl::RESOURCE_IMAGES_ACCOUNT, Acl::PERM_IMAGES_ACCOUNT_MANAGE);
         $validator->addErrorIf(!$c, 'scope', sprintf("You don't have permissions to create image in scope %s", $scope));
         $createScope = $scope;
     }
     $image = $role->getImage($server->platform, $server->cloudLocation)->getImage();
     $rootBlockDevice = [];
     if ($server->platform == SERVER_PLATFORMS::EC2 && ($server->isVersionSupported('0.7') && $server->os == 'linux' || $image->isEc2HvmImage())) {
         if ($rootVolumeSize > 0) {
             $rootBlockDevice['size'] = $rootVolumeSize;
         }
         if (in_array($rootVolumeType, [CreateVolumeRequestData::VOLUME_TYPE_STANDARD, CreateVolumeRequestData::VOLUME_TYPE_GP2, CreateVolumeRequestData::VOLUME_TYPE_IO1, CreateVolumeRequestData::VOLUME_TYPE_SC1, CreateVolumeRequestData::VOLUME_TYPE_ST1])) {
             $rootBlockDevice['volume_type'] = $rootVolumeType;
             if ($rootVolumeType == CreateVolumeRequestData::VOLUME_TYPE_IO1 && $rootVolumeIops > 0) {
                 $rootBlockDevice['iops'] = $rootVolumeIops;
             }
         }
     }
     if (!$validator->isValid($this->response)) {
         return;
     }
     $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo(DBServer::LoadByID($server->serverId), $name, $replaceType, $object, $description, $rootBlockDevice);
     $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
     $BundleTask->createdById = $this->user->id;
     $BundleTask->createdByEmail = $this->user->getEmail();
     $BundleTask->osId = $role->osId;
     $BundleTask->objectScope = $createScope;
     if ($role->getOs()->family == 'windows') {
         $BundleTask->osFamily = $role->getOs()->family;
         $BundleTask->osVersion = $role->getOs()->generation;
         $BundleTask->osName = '';
     } else {
         $BundleTask->osFamily = $role->getOs()->family;
         $BundleTask->osVersion = $role->getOs()->version;
         $BundleTask->osName = $role->getOs()->name;
     }
     if (in_array($role->getOs()->family, array('redhat', 'oel', 'scientific')) && $server->platform == SERVER_PLATFORMS::EC2) {
         $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
     }
     $BundleTask->save();
     $this->response->data(['bundleTaskId' => $BundleTask->id]);
     $this->response->success("Bundle task successfully created.");
 }
Exemplo n.º 6
0
 public function xBuildAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE);
     $this->request->defineParams(array('platform' => array('type' => 'string'), 'architecture' => array('type' => 'string'), 'behaviors' => array('type' => 'json'), 'roleName' => array('type' => 'string'), 'imageId' => array('type' => 'string'), 'location' => array('type' => 'string'), 'advanced' => array('type' => 'json'), 'chef' => array('type' => 'json')));
     if (strlen($this->getParam('roleName')) < 3) {
         throw new Exception(_("Role name should be greater than 3 chars"));
     }
     if (!preg_match("/^[A-Za-z0-9-]+\$/si", $this->getParam('roleName'))) {
         throw new Exception(_("Role name is incorrect"));
     }
     $chkRoleId = $this->db->GetOne("SELECT id FROM roles WHERE name=? AND (env_id = '0' OR env_id = ?) LIMIT 1", array($this->getParam('roleName'), $this->getEnvironmentId()));
     if ($chkRoleId) {
         if (!$this->db->GetOne("SELECT id FROM roles_queue WHERE role_id=? LIMIT 1", array($chkRoleId))) {
             throw new Exception('Selected role name is already used. Please select another one.');
         }
     }
     $imageId = $this->getParam('imageId');
     $advanced = $this->getParam('advanced');
     $chef = $this->getParam('chef');
     $behaviours = implode(",", array_values($this->getParam('behaviors')));
     // Create server
     $creInfo = new ServerCreateInfo($this->getParam('platform'), null, 0, 0);
     $creInfo->clientId = $this->user->getAccountId();
     $creInfo->envId = $this->getEnvironmentId();
     $creInfo->farmId = 0;
     $creInfo->SetProperties(array(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR => $behaviours, SERVER_PROPERTIES::SZR_IMPORTING_IMAGE_ID => $imageId, SERVER_PROPERTIES::SZR_KEY => Scalr::GenerateRandomKey(40), SERVER_PROPERTIES::SZR_KEY_TYPE => SZR_KEY_TYPE::PERMANENT, SERVER_PROPERTIES::SZR_VESION => "0.13.0", SERVER_PROPERTIES::SZR_IMPORTING_MYSQL_SERVER_TYPE => "mysql", SERVER_PROPERTIES::SZR_DEV_SCALARIZR_BRANCH => $advanced['scalrbranch'], SERVER_PROPERTIES::ARCHITECTURE => $this->getParam('architecture'), SERVER_PROPERTIES::SZR_IMPORTING_LEAVE_ON_FAIL => $advanced['dontterminatefailed'] == 'on' ? 1 : 0, SERVER_PROPERTIES::SZR_IMPORTING_CHEF_SERVER_ID => $chef['chef.server'], SERVER_PROPERTIES::SZR_IMPORTING_CHEF_ENVIRONMENT => $chef['chef.environment'], SERVER_PROPERTIES::SZR_IMPORTING_CHEF_ROLE_NAME => $chef['chef.role']));
     $dbServer = DBServer::Create($creInfo, true);
     $dbServer->status = SERVER_STATUS::TEMPORARY;
     $dbServer->save();
     //Launch server
     $launchOptions = new Scalr_Server_LaunchOptions();
     $launchOptions->imageId = $imageId;
     $launchOptions->cloudLocation = $this->getParam('cloud_location');
     $launchOptions->architecture = $this->getParam('architecture');
     $platform = PlatformFactory::NewPlatform($this->getParam('platform'));
     switch ($this->getParam('platform')) {
         case SERVER_PLATFORMS::ECS:
             $launchOptions->serverType = 10;
             break;
         case SERVER_PLATFORMS::IDCF:
             $launchOptions->serverType = 24;
             break;
         case SERVER_PLATFORMS::RACKSPACE:
             if ($this->getParam('osfamily') == 'ubuntu') {
                 $launchOptions->serverType = 1;
             } else {
                 $launchOptions->serverType = 3;
             }
             break;
         case SERVER_PLATFORMS::RACKSPACENG_US:
             $launchOptions->serverType = 3;
             break;
         case SERVER_PLATFORMS::RACKSPACENG_UK:
             $launchOptions->serverType = 3;
             break;
         case SERVER_PLATFORMS::EC2:
             if ($this->getParam('hvm') == 1) {
                 $launchOptions->serverType = 'm3.xlarge';
                 $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
             } else {
                 if ($this->getParam('osfamily') == 'oel') {
                     $launchOptions->serverType = 'm1.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } elseif ($this->getParam('osfamily') == 'rhel') {
                     $launchOptions->serverType = 'm1.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } elseif ($this->getParam('osfamily') == 'scientific') {
                     $launchOptions->serverType = 'm1.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } else {
                     $launchOptions->serverType = 'm1.small';
                 }
             }
             $launchOptions->userData = "#cloud-config\ndisable_root: false";
             break;
         case SERVER_PLATFORMS::GCE:
             $launchOptions->serverType = 'n1-standard-1';
             $locations = array_keys($platform->getLocations());
             $launchOptions->cloudLocation = $locations[0];
             $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::GCE_STORAGE;
             break;
     }
     if ($advanced['servertype']) {
         $launchOptions->serverType = $advanced['servertype'];
     }
     if ($advanced['availzone']) {
         $launchOptions->availZone = $advanced['availzone'];
     }
     if ($advanced['region']) {
         $launchOptions->cloudLocation = $advanced['region'];
     }
     //Add Bundle task
     $creInfo = new ServerSnapshotCreateInfo($dbServer, $this->getParam('roleName'), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
     $bundleTask = BundleTask::Create($creInfo, true);
     if ($bundleType) {
         $bundleTask->bundleType = $bundleType;
     }
     $bundleTask->createdById = $this->user->id;
     $bundleTask->createdByEmail = $this->user->getEmail();
     $bundleTask->osFamily = $this->getParam('osfamily');
     $bundleTask->cloudLocation = $launchOptions->cloudLocation;
     $bundleTask->save();
     $bundleTask->Log(sprintf("Launching temporary server (%s)", serialize($launchOptions)));
     $dbServer->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     try {
         $platform->LaunchServer($dbServer, $launchOptions);
         $bundleTask->Log(_("Temporary server launched. Waiting for running state..."));
     } catch (Exception $e) {
         $bundleTask->SnapshotCreationFailed(sprintf(_("Unable to launch temporary server: %s"), $e->getMessage()));
     }
     $this->response->data(array('serverId' => $dbServer->serverId, 'bundleTaskId' => $bundleTask->id));
 }
Exemplo n.º 7
0
 public function xServerCreateSnapshotAction()
 {
     $this->request->defineParams(array('rootVolumeSize' => array('type' => 'int')));
     if (!$this->getParam('serverId')) {
         throw new Exception(_('Server not found'));
     }
     $dbServer = DBServer::LoadByID($this->getParam('serverId'));
     $this->user->getPermissions()->validate($dbServer);
     $err = array();
     if (strlen($this->getParam('roleName')) < 3) {
         $err[] = _("Role name should be greater than 3 chars");
     }
     if (!preg_match("/^[A-Za-z0-9-]+\$/si", $this->getParam('roleName'))) {
         $err[] = _("Role name is incorrect");
     }
     $roleinfo = $this->db->GetRow("SELECT * FROM roles WHERE name=? AND (env_id=? OR env_id='0')", array($this->getParam('roleName'), $dbServer->envId, $dbServer->roleId));
     if ($this->getParam('replaceType') != SERVER_REPLACEMENT_TYPE::REPLACE_ALL) {
         if ($roleinfo && $roleinfo['id'] != $dbServer->roleId) {
             $err[] = _("Specified role name is already used by another role. You can use this role name only if you will replace old on on ALL your farms.");
         }
     } else {
         if ($roleinfo && $roleinfo['env_id'] == 0) {
             $err[] = _("Selected role name is reserved and cannot be used for custom role");
         }
     }
     //Check for already running bundle on selected instance
     $chk = $this->db->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed')", array($dbServer->serverId));
     if ($chk) {
         $err[] = sprintf(_("Server '%s' is already synchonizing."), $dbServer->serverId);
     }
     //Check is role already synchronizing...
     $chk = $this->db->GetOne("SELECT server_id FROM bundle_tasks WHERE prototype_role_id=? AND status NOT IN ('success', 'failed')", array($dbServer->roleId));
     if ($chk && $chk != $dbServer->serverId) {
         try {
             $bDBServer = DBServer::LoadByID($chk);
             if ($bDBServer->farmId == $DBServer->farmId) {
                 $err[] = sprintf(_("Role '%s' is already synchonizing."), $dbServer->GetFarmRoleObject()->GetRoleObject()->name);
             }
         } catch (Exception $e) {
         }
     }
     if ($dbServer->GetFarmRoleObject()->NewRoleID) {
         $err[] = sprintf(_("Role '%s' is already synchonizing."), $dbServer->GetFarmRoleObject()->GetRoleObject()->name);
     }
     if (count($err)) {
         throw new Exception(nl2br(implode('\\n', $err)));
     }
     $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($dbServer, $this->getParam('roleName'), $this->getParam('replaceType'), false, $this->getParam('roleDescription'), $this->getParam('rootVolumeSize'), $this->getParam('noServersReplace') == 'on' ? true : false);
     $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
     $this->response->success("Bundle task successfully created. <a href='#/bundletasks/{$BundleTask->id}/logs'>Click here to check status.</a>");
 }
Exemplo n.º 8
0
 public function xBuildAction()
 {
     $this->request->defineParams(array('platform' => array('type' => 'string'), 'architecture' => array('type' => 'string'), 'behaviors' => array('type' => 'json'), 'roleName' => array('type' => 'string'), 'imageId' => array('type' => 'string'), 'location' => array('type' => 'string'), 'mysqlServerType' => array('type' => 'string'), 'devScalarizrBranch' => array('type' => 'string')));
     if (strlen($this->getParam('roleName')) < 3) {
         throw new Exception(_("Role name should be greater than 3 chars"));
     }
     if (!preg_match("/^[A-Za-z0-9-]+\$/si", $this->getParam('roleName'))) {
         throw new Exception(_("Role name is incorrect"));
     }
     $chkRoleId = $this->db->GetOne("SELECT id FROM roles WHERE name=? AND (env_id = '0' OR env_id = ?)", array($this->getParam('roleName'), $this->getEnvironmentId()));
     if ($chkRoleId) {
         if (!$this->db->GetOne("SELECT id FROM roles_queue WHERE role_id=?", array($chkRoleId))) {
             throw new Exception('Selected role name is already used. Please select another one.');
         }
     }
     $imageId = $this->getParam('imageId');
     if ($this->getParam('platform') == SERVER_PLATFORMS::RACKSPACE) {
         $imageId = str_replace('lon', '', $imageId);
     }
     $behaviours = implode(",", array_values($this->getParam('behaviors')));
     // Create server
     $creInfo = new ServerCreateInfo($this->getParam('platform'), null, 0, 0);
     $creInfo->clientId = $this->user->getAccountId();
     $creInfo->envId = $this->getEnvironmentId();
     $creInfo->farmId = 0;
     $creInfo->SetProperties(array(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR => $behaviours, SERVER_PROPERTIES::SZR_KEY => Scalr::GenerateRandomKey(40), SERVER_PROPERTIES::SZR_KEY_TYPE => SZR_KEY_TYPE::PERMANENT, SERVER_PROPERTIES::SZR_VESION => "0.6", SERVER_PROPERTIES::SZR_IMPORTING_MYSQL_SERVER_TYPE => $this->getParam('mysqlServerType'), SERVER_PROPERTIES::SZR_DEV_SCALARIZR_BRANCH => $this->getParam('devScalarizrBranch')));
     $dbServer = DBServer::Create($creInfo, true);
     $dbServer->status = SERVER_STATUS::TEMPORARY;
     $dbServer->save();
     //Launch server
     $launchOptions = new Scalr_Server_LaunchOptions();
     $launchOptions->imageId = $imageId;
     $launchOptions->cloudLocation = $this->getParam('location');
     $launchOptions->architecture = $this->getParam('architecture');
     switch ($this->getParam('platform')) {
         case SERVER_PLATFORMS::RACKSPACE:
             $launchOptions->serverType = 1;
             break;
         case SERVER_PLATFORMS::EC2:
             $launchOptions->serverType = 'm1.small';
             $launchOptions->userData = "#cloud-config\ndisable_root: false";
             break;
     }
     if ($this->getParam('serverType')) {
         $launchOptions->serverType = $this->getParam('serverType');
     }
     if ($this->getParam('availZone')) {
         $launchOptions->availZone = $this->getParam('availZone');
     }
     //Add Bundle task
     $creInfo = new ServerSnapshotCreateInfo($dbServer, $this->getParam('roleName'), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
     $bundleTask = BundleTask::Create($creInfo, true);
     $bundleTask->cloudLocation = $launchOptions->cloudLocation;
     $bundleTask->save();
     $bundleTask->Log(sprintf("Launching temporary server (%s)", serialize($launchOptions)));
     $dbServer->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     try {
         PlatformFactory::NewPlatform($this->getParam('platform'))->LaunchServer($dbServer, $launchOptions);
         $bundleTask->Log(_("Temporary server launched. Waiting for running state..."));
     } catch (Exception $e) {
         $bundleTask->SnapshotCreationFailed(sprintf(_("Unable to launch temporary server: %s"), $e->getMessage()));
     }
     $this->response->data(array('bundleTaskId' => $bundleTask->id));
 }
Exemplo n.º 9
0
 /**
  * @param   string  $serverId
  * @param   string  $name
  * @param   string  $description
  * @param   bool    $createRole
  * @param   string  $replaceRole
  * @param   bool    $replaceImage
  * @param   int     $rootVolumeSize
  * @param   string  $rootVolumeType
  * @param   int     $rootVolumeIops
  * @throws Exception
  */
 public function xServerCreateSnapshotAction($serverId, $name = '', $description = '', $createRole = false, $replaceRole = '', $replaceImage = false, $rootVolumeSize = 0, $rootVolumeType = '', $rootVolumeIops = 0)
 {
     $this->request->restrictAccess(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE);
     if (!$serverId) {
         throw new Exception('Server not found');
     }
     $dbServer = DBServer::LoadByID($serverId);
     $this->user->getPermissions()->validate($dbServer);
     $errorMsg = [];
     //Check for already running bundle on selected instance
     $chk = $this->db->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($dbServer->serverId));
     if ($chk) {
         $errorMsg[] = sprintf(_("Server '%s' is already synchonizing."), $dbServer->serverId);
     }
     //Check is role already synchronizing...
     $chk = $this->db->GetOne("SELECT server_id FROM bundle_tasks WHERE prototype_role_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($dbServer->GetFarmRoleObject()->RoleID));
     if ($chk && $chk != $dbServer->serverId) {
         try {
             $bDBServer = DBServer::LoadByID($chk);
             if ($bDBServer->farmId == $dbServer->farmId) {
                 $errorMsg[] = sprintf(_("Role '%s' is already synchronizing."), $dbServer->GetFarmRoleObject()->GetRoleObject()->name);
             }
         } catch (Exception $e) {
         }
     }
     if (!empty($errorMsg)) {
         throw new Exception(implode('\\n', $errorMsg));
     }
     $validator = new \Scalr\UI\Request\Validator();
     $validator->addErrorIf(strlen($name) < 3, 'name', _("Role name should be greater than 3 chars"));
     $validator->addErrorIf(!preg_match("/^[A-Za-z0-9-]+\$/si", $name), 'name', _("Role name is incorrect"));
     $validator->addErrorIf(!in_array($replaceRole, ['farm', 'all', '']), 'replaceRole', 'Invalid value');
     $object = $createRole ? BundleTask::BUNDLETASK_OBJECT_ROLE : BundleTask::BUNDLETASK_OBJECT_IMAGE;
     $replaceType = SERVER_REPLACEMENT_TYPE::NO_REPLACE;
     if ($createRole) {
         $this->request->restrictAccess(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE);
         if ($replaceRole == 'farm') {
             $this->request->restrictFarmAccess($dbServer->GetFarmObject(), Acl::PERM_FARMS_MANAGE);
             $replaceType = SERVER_REPLACEMENT_TYPE::REPLACE_FARM;
         } else {
             if ($replaceRole == 'all') {
                 $this->request->restrictFarmAccess(null, Acl::PERM_FARMS_MANAGE);
                 $replaceType = SERVER_REPLACEMENT_TYPE::REPLACE_ALL;
             }
         }
     } else {
         $scope = $dbServer->GetFarmRoleObject()->GetRoleObject()->__getNewRoleObject()->getScope();
         if ($replaceImage && ($scope == ScopeInterface::SCOPE_ENVIRONMENT && $this->request->isAllowed(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE) || $scope == ScopeInterface::SCOPE_ACCOUNT && $this->request->isAllowed(Acl::RESOURCE_ROLES_ACCOUNT, Acl::PERM_ROLES_ACCOUNT_MANAGE))) {
             $replaceType = SERVER_REPLACEMENT_TYPE::REPLACE_ALL;
         }
     }
     if ($createRole) {
         $roleInfo = $this->db->GetRow("SELECT * FROM roles WHERE name=? AND (client_id IS NULL OR client_id = ? AND env_id IS NULL OR env_id=?) LIMIT 1", array($name, $dbServer->clientId, $dbServer->envId, $dbServer->GetFarmRoleObject()->RoleID));
         if ($roleInfo) {
             if (empty($roleInfo['client_id'])) {
                 $validator->addError('name', _("Selected role name is reserved and cannot be used for custom role"));
             } else {
                 if ($replaceType != SERVER_REPLACEMENT_TYPE::REPLACE_ALL) {
                     $validator->addError('name', _("Specified role name is already used by another role. You can use this role name only if you will replace old one on ALL your farms."));
                 } else {
                     if ($replaceType == SERVER_REPLACEMENT_TYPE::REPLACE_ALL && $roleInfo['id'] != $dbServer->GetFarmRoleObject()->RoleID) {
                         $validator->addError('name', _("This Role name is already in use. You cannot replace a Role different from the one you are currently snapshotting."));
                     }
                 }
             }
         }
     }
     $roleImage = $dbServer->GetFarmRoleObject()->GetRoleObject()->__getNewRoleObject()->getImage($dbServer->platform, $dbServer->GetCloudLocation());
     $rootBlockDevice = [];
     if ($dbServer->platform == SERVER_PLATFORMS::EC2 && ($dbServer->IsSupported('0.7') && $dbServer->osType == 'linux' || $roleImage->getImage()->isEc2HvmImage())) {
         if ($rootVolumeSize > 0) {
             $rootBlockDevice['size'] = $rootVolumeSize;
         }
         if (in_array($rootVolumeType, ['standard', 'gp2', 'io1'])) {
             $rootBlockDevice['volume_type'] = $rootVolumeType;
             if ($rootVolumeType == 'io1' && $rootVolumeIops > 0) {
                 $rootBlockDevice['iops'] = $rootVolumeIops;
             }
         }
     }
     if (!$validator->isValid($this->response)) {
         return;
     }
     $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($dbServer, $name, $replaceType, $object, $description, $rootBlockDevice);
     $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
     $BundleTask->createdById = $this->user->id;
     $BundleTask->createdByEmail = $this->user->getEmail();
     if ($dbServer->GetFarmRoleObject()->GetSetting('user-data.scm_branch') == 'feature/image-api') {
         $BundleTask->generation = 2;
     }
     $protoRole = DBRole::loadById($dbServer->GetFarmRoleObject()->RoleID);
     $BundleTask->osId = $protoRole->osId;
     if ($protoRole->getOs()->family == 'windows') {
         $BundleTask->osFamily = $protoRole->getOs()->family;
         $BundleTask->osVersion = $protoRole->getOs()->generation;
         $BundleTask->osName = '';
     } else {
         $BundleTask->osFamily = $protoRole->getOs()->family;
         $BundleTask->osVersion = $protoRole->getOs()->version;
         $BundleTask->osName = $protoRole->getOs()->name;
     }
     if (in_array($protoRole->getOs()->family, array('redhat', 'oel', 'scientific')) && $dbServer->platform == SERVER_PLATFORMS::EC2) {
         $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
     }
     $BundleTask->save();
     $this->response->data(['bundleTaskId' => $BundleTask->id]);
     $this->response->success("Bundle task successfully created.");
 }
Exemplo n.º 10
0
 /**
  * @param   string      $platform
  * @param   string      $architecture
  * @param   JsonData    $behaviors
  * @param   string      $name
  * @param   bool        $createImage
  * @param   string      $imageId
  * @param   string      $cloudLocation
  * @param   string      $osId
  * @param   integer     $hvm
  * @param   JsonData    $advanced
  * @param   JsonData    $chef
  * @throws  Exception
  */
 public function xBuildAction($platform, $architecture, JsonData $behaviors, $name = '', $createImage = false, $imageId, $cloudLocation, $osId, $hvm = 0, JsonData $advanced, JsonData $chef)
 {
     $this->request->restrictAccess(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_BUILD);
     if (!Role::isValidName($name)) {
         throw new Exception(_("Name is incorrect"));
     }
     if (!$createImage) {
         $this->request->restrictAccess(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE);
     }
     if (!$createImage && Role::isNameUsed($name, $this->user->getAccountId(), $this->getEnvironmentId())) {
         throw new Exception('Selected role name is already used. Please select another one.');
     }
     $behaviours = implode(",", array_values($behaviors->getArrayCopy()));
     $os = Os::findPk($osId);
     if (!$os) {
         throw new Exception('Operating system not found.');
     }
     // Create server
     $creInfo = new ServerCreateInfo($platform, null, 0, 0);
     $creInfo->clientId = $this->user->getAccountId();
     $creInfo->envId = $this->getEnvironmentId();
     $creInfo->farmId = 0;
     $creInfo->SetProperties(array(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR => $behaviours, SERVER_PROPERTIES::SZR_IMPORTING_IMAGE_ID => $imageId, SERVER_PROPERTIES::SZR_KEY => Scalr::GenerateRandomKey(40), SERVER_PROPERTIES::SZR_KEY_TYPE => SZR_KEY_TYPE::PERMANENT, SERVER_PROPERTIES::SZR_VESION => "0.13.0", SERVER_PROPERTIES::SZR_IMPORTING_MYSQL_SERVER_TYPE => "mysql", SERVER_PROPERTIES::SZR_DEV_SCALARIZR_BRANCH => $advanced['scalrbranch'], SERVER_PROPERTIES::ARCHITECTURE => $architecture, SERVER_PROPERTIES::SZR_IMPORTING_LEAVE_ON_FAIL => $advanced['dontterminatefailed'] == 'on' ? 1 : 0, SERVER_PROPERTIES::SZR_IMPORTING_CHEF_SERVER_ID => $chef['chef.server'], SERVER_PROPERTIES::SZR_IMPORTING_CHEF_ENVIRONMENT => $chef['chef.environment'], SERVER_PROPERTIES::SZR_IMPORTING_CHEF_ROLE_NAME => $chef['chef.role']));
     $dbServer = DBServer::Create($creInfo, true);
     $dbServer->status = SERVER_STATUS::TEMPORARY;
     $dbServer->imageId = $imageId;
     $dbServer->save();
     //Launch server
     $launchOptions = new Scalr_Server_LaunchOptions();
     $launchOptions->imageId = $imageId;
     $launchOptions->cloudLocation = $cloudLocation;
     $launchOptions->architecture = $architecture;
     $platformObj = PlatformFactory::NewPlatform($platform);
     switch ($platform) {
         case SERVER_PLATFORMS::IDCF:
             $launchOptions->serverType = 24;
             break;
         case SERVER_PLATFORMS::RACKSPACENG_US:
             $launchOptions->serverType = 3;
             break;
         case SERVER_PLATFORMS::RACKSPACENG_UK:
             $launchOptions->serverType = 3;
             break;
         case SERVER_PLATFORMS::EC2:
             if ($cloudLocation == Aws::REGION_AP_NORTHEAST_2) {
                 if ($hvm == 1 || $this->isHvmBundleTypeOs($os)) {
                     $launchOptions->serverType = 't2.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 }
             } else {
                 if ($hvm == 1) {
                     $launchOptions->serverType = "m3.xlarge";
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } else {
                     $launchOptions->serverType = "m3.large";
                     if ($this->isHvmBundleTypeOs($os)) {
                         $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                     }
                     if ($os->family == 'oel' && $os->generation == '5') {
                         $launchOptions->serverType = "m1.large";
                     }
                 }
             }
             $launchOptions->userData = "#cloud-config\ndisable_root: false";
             break;
         case SERVER_PLATFORMS::GCE:
             $launchOptions->serverType = 'n1-standard-1';
             $location = null;
             $locations = array_keys($platformObj->getLocations($this->environment));
             while (count($locations) != 0) {
                 $location = array_shift($locations);
                 if (strstr($location, "us-")) {
                     break;
                 }
             }
             $launchOptions->cloudLocation = $locations[0];
             $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::GCE_STORAGE;
             break;
     }
     if ($advanced['servertype']) {
         $launchOptions->serverType = $advanced['servertype'];
     }
     if ($advanced['availzone']) {
         $launchOptions->availZone = $advanced['availzone'];
     }
     if ($advanced['region']) {
         $launchOptions->cloudLocation = $advanced['region'];
     }
     //Add Bundle task
     $creInfo = new ServerSnapshotCreateInfo($dbServer, $name, SERVER_REPLACEMENT_TYPE::NO_REPLACE);
     $bundleTask = BundleTask::Create($creInfo, true);
     if ($bundleType) {
         $bundleTask->bundleType = $bundleType;
     }
     $bundleTask->createdById = $this->user->id;
     $bundleTask->createdByEmail = $this->user->getEmail();
     $bundleTask->osFamily = $os->family;
     $bundleTask->object = $createImage ? BundleTask::BUNDLETASK_OBJECT_IMAGE : BundleTask::BUNDLETASK_OBJECT_ROLE;
     $bundleTask->cloudLocation = $launchOptions->cloudLocation;
     $bundleTask->save();
     $bundleTask->Log(sprintf("Launching temporary server (%s)", serialize($launchOptions)));
     $dbServer->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     try {
         $platformObj->LaunchServer($dbServer, $launchOptions);
         $dbServer->Save();
         $bundleTask->Log(_("Temporary server launched. Waiting for running state..."));
     } catch (Exception $e) {
         $bundleTask->SnapshotCreationFailed(sprintf(_("Unable to launch temporary server: %s"), $e->getMessage()));
     }
     $this->response->data(array('serverId' => $dbServer->serverId, 'bundleTaskId' => $bundleTask->id));
 }
Exemplo n.º 11
0
 public function xServerCreateSnapshotAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE);
     $this->request->defineParams(array('rootVolumeSize' => array('type' => 'int')));
     if (!$this->getParam('serverId')) {
         throw new Exception(_('Server not found'));
     }
     $dbServer = DBServer::LoadByID($this->getParam('serverId'));
     $this->user->getPermissions()->validate($dbServer);
     $err = array();
     if (strlen($this->getParam('roleName')) < 3) {
         $err[] = _("Role name should be greater than 3 chars");
     }
     if (!preg_match("/^[A-Za-z0-9-]+\$/si", $this->getParam('roleName'))) {
         $err[] = _("Role name is incorrect");
     }
     $roleinfo = $this->db->GetRow("SELECT * FROM roles WHERE name=? AND (env_id=? OR env_id='0') LIMIT 1", array($this->getParam('roleName'), $dbServer->envId, $dbServer->roleId));
     if ($this->getParam('replaceType') != SERVER_REPLACEMENT_TYPE::REPLACE_ALL) {
         if ($roleinfo) {
             $err[] = _("Specified role name is already used by another role. You can use this role name only if you will replace old one on ALL your farms.");
         }
     } else {
         if ($roleinfo && $roleinfo['env_id'] == 0) {
             $err[] = _("Selected role name is reserved and cannot be used for custom role");
         }
     }
     //Check for already running bundle on selected instance
     $chk = $this->db->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($dbServer->serverId));
     if ($chk) {
         $err[] = sprintf(_("Server '%s' is already synchonizing."), $dbServer->serverId);
     }
     //Check is role already synchronizing...
     $chk = $this->db->GetOne("SELECT server_id FROM bundle_tasks WHERE prototype_role_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($dbServer->roleId));
     if ($chk && $chk != $dbServer->serverId) {
         try {
             $bDBServer = DBServer::LoadByID($chk);
             if ($bDBServer->farmId == $DBServer->farmId) {
                 $err[] = sprintf(_("Role '%s' is already synchonizing."), $dbServer->GetFarmRoleObject()->GetRoleObject()->name);
             }
         } catch (Exception $e) {
         }
     }
     if ($dbServer->GetFarmRoleObject()->NewRoleID) {
         $err[] = sprintf(_("Role '%s' is already synchonizing."), $dbServer->GetFarmRoleObject()->GetRoleObject()->name);
     }
     if (count($err)) {
         throw new Exception(nl2br(implode('\\n', $err)));
     }
     $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($dbServer, $this->getParam('roleName'), $this->getParam('replaceType'), false, $this->getParam('roleDescription'), $this->getParam('rootVolumeSize'), $this->getParam('noServersReplace') == 'on' ? true : false);
     $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
     $BundleTask->createdById = $this->user->id;
     $BundleTask->createdByEmail = $this->user->getEmail();
     if ($dbServer->GetFarmRoleObject()->GetSetting('user-data.scm_branch') == 'feature/image-api') {
         $BundleTask->generation = 2;
     }
     $protoRole = DBRole::loadById($dbServer->roleId);
     $BundleTask->osFamily = $protoRole->osFamily;
     $BundleTask->osVersion = $protoRole->osVersion;
     if (in_array($protoRole->osFamily, array('redhat', 'oel', 'scientific')) && $dbServer->platform == SERVER_PLATFORMS::EC2) {
         $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
     }
     $BundleTask->save();
     $this->response->success("Bundle task successfully created. <a href='#/bundletasks/{$BundleTask->id}/logs'>Click here to check status.</a>", true);
 }
Exemplo n.º 12
0
 /**
  * @param   string      $platform
  * @param   string      $architecture
  * @param   JsonData    $behaviors
  * @param   string      $name
  * @param   bool        $createImage
  * @param   string      $imageId
  * @param   string      $cloudLocation
  * @param   string      $osId
  * @param   integer     $hvm
  * @param   JsonData    $advanced
  * @param   JsonData    $chef
  * @throws  Exception
  */
 public function xBuildAction($platform, $architecture, JsonData $behaviors, $name = '', $createImage = false, $imageId, $cloudLocation, $osId, $hvm = 0, JsonData $advanced, JsonData $chef)
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE);
     if (!\Scalr\Model\Entity\Role::validateName($name)) {
         throw new Exception(_("Name is incorrect"));
     }
     if (!$createImage && $this->db->GetOne("SELECT id FROM roles WHERE name=? AND (env_id IS NULL OR env_id = ?) LIMIT 1", array($name, $this->getEnvironmentId()))) {
         throw new Exception('Selected role name is already used. Please select another one.');
     }
     $behaviours = implode(",", array_values($behaviors->getArrayCopy()));
     $os = Os::findPk($osId);
     if (!$os) {
         throw new Exception('Operating system not found.');
     }
     // Create server
     $creInfo = new ServerCreateInfo($platform, null, 0, 0);
     $creInfo->clientId = $this->user->getAccountId();
     $creInfo->envId = $this->getEnvironmentId();
     $creInfo->farmId = 0;
     $creInfo->SetProperties(array(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR => $behaviours, SERVER_PROPERTIES::SZR_IMPORTING_IMAGE_ID => $imageId, SERVER_PROPERTIES::SZR_KEY => Scalr::GenerateRandomKey(40), SERVER_PROPERTIES::SZR_KEY_TYPE => SZR_KEY_TYPE::PERMANENT, SERVER_PROPERTIES::SZR_VESION => "0.13.0", SERVER_PROPERTIES::SZR_IMPORTING_MYSQL_SERVER_TYPE => "mysql", SERVER_PROPERTIES::SZR_DEV_SCALARIZR_BRANCH => $advanced['scalrbranch'], SERVER_PROPERTIES::ARCHITECTURE => $architecture, SERVER_PROPERTIES::SZR_IMPORTING_LEAVE_ON_FAIL => $advanced['dontterminatefailed'] == 'on' ? 1 : 0, SERVER_PROPERTIES::SZR_IMPORTING_CHEF_SERVER_ID => $chef['chef.server'], SERVER_PROPERTIES::SZR_IMPORTING_CHEF_ENVIRONMENT => $chef['chef.environment'], SERVER_PROPERTIES::SZR_IMPORTING_CHEF_ROLE_NAME => $chef['chef.role']));
     $dbServer = DBServer::Create($creInfo, true);
     $dbServer->status = SERVER_STATUS::TEMPORARY;
     $dbServer->imageId = $imageId;
     $dbServer->save();
     //Launch server
     $launchOptions = new Scalr_Server_LaunchOptions();
     $launchOptions->imageId = $imageId;
     $launchOptions->cloudLocation = $cloudLocation;
     $launchOptions->architecture = $architecture;
     $platformObj = PlatformFactory::NewPlatform($platform);
     switch ($platform) {
         case SERVER_PLATFORMS::ECS:
             $launchOptions->serverType = 10;
             if ($cloudLocation == 'all') {
                 $locations = array_keys($platformObj->getLocations($this->environment));
                 $launchOptions->cloudLocation = $locations[0];
             }
             //Network here:
             $osClient = $platformObj->getOsClient($this->environment, $launchOptions->cloudLocation);
             $networks = $osClient->network->listNetworks();
             $tenantId = $osClient->getConfig()->getAuthToken()->getTenantId();
             foreach ($networks as $network) {
                 if ($network->status == 'ACTIVE') {
                     if ($network->{"router:external"} != true) {
                         if ($tenantId == $network->tenant_id) {
                             $launchOptions->networks = array($network->id);
                             break;
                         }
                     }
                 }
             }
             break;
         case SERVER_PLATFORMS::IDCF:
             $launchOptions->serverType = 24;
             break;
         case SERVER_PLATFORMS::RACKSPACE:
             if ($os->family == 'ubuntu') {
                 $launchOptions->serverType = 1;
             } else {
                 $launchOptions->serverType = 3;
             }
             break;
         case SERVER_PLATFORMS::RACKSPACENG_US:
             $launchOptions->serverType = 3;
             break;
         case SERVER_PLATFORMS::RACKSPACENG_UK:
             $launchOptions->serverType = 3;
             break;
         case SERVER_PLATFORMS::EC2:
             if ($hvm == 1) {
                 $launchOptions->serverType = 'm3.xlarge';
                 $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
             } else {
                 if ($os->family == 'oel') {
                     $launchOptions->serverType = 'm3.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } elseif ($os->family == 'rhel') {
                     $launchOptions->serverType = 'm3.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } elseif ($os->family == 'scientific') {
                     $launchOptions->serverType = 'm3.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } elseif ($os->family == 'debian' && $os->generation == '8') {
                     $launchOptions->serverType = 'm3.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } elseif ($os->family == 'centos' && $os->generation == '7') {
                     $launchOptions->serverType = 'm3.large';
                     $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
                 } else {
                     $launchOptions->serverType = 'm3.large';
                 }
             }
             $launchOptions->userData = "#cloud-config\ndisable_root: false";
             break;
         case SERVER_PLATFORMS::GCE:
             $launchOptions->serverType = 'n1-standard-1';
             $location = null;
             $locations = array_keys($platformObj->getLocations($this->environment));
             while (count($locations) != 0) {
                 $location = array_shift($locations);
                 if (strstr($location, "us-")) {
                     break;
                 }
             }
             $launchOptions->cloudLocation = $locations[0];
             $bundleType = SERVER_SNAPSHOT_CREATION_TYPE::GCE_STORAGE;
             break;
     }
     if ($advanced['servertype']) {
         $launchOptions->serverType = $advanced['servertype'];
     }
     if ($advanced['availzone']) {
         $launchOptions->availZone = $advanced['availzone'];
     }
     if ($advanced['region']) {
         $launchOptions->cloudLocation = $advanced['region'];
     }
     //Add Bundle task
     $creInfo = new ServerSnapshotCreateInfo($dbServer, $name, SERVER_REPLACEMENT_TYPE::NO_REPLACE);
     $bundleTask = BundleTask::Create($creInfo, true);
     if ($bundleType) {
         $bundleTask->bundleType = $bundleType;
     }
     $bundleTask->createdById = $this->user->id;
     $bundleTask->createdByEmail = $this->user->getEmail();
     $bundleTask->osFamily = $os->family;
     $bundleTask->object = $createImage ? BundleTask::BUNDLETASK_OBJECT_IMAGE : BundleTask::BUNDLETASK_OBJECT_ROLE;
     $bundleTask->cloudLocation = $launchOptions->cloudLocation;
     $bundleTask->save();
     $bundleTask->Log(sprintf("Launching temporary server (%s)", serialize($launchOptions)));
     $dbServer->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     try {
         $platformObj->LaunchServer($dbServer, $launchOptions);
         $bundleTask->Log(_("Temporary server launched. Waiting for running state..."));
     } catch (Exception $e) {
         $bundleTask->SnapshotCreationFailed(sprintf(_("Unable to launch temporary server: %s"), $e->getMessage()));
     }
     $this->response->data(array('serverId' => $dbServer->serverId, 'bundleTaskId' => $bundleTask->id));
 }
Exemplo n.º 13
0
 public function xTerminateAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'deleteDNSZones' => array('type' => 'string'), 'deleteCloudObjects' => array('type' => 'string'), 'unTermOnFail' => array('type' => 'string'), 'sync' => array('type' => 'array'), 'syncInstances' => array('type' => 'array')));
     $syncInstances = $this->getParam('syncInstances');
     foreach ($this->getParam('sync') as $farmRoleId) {
         $serverId = $syncInstances[$farmRoleId];
         $dbServer = DBServer::LoadByID($serverId);
         $this->user->getPermissions()->validate($dbServer);
         $serverSnapshotCreateInfo = new ServerSnapshotCreateInfo($dbServer, BundleTask::GenerateRoleName($dbServer->GetFarmRoleObject(), $dbServer), SERVER_REPLACEMENT_TYPE::REPLACE_FARM, false, sprintf(_("Server snapshot created during farm '%s' termination at %s"), $dbServer->GetFarmObject()->Name, date("M j, Y H:i:s")));
         BundleTask::Create($serverSnapshotCreateInfo);
     }
     $removeZoneFromDNS = $this->getParam('deleteDNSZones') == 'on' ? 1 : 0;
     $keepCloudObjects = $this->getParam('deleteCloudObjects') == 'on' ? 0 : 1;
     $termOnFail = $this->getParam('unTermOnFail') == 'on' ? 0 : 1;
     $event = new FarmTerminatedEvent($removeZoneFromDNS, $keepCloudObjects, $termOnFail, $keepCloudObjects);
     Scalr::FireEvent($this->getParam('farmId'), $event);
     $this->response->success('Farm successfully terminated. Instances termination can take a few minutes.');
 }