/** launchOptions: imageId */ public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $DBRole = DBRole::loadById($DBServer->roleId); $launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::OPENSTACK, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)); $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_FLAVOR_ID); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } $launchOptions->userData = trim($u_data, ";"); $launchOptions->architecture = 'x86_64'; } $osClient = $this->getOsClient($DBServer->GetEnvironmentObject(), $launchOptions->cloudLocation); $result = $osClient->serverCreate($DBServer->serverId, $launchOptions->imageId, $launchOptions->serverType, base64_encode($launchOptions->userData), array('path' => '/etc/scalr/private.d/.user-data', 'contents' => base64_encode($launchOptions->userData))); if ($result->server) { //TODO: $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $result->server->id); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::IMAGE_ID, $result->server->image->id); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID, $result->server->flavor->id); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::ADMIN_PASS, $result->server->adminPass); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::NAME, $DBServer->serverId); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::HOST_ID, $result->server->hostId); $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION, $launchOptions->cloudLocation); return $DBServer; } else { throw new Exception(sprintf(_("Cannot launch new instance. %s"), $result->faultstring)); } }
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $environment = $DBServer->GetEnvironmentObject(); $diskOffering = null; $size = null; if (!$launchOptions) { $farmRole = $DBServer->GetFarmRoleObject(); $launchOptions = new Scalr_Server_LaunchOptions(); $dbRole = DBRole::loadById($DBServer->roleId); $launchOptions->imageId = $dbRole->getImageId($this->platform, $DBServer->GetFarmRoleObject()->CloudLocation); $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SERVICE_OFFERING_ID); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; /* * User Data */ foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } $launchOptions->userData = trim($u_data, ";"); $diskOffering = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_DISK_OFFERING_ID); if ($diskOffering === false || $diskOffering === null) { $diskOffering = null; } $sharedIp = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SHARED_IP_ID); $networkType = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE); $networkId = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_ID); $roleName = $farmRole->GetRoleObject()->name; } else { $launchOptions->userData = array(); $roleName = 'TemporaryScalrServer' . rand(100, 999); } $launchOptions->architecture = 'x86_64'; $cs = $this->getCloudStackClient($environment, $launchOptions->cloudLocation); if (!$sharedIp) { if ($networkId && ($networkType == 'Virtual' || $networkType == 'Isolated' || !$networkType)) { $sharedIpId = $this->getConfigVariable(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}", $environment, false); if (!$sharedIpId) { $ipResult = $cs->associateIpAddress($launchOptions->cloudLocation); $ipId = $ipResult->id; if ($ipId) { while (true) { $ipInfo = $cs->listPublicIpAddresses($ipId); $ipInfo = $ipInfo->publicipaddress[0]; if (!$ipInfo) { throw new Exception("Cannot allocate IP address: listPublicIpAddresses -> failed"); } if ($ipInfo->state == 'Allocated') { $this->setConfigVariable(array(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}" => $ipId), $environment, false); $this->setConfigVariable(array(self::SHARED_IP . ".{$launchOptions->cloudLocation}" => $ipInfo->ipaddress), $environment, false); $this->setConfigVariable(array(self::SHARED_IP_INFO . ".{$launchOptions->cloudLocation}" => serialize($ipInfo)), $environment, false); $sharedIpId = $ipId; break; } else { if ($ipInfo->state == 'Allocating') { sleep(1); } else { throw new Exception("Cannot allocate IP address: ipAddress->state = {$ipInfo->state}"); } } } } else { throw new Exception("Cannot allocate IP address: associateIpAddress -> failed"); } } } } if ($DBServer->status == SERVER_STATUS::TEMPORARY) { $keyName = "SCALR-ROLESBUILDER-" . SCALR_ID; $farmId = 0; } else { $keyName = "FARM-{$DBServer->farmId}-" . SCALR_ID; $farmId = $DBServer->farmId; } $sshKey = Scalr_SshKey::init(); try { if (!$sshKey->loadGlobalByName($keyName, "", $DBServer->envId, $this->platform)) { $result = $cs->createSSHKeyPair($keyName); if ($result->keypair->privatekey) { $sshKey->farmId = $farmId; $sshKey->clientId = $DBServer->clientId; $sshKey->envId = $DBServer->envId; $sshKey->type = Scalr_SshKey::TYPE_GLOBAL; $sshKey->cloudLocation = ""; //$launchOptions->cloudLocation; $sshKey->cloudKeyName = $keyName; $sshKey->platform = $this->platform; $sshKey->setPrivate($result->keypair->privatekey); $sshKey->setPublic($sshKey->generatePublicKey()); $sshKey->save(); } } } catch (Exception $e) { Logger::getLogger("CloudStack")->error(new FarmLogMessage($DBServer->farmId, "Unable to generate keypair: {$e->getMessage()}")); } $vResult = $cs->deployVirtualMachine($launchOptions->serverType, $launchOptions->imageId, $launchOptions->cloudLocation, null, $diskOffering, $DBServer->serverId, null, $roleName, null, null, $keyName, "", $networkId, null, null, $size, base64_encode($launchOptions->userData)); if ($vResult->id) { $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $vResult->id); $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION, $launchOptions->cloudLocation); $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::LAUNCH_JOB_ID, $vResult->jobid); $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture); return $DBServer; } else { throw new Exception(sprintf("Cannot launch new instance: %s", $vResult->errortext)); } }
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $runInstanceRequest = new RunInstancesRequestData(isset($launchOptions->imageId) ? $launchOptions->imageId : null, 1, 1); $environment = $DBServer->GetEnvironmentObject(); $placementData = null; $noSecurityGroups = false; if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $DBRole = DBRole::loadById($DBServer->roleId); $dbFarmRole = $DBServer->GetFarmRoleObject(); /* $runInstanceRequest->setMonitoring( $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_ENABLE_CW_MONITORING) ); */ $launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS, $dbFarmRole->CloudLocation); // Need OS Family to get block device mapping for OEL roles $imageInfo = $DBRole->getImageDetails(SERVER_PLATFORMS::EUCALYPTUS, $dbFarmRole->CloudLocation); $launchOptions->osFamily = $imageInfo['os_family']; $launchOptions->cloudLocation = $dbFarmRole->CloudLocation; $akiId = $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::EKIID); if (!$akiId) { $akiId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_EUCA_EKI_ID); } if ($akiId) { $runInstanceRequest->kernelId = $akiId; } $ariId = $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::ERIID); if (!$ariId) { $ariId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_EUCA_ERI_ID); } if ($ariId) { $runInstanceRequest->ramdiskId = $ariId; } $launchOptions->serverType = $dbFarmRole->GetSetting(DBFarmRole::SETTING_EUCA_INSTANCE_TYPE); /* if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_OPTIMIZED) == 1) { $runInstanceRequest->ebsOptimized = true; } else { $runInstanceRequest->ebsOptimized = false; } */ foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } $runInstanceRequest->userData = base64_encode(trim($u_data, ";")); /* $vpcId = $dbFarmRole->GetFarmObject()->GetSetting(DBFarm::SETTING_EC2_VPC_ID); if ($vpcId) { if ($DBRole->hasBehavior(ROLE_BEHAVIORS::VPC_ROUTER)) { $networkInterface = new InstanceNetworkInterfaceSetRequestData(); $networkInterface->networkInterfaceId = $dbFarmRole->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_NID); $networkInterface->deviceIndex = 0; $networkInterface->deleteOnTermination = false; $runInstanceRequest->setNetworkInterface($networkInterface); $noSecurityGroups = true; } else { $vpcSubnetId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_SUBNET_ID); $vpcInternetAccess = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_INTERNET_ACCESS); if (!$vpcSubnetId) { $aws = $environment->aws($launchOptions->cloudLocation); $subnet = $this->AllocateNewSubnet( $aws->ec2, $vpcId, $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_AVAIL_ZONE), 24 ); try { $subnet->createTags(array( array('key' => "scalr-id", 'value' => SCALR_ID), array('key' => "scalr-sn-type", 'value' => $vpcInternetAccess), array('key' => "Name", 'value' => 'Scalr System Subnet') )); } catch (Exception $e) {} try { $routeTableId = $dbFarmRole->GetSetting(DBFarmRole::SETTING_AWS_VPC_ROUTING_TABLE_ID); Logger::getLogger('VPC')->warn(new FarmLogMessage($DBServer->farmId, "Internet access: {$vpcInternetAccess}")); if (!$routeTableId) { if ($vpcInternetAccess == Scalr_Role_Behavior_Router::INTERNET_ACCESS_OUTBOUND) { $routerRole = $DBServer->GetFarmObject()->GetFarmRoleByBehavior(ROLE_BEHAVIORS::VPC_ROUTER); if (!$routerRole) { if (\Scalr::config('scalr.instances_connection_policy') != 'local') throw new Exception("Outbound access require VPC router role in farm"); } $networkInterfaceId = $routerRole->GetSetting(Scalr_Role_Behavior_Router::ROLE_VPC_NID); Logger::getLogger('EC2')->warn(new FarmLogMessage($DBServer->farmId, "Requesting outbound routing table. NID: {$networkInterfaceId}")); $routeTableId = $this->getRoutingTable($vpcInternetAccess, $aws, $networkInterfaceId, $vpcId); Logger::getLogger('EC2')->warn(new FarmLogMessage($DBServer->farmId, "Routing table ID: {$routeTableId}")); } elseif ($vpcInternetAccess == Scalr_Role_Behavior_Router::INTERNET_ACCESS_FULL) { $routeTableId = $this->getRoutingTable($vpcInternetAccess, $aws, null, $vpcId); } } $aws->ec2->routeTable->associate($routeTableId, $subnet->subnetId); } catch (Exception $e) { Logger::getLogger('EC2')->warn(new FarmLogMessage($DBServer->farmId, "Removing allocated subnet, due to routing table issues")); $aws->ec2->subnet->delete($subnet->subnetId); throw $e; } $vpcSubnetId = $subnet->subnetId; $dbFarmRole->SetSetting(DBFarmRole::SETTING_AWS_VPC_SUBNET_ID, $vpcSubnetId, DBFarmRole::TYPE_LCL); } if ($vpcSubnetId) { $runInstanceRequest->subnetId = $vpcSubnetId; } else throw new Exception("Unable to define subnetId for role in VPC"); } } */ $vpcId = false; } else { $runInstanceRequest->userData = base64_encode(trim($launchOptions->userData)); } $governance = new Scalr_Governance($DBServer->envId); $euca = $environment->eucalyptus($launchOptions->cloudLocation); // Set AMI, AKI and ARI ids $runInstanceRequest->imageId = $launchOptions->imageId; $runInstanceRequest->instanceInitiatedShutdownBehavior = 'terminate'; if (!$noSecurityGroups) { foreach ($this->GetServerSecurityGroupsList($DBServer, $euca->ec2, $vpcId, $governance) as $sgroup) { $runInstanceRequest->appendSecurityGroupId($sgroup); } if (!$runInstanceRequest->subnetId) { // Set availability zone if (!$launchOptions->availZone) { $avail_zone = $this->GetServerAvailZone($DBServer, $euca->ec2, $launchOptions); if ($avail_zone) { $placementData = new PlacementResponseData($avail_zone); } } else { $placementData = new PlacementResponseData($launchOptions->availZone); } } } $runInstanceRequest->minCount = 1; $runInstanceRequest->maxCount = 1; // Set instance type $runInstanceRequest->instanceType = $launchOptions->serverType; if ($placementData !== null) { $runInstanceRequest->setPlacement($placementData); } $sshKey = Scalr_SshKey::init(); if ($DBServer->status == SERVER_STATUS::TEMPORARY) { $keyName = "SCALR-ROLESBUILDER-" . SCALR_ID; $farmId = 0; } else { $keyName = $governance->getValue(Scalr_Governance::AWS_KEYPAIR); if ($keyName) { $skipKeyValidation = true; } else { $keyName = "FARM-{$DBServer->farmId}-" . SCALR_ID; $farmId = $DBServer->farmId; $oldKeyName = "FARM-{$DBServer->farmId}"; if ($sshKey->loadGlobalByName($oldKeyName, $launchOptions->cloudLocation, $DBServer->envId, SERVER_PLATFORMS::EUCALYPTUS)) { $keyName = $oldKeyName; $skipKeyValidation = true; } } } if (!$skipKeyValidation && !$sshKey->loadGlobalByName($keyName, $launchOptions->cloudLocation, $DBServer->envId, SERVER_PLATFORMS::EUCALYPTUS)) { $result = $euca->ec2->keyPair->create($keyName); if ($result->keyMaterial) { $sshKey->farmId = $farmId; $sshKey->clientId = $DBServer->clientId; $sshKey->envId = $DBServer->envId; $sshKey->type = Scalr_SshKey::TYPE_GLOBAL; $sshKey->cloudLocation = $launchOptions->cloudLocation; $sshKey->cloudKeyName = $keyName; $sshKey->platform = SERVER_PLATFORMS::EUCALYPTUS; $sshKey->setPrivate($result->keyMaterial); $sshKey->setPublic($sshKey->generatePublicKey()); $sshKey->save(); } } $runInstanceRequest->keyName = $keyName; try { $result = $euca->ec2->instance->run($runInstanceRequest); } catch (Exception $e) { if (stristr($e->getMessage(), "The key pair") && stristr($e->getMessage(), "does not exist")) { $sshKey->delete(); throw $e; } if (stristr($e->getMessage(), "The requested Availability Zone is no longer supported") || stristr($e->getMessage(), "is not supported in your requested Availability Zone") || stristr($e->getMessage(), "is currently constrained and we are no longer accepting new customer requests")) { $availZone = $runInstanceRequest->getPlacement() ? $runInstanceRequest->getPlacement()->availabilityZone : null; if ($availZone) { $DBServer->GetEnvironmentObject()->setPlatformConfig(array("eucalyptus.{$launchOptions->cloudLocation}.{$availZone}.unavailable" => time())); } throw $e; } else { throw $e; } } if ($result->instancesSet->get(0)->instanceId) { $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::AVAIL_ZONE, $result->instancesSet->get(0)->placement->availabilityZone); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::INSTANCE_ID, $result->instancesSet->get(0)->instanceId); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::INSTANCE_TYPE, $runInstanceRequest->instanceType); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::EMIID, $runInstanceRequest->imageId); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::REGION, $launchOptions->cloudLocation); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::ARCHITECTURE, $result->instancesSet->get(0)->architecture); $DBServer->osType = $result->instancesSet->get(0)->platform ? $result->instancesSet->get(0)->platform : 'linux'; return $DBServer; } else { throw new Exception(sprintf(_("Cannot launch new instance. %s"), serialize($result))); } }
/** launchOptions: imageId */ public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $DBRole = DBRole::loadById($DBServer->roleId); $launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::RACKSPACE, $DBServer->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)); $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_RS_FLAVOR_ID); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } $launchOptions->userData = trim($u_data, ";"); $launchOptions->architecture = 'x86_64'; } $rsClient = $this->getRsClient($DBServer->GetEnvironmentObject(), $launchOptions->cloudLocation); //Cannot launch new instance. Request to Rackspace failed (Code: 413): {"overLimit":{"message":"Too many requests...","code":413,"retryAfter":"2012-03-12T09:44:56.343-05:00"}} (19641119, 4) try { $result = $rsClient->createServer($DBServer->serverId, $launchOptions->imageId, $launchOptions->serverType, array(), array('path' => '/etc/scalr/private.d/.user-data', 'contents' => base64_encode($launchOptions->userData))); } catch (Exception $e) { throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), $e->getMessage(), $launchOptions->imageId, $launchOptions->serverType)); } if ($result->server) { $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::SERVER_ID, $result->server->id); $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::IMAGE_ID, $result->server->imageId); $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::FLAVOR_ID, $result->server->flavorId); $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::ADMIN_PASS, $result->server->adminPass); $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::NAME, $DBServer->serverId); $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::HOST_ID, $result->server->hostId); $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture); $DBServer->SetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER, $launchOptions->cloudLocation); return $DBServer; } else { throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), serialize($result), $launchOptions->imageId, $launchOptions->serverType)); } }
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $DBRole = DBRole::loadById($DBServer->roleId); $eucaClient = $this->getEucaClient($DBServer->GetEnvironmentObject(), $DBServer->GetCloudLocation()); $i_type = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_EUCA_INSTANCE_TYPE); foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } /* $imageId, $instanceType, $keyName = null, $availZone = null, $securityGroup = array(), $userData = "", $minCount = 1, $maxCount = 1, $kernelId = null, $ramdiskId = null, $monitoring = false */ $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $DBRole->architecture); $key_pair_name = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($DBServer->farmId, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION))->cloudKeyName; $result = $eucaClient->runInstances($DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION)), $i_type, $key_pair_name, $this->GetServerAvailZone($DBServer), $this->GetServerSecurityGroupsList($DBServer, $eucaClient), trim($u_data, ";")); if ($result->instancesSet) { $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::AVAIL_ZONE, (string) $result->instancesSet->item[0]->placement->availabilityZone); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::INSTANCE_ID, (string) $result->instancesSet->item[0]->instanceId); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::INSTANCE_TYPE, $i_type); $DBServer->SetProperty(EUCA_SERVER_PROPERTIES::EMIID, $DBRole->getImageId(SERVER_PLATFORMS::EUCALYPTUS, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION))); return $DBServer; } }
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $environment = $DBServer->GetEnvironmentObject(); if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $DBRole = DBRole::loadById($DBServer->roleId); $launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::GCE, $DBServer->GetProperty(GCE_SERVER_PROPERTIES::CLOUD_LOCATION)); $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_GCE_MACHINE_TYPE); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; $userData = $DBServer->GetCloudUserData(); $launchOptions->architecture = 'x86_64'; $networkName = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_GCE_NETWORK); } else { $userData = array(); $networkName = 'default'; } if ($DBServer->status == SERVER_STATUS::TEMPORARY) { $keyName = "SCALR-ROLESBUILDER-" . SCALR_ID; } else { $keyName = "FARM-{$DBServer->farmId}-" . SCALR_ID; } $sshKey = Scalr_SshKey::init(); if (!$sshKey->loadGlobalByName($keyName, "", $DBServer->envId, SERVER_PLATFORMS::GCE)) { $keys = $sshKey->generateKeypair(); if ($keys['public']) { $sshKey->farmId = $DBServer->farmId; $sshKey->clientId = $DBServer->clientId; $sshKey->envId = $DBServer->envId; $sshKey->type = Scalr_SshKey::TYPE_GLOBAL; $sshKey->cloudLocation = ""; $sshKey->cloudKeyName = $keyName; $sshKey->platform = SERVER_PLATFORMS::GCE; $sshKey->save(); $publicKey = $keys['public']; } else { throw new Exception("Scalr unable to generate ssh keypair"); } } else { $publicKey = $sshKey->getPublic(); } $gce = $this->getClient($environment, $launchOptions->cloudLocation); // // // Check firewall $firewalls = $gce->firewalls->listFirewalls($environment->getPlatformConfigValue(self::PROJECT_ID)); $firewallFound = false; foreach ($firewalls->getItems() as $f) { if ($f->getName() == 'scalr-system') { $firewallFound = true; break; } } // Create scalr firewall if (!$firewallFound) { $firewall = new Google_Firewall(); $firewall->setName('scalr-system'); $firewall->setNetwork($this->getObjectUrl($networkName, 'networks', $environment->getPlatformConfigValue(self::PROJECT_ID))); //Get scalr IP-pool IP list and set source ranges $firewall->setSourceRanges(\Scalr::config('scalr.aws.ip_pool')); // Set ports $tcp = new Google_FirewallAllowed(); $tcp->setIPProtocol('tcp'); $tcp->setPorts(array('1-65535')); $udp = new Google_FirewallAllowed(); $udp->setIPProtocol('udp'); $udp->setPorts(array('1-65535')); $firewall->setAllowed(array($tcp, $udp)); // Set target tags $firewall->setTargetTags(array('scalr')); $gce->firewalls->insert($environment->getPlatformConfigValue(self::PROJECT_ID), $firewall); } /// //// ////// $instance = new Google_Instance(); $instance->setKind("compute#instance"); $accessConfig = new Google_AccessConfig(); $accessConfig->setName("External NAT"); $accessConfig->setType("ONE_TO_ONE_NAT"); $network = new Google_NetworkInterface(); $network->setNetwork($this->getObjectUrl($networkName, 'networks', $environment->getPlatformConfigValue(self::PROJECT_ID))); $network->setAccessConfigs(array($accessConfig)); $instance->setNetworkInterfaces(array($network)); $serviceAccount = new Google_ServiceAccount(); $serviceAccount->setEmail("default"); $serviceAccount->setScopes(array("https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.full_control")); $instance->setServiceAccounts(array($serviceAccount)); if ($launchOptions->cloudLocation != 'x-scalr-custom') { $availZone = $launchOptions->cloudLocation; } else { $location = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_GCE_CLOUD_LOCATION); $availZones = array(); if (stristr($location, "x-scalr-custom")) { $zones = explode("=", $location); foreach (explode(":", $zones[1]) as $zone) { if ($zone != "") { array_push($availZones, $zone); } } } sort($availZones); $availZones = array_reverse($availZones); $servers = $DBServer->GetFarmRoleObject()->GetServersByFilter(array("status" => array(SERVER_STATUS::RUNNING, SERVER_STATUS::INIT, SERVER_STATUS::PENDING))); $availZoneDistribution = array(); foreach ($servers as $cDbServer) { if ($cDbServer->serverId != $DBServer->serverId) { $availZoneDistribution[$cDbServer->GetProperty(GCE_SERVER_PROPERTIES::CLOUD_LOCATION)]++; } } $sCount = 1000000; foreach ($availZones as $zone) { if ((int) $availZoneDistribution[$zone] <= $sCount) { $sCount = (int) $availZoneDistribution[$zone]; $availZone = $zone; } } $aZones = implode(",", $availZones); // Available zones $dZones = ""; // Zones distribution foreach ($availZoneDistribution as $zone => $num) { $dZones .= "({$zone}:{$num})"; } $DBServer->SetProperty("tmp.gce.avail_zone.algo2", "[A:{$aZones}][D:{$dZones}][S:{$availZone}]"); } $instance->setZone($this->getObjectUrl($availZone, 'zones', $environment->getPlatformConfigValue(self::PROJECT_ID))); $instance->setMachineType($this->getObjectUrl($launchOptions->serverType, 'machineTypes', $environment->getPlatformConfigValue(self::PROJECT_ID), $availZone)); $instance->setImage($this->getObjectUrl($launchOptions->imageId, 'images', $environment->getPlatformConfigValue(self::PROJECT_ID))); $instance->setName($DBServer->serverId); $tags = array('scalr', "env-{$DBServer->envId}"); if ($DBServer->farmId) { $tags[] = "farm-{$DBServer->farmId}"; } if ($DBServer->farmRoleId) { $tags[] = "farmrole-{$DBServer->farmRoleId}"; } $gTags = new Google_Tags(); $gTags->setItems($tags); $instance->setTags($gTags); $metadata = new Google_Metadata(); $items = array(); // Set user data foreach ($userData as $k => $v) { $uData .= "{$k}={$v};"; } $uData = trim($uData, ";"); if ($uData) { $item = new Google_MetadataItems(); $item->setKey('scalr'); $item->setValue($uData); $items[] = $item; } // Add SSH Key $item = new Google_MetadataItems(); $item->setKey("sshKeys"); $item->setValue("scalr:{$publicKey}"); $items[] = $item; $metadata->setItems($items); $instance->setMetadata($metadata); try { $result = $gce->instances->insert($environment->getPlatformConfigValue(self::PROJECT_ID), $availZone, $instance); } catch (Exception $e) { throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), $e->getMessage(), $launchOptions->imageId, $launchOptions->serverType)); } if ($result->id) { $DBServer->SetProperty(GCE_SERVER_PROPERTIES::PROVISIONING_OP_ID, $result->name); $DBServer->SetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME, $DBServer->serverId); $DBServer->SetProperty(GCE_SERVER_PROPERTIES::SERVER_ID, $DBServer->serverId); $DBServer->SetProperty(GCE_SERVER_PROPERTIES::CLOUD_LOCATION, $availZone); $DBServer->SetProperty(GCE_SERVER_PROPERTIES::MACHINE_TYPE, $launchOptions->serverType); $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture); return $DBServer; } else { throw new Exception(sprintf(_("Cannot launch new instance. %s (%s, %s)"), serialize($result), $launchOptions->imageId, $launchOptions->serverType)); } }
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $environment = $DBServer->GetEnvironmentObject(); $farmRole = $DBServer->GetFarmRoleObject(); if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $dbRole = DBRole::loadById($DBServer->roleId); $launchOptions->imageId = $dbRole->getImageId(SERVER_PLATFORMS::CLOUDSTACK, $DBServer->GetFarmRoleObject()->CloudLocation); $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SERVICE_OFFERING_ID); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; /* * User Data */ foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } $launchOptions->userData = trim($u_data, ";"); $launchOptions->architecture = 'x86_64'; } $cs = $this->getCloudStackClient($environment, $launchOptions->cloudLocation); $networkType = $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE); if ($networkType == 'Virtual') { $sharedIpId = $environment->getPlatformConfigValue(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}", false); if (!$sharedIpId) { $ipResult = $cs->associateIpAddress($launchOptions->cloudLocation); $ipId = $ipResult->id; if ($ipId) { while (true) { $ipInfo = $cs->listPublicIpAddresses($ipId); $ipInfo = $ipInfo->publicipaddress[0]; if (!$ipInfo) { throw new Exception("Cannot allocate IP address: listPublicIpAddresses -> failed"); } if ($ipInfo->state == 'Allocated') { $environment->setPlatformConfig(array(self::SHARED_IP_ID . ".{$launchOptions->cloudLocation}" => $ipId), false); $environment->setPlatformConfig(array(self::SHARED_IP . ".{$launchOptions->cloudLocation}" => $ipInfo->ipaddress), false); $environment->setPlatformConfig(array(self::SHARED_IP_INFO . ".{$launchOptions->cloudLocation}" => serialize($ipInfo)), false); $sharedIpId = $ipId; break; } else { if ($ipInfo->state == 'Allocating') { sleep(1); } else { throw new Exception("Cannot allocate IP address: ipAddress->state = {$ipInfo->state}"); } } } } else { throw new Exception("Cannot allocate IP address: associateIpAddress -> failed"); } } } $sshKey = Scalr_SshKey::init(); try { if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $launchOptions->cloudLocation)) { $key_name = "FARM-{$DBServer->farmId}"; $result = $cs->createSSHKeyPair($key_name); if ($result->keypair->privatekey) { $sshKey->farmId = $DBServer->farmId; $sshKey->clientId = $DBServer->clientId; $sshKey->envId = $DBServer->envId; $sshKey->type = Scalr_SshKey::TYPE_GLOBAL; $sshKey->cloudLocation = $launchOptions->cloudLocation; $sshKey->cloudKeyName = $key_name; $sshKey->platform = SERVER_PLATFORMS::CLOUDSTACK; $sshKey->setPrivate($result->keypair->privatekey); $sshKey->setPublic($sshKey->generatePublicKey()); $sshKey->save(); } } } catch (Exception $e) { } $keyName = $sshKey->cloudKeyName; $vResult = $cs->deployVirtualMachine($launchOptions->serverType, $launchOptions->imageId, $launchOptions->cloudLocation, null, null, "", null, $farmRole->GetRoleObject()->name, null, null, $keyName, "", $farmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_ID), null, null, null, base64_encode($launchOptions->userData)); if ($vResult->id) { $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $vResult->id); $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION, $launchOptions->cloudLocation); $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::LAUNCH_JOB_ID, $vResult->jobid); return $DBServer; } else { throw new Exception(sprintf("Cannot launch new instance: %s", $vResult->errortext)); } }
/** launchOptions: imageId */ public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $config = \Scalr::getContainer()->config; if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $DBRole = DBRole::loadById($DBServer->roleId); $launchOptions->imageId = $DBRole->getImageId($this->platform, $DBServer->GetFarmRoleObject()->CloudLocation); $launchOptions->serverType = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_FLAVOR_ID); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; $launchOptions->userData = $DBServer->GetCloudUserData(); $launchOptions->userData['region'] = $DBServer->GetFarmRoleObject()->CloudLocation; foreach ($launchOptions->userData as $k => $v) { if (!$v) { unset($launchOptions->userData[$k]); } } $launchOptions->architecture = 'x86_64'; $isWindows = $DBServer->osType == 'windows' || $DBRole->osFamily == 'windows'; } else { $launchOptions->userData = array(); $isWindows = $DBServer->osType == 'windows'; } $environment = $DBServer->GetEnvironmentObject(); $client = $this->getOsClient($environment, $launchOptions->cloudLocation); // Prepare user data $u_data = ""; foreach ($launchOptions->userData as $k => $v) { $u_data .= "{$k}={$v};"; } $u_data = trim($u_data, ";"); $personality = new PersonalityList(); if ($isWindows) { $personality->append(new Personality('C:\\Program Files\\Scalarizr\\etc\\private.d\\.user-data', base64_encode($u_data))); } else { if ($DBServer->platform == SERVER_PLATFORMS::ECS) { $personality->append(new Personality('/etc/.scalr-user-data', base64_encode($u_data))); } else { $personality->append(new Personality('/etc/scalr/private.d/.user-data', base64_encode($u_data))); } } //Check SecurityGroups $securityGroupsEnabled = $this->getConfigVariable(self::EXT_SECURITYGROUPS_ENABLED, $environment, false); if ($securityGroupsEnabled === null || $securityGroupsEnabled === false) { if ($client->servers->isExtensionSupported(ServersExtension::securityGroups())) { $securityGroupsEnabled = 1; } else { $securityGroupsEnabled = 0; } $this->setConfigVariable(array(self::EXT_SECURITYGROUPS_ENABLED => $securityGroupsEnabled), $environment, false); } if ($securityGroupsEnabled) { $securityGroups = $this->GetServerSecurityGroupsList($DBServer, $client); foreach ($securityGroups as $sg) { $itm = new stdClass(); $itm->name = $sg; $extProperties['security_groups'][] = $itm; } } //Check key-pairs $keyPairsEnabled = $this->getConfigVariable(self::EXT_KEYPAIRS_ENABLED, $environment, false); if ($keyPairsEnabled === null || $keyPairsEnabled === false) { if ($client->servers->isExtensionSupported(ServersExtension::keypairs())) { $keyPairsEnabled = 1; } else { $keyPairsEnabled = 0; } $this->setConfigVariable(array(self::EXT_KEYPAIRS_ENABLED => $keyPairsEnabled), $environment, false); } if ($keyPairsEnabled) { $sshKey = Scalr_SshKey::init(); if ($DBServer->status == SERVER_STATUS::TEMPORARY) { $keyName = "SCALR-ROLESBUILDER-" . SCALR_ID; $farmId = 0; } else { $keyName = "FARM-{$DBServer->farmId}-" . SCALR_ID; $farmId = $DBServer->farmId; } if ($sshKey->loadGlobalByName($keyName, $launchOptions->cloudLocation, $DBServer->envId, SERVER_PLATFORMS::OPENSTACK)) { $keyLoaded = true; } if (!$keyLoaded && !$sshKey->loadGlobalByName($keyName, $launchOptions->cloudLocation, $DBServer->envId, $DBServer->platform)) { $result = $client->servers->createKeypair($keyName); if ($result->private_key) { $sshKey->farmId = $farmId; $sshKey->clientId = $DBServer->clientId; $sshKey->envId = $DBServer->envId; $sshKey->type = Scalr_SshKey::TYPE_GLOBAL; $sshKey->cloudLocation = $launchOptions->cloudLocation; $sshKey->cloudKeyName = $keyName; $sshKey->platform = $DBServer->platform; $sshKey->setPrivate($result->private_key); $sshKey->setPublic($result->public_key); $sshKey->save(); } } $extProperties['key_name'] = $keyName; } //TODO: newtorks $networks = null; $osUserData = null; $osPersonality = null; $userDataMethod = $config->defined("scalr.{$this->platform}.user_data_method") ? $config("scalr.{$this->platform}.user_data_method") : null; if (!$userDataMethod || $userDataMethod == 'both' || $userDataMethod == 'personality') { $osPersonality = $personality; } if (!$userDataMethod || $userDataMethod == 'both' || $userDataMethod == 'meta-data') { $osUserData = $launchOptions->userData; } try { $result = $client->servers->createServer($DBServer->serverId, $launchOptions->serverType, $launchOptions->imageId, null, $osUserData, $osPersonality, $networks, $extProperties); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $result->id); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::IMAGE_ID, $launchOptions->imageId); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID, $launchOptions->serverType); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::ADMIN_PASS, $result->adminPass); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::NAME, $DBServer->serverId); $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture); $DBServer->SetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION, $launchOptions->cloudLocation); $DBServer->SetProperty(SERVER_PROPERTIES::SYSTEM_USER_DATA_METHOD, $userDataMethod); if ($DBServer->farmRoleId) { $ipPool = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_IP_POOL); if ($ipPool) { $DBServer->SetProperty(SERVER_PROPERTIES::SYSTEM_IGNORE_INBOUND_MESSAGES, 1); } } $DBServer->osType = $isWindows ? 'windows' : 'linux'; return $DBServer; } catch (Exception $e) { if (stripos($e->getMessage(), 'Invalid key_name provided')) { $sshKey->delete(); throw new Exception(sprintf(_("Cannot launch new instance: KeyPair was removed from cloud. Re-generating it."), $e->getMessage())); } throw new Exception(sprintf(_("Cannot launch new instance. %s"), $e->getMessage())); } }
public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null) { $RunInstancesType = new RunInstancesType(); $RunInstancesType->ConfigureRootPartition(); if (!$launchOptions) { $launchOptions = new Scalr_Server_LaunchOptions(); $DBRole = DBRole::loadById($DBServer->roleId); // Set Cloudwatch monitoring $RunInstancesType->SetCloudWatchMonitoring($DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_ENABLE_CW_MONITORING)); $launchOptions->architecture = $DBRole->architecture; $launchOptions->imageId = $DBRole->getImageId(SERVER_PLATFORMS::EC2, $DBServer->GetFarmRoleObject()->CloudLocation); $launchOptions->cloudLocation = $DBServer->GetFarmRoleObject()->CloudLocation; $akiId = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AKIID); if (!$akiId) { $akiId = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_AKI_ID); } if ($akiId) { $RunInstancesType->kernelId = $akiId; } $ariId = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::ARIID); if (!$ariId) { $ariId = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_ARI_ID); } if ($ariId) { $RunInstancesType->ramdiskId = $ariId; } $i_type = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_INSTANCE_TYPE); if (!$i_type) { $DBRole = DBRole::loadById($DBServer->roleId); $i_type = $DBRole->getProperty(EC2_SERVER_PROPERTIES::INSTANCE_TYPE); } $launchOptions->serverType = $i_type; foreach ($DBServer->GetCloudUserData() as $k => $v) { $u_data .= "{$k}={$v};"; } $RunInstancesType->SetUserData(trim($u_data, ";")); $vpcPrivateIp = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_VPC_PRIVATE_IP); $vpcSubnetId = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_VPC_SUBNET_ID); if ($vpcSubnetId) { $RunInstancesType->subnetId = $vpcSubnetId; if ($vpcPrivateIp) { $RunInstancesType->privateIpAddress = $vpcPrivateIp; } } } else { $RunInstancesType->SetUserData(trim($launchOptions->userData)); } $DBServer->SetProperty(SERVER_PROPERTIES::ARCHITECTURE, $launchOptions->architecture); $EC2Client = Scalr_Service_Cloud_Aws::newEc2($launchOptions->cloudLocation, $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::PRIVATE_KEY), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::CERTIFICATE)); // Set AMI, AKI and ARI ids $RunInstancesType->imageId = $launchOptions->imageId; if (!$RunInstancesType->subnetId) { // Set Security groups foreach ($this->GetServerSecurityGroupsList($DBServer, $EC2Client) as $sgroup) { $RunInstancesType->AddSecurityGroup($sgroup); } } $RunInstancesType->minCount = 1; $RunInstancesType->maxCount = 1; // Set availability zone if (!$launchOptions->availZone) { $avail_zone = $this->GetServerAvailZone($DBServer, $EC2Client, $launchOptions); if ($avail_zone) { $RunInstancesType->SetAvailabilityZone($avail_zone); } } else { $RunInstancesType->SetAvailabilityZone($launchOptions->availZone); } // Set instance type $RunInstancesType->instanceType = $launchOptions->serverType; if (in_array($RunInstancesType->instanceType, array('cc1.4xlarge', 'cg1.4xlarge', 'cc2.8xlarge'))) { $placementGroup = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_AWS_CLUSTER_PG); if (!$placementGroup) { $placementGroup = "scalr-role-{$DBServer->farmRoleId}"; if (!$EC2Client->CreatePlacementGroup($placementGroup)) { throw new Exception(sprintf(_("Cannot launch new instance. Unable to create placement group: %s"), $result->faultstring)); } $DBServer->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_AWS_CLUSTER_PG, $placementGroup); } $RunInstancesType->SetPlacementGroup($placementGroup); } // Set additional info $RunInstancesType->additionalInfo = ""; ///// if ($DBServer->status == SERVER_STATUS::TEMPORARY) { $keyName = "SCALR-ROLESBUILDER"; $sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY); if (!$sshKey->loadGlobalByName($keyName, $launchOptions->cloudLocation, $DBServer->envId)) { $result = $EC2Client->CreateKeyPair($keyName); if ($result->keyMaterial) { $sshKey->farmId = 0; $sshKey->clientId = $DBServer->clientId; $sshKey->envId = $DBServer->envId; $sshKey->type = Scalr_SshKey::TYPE_GLOBAL; $sshKey->cloudLocation = $launchOptions->cloudLocation; $sshKey->cloudKeyName = $keyName; $sshKey->platform = SERVER_PLATFORMS::EC2; $sshKey->setPrivate($result->keyMaterial); $sshKey->setPublic($sshKey->generatePublicKey()); $sshKey->save(); } } } else { $sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY)->loadGlobalByFarmId($DBServer->farmId, $DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION)); $keyName = $sshKey->cloudKeyName; } ///// $RunInstancesType->keyName = $keyName; try { $result = $EC2Client->RunInstances($RunInstancesType); } catch (Exception $e) { if (stristr($e->getMessage(), "key pair") && stristr($e->getMessage(), "does not exist")) { $result = $EC2Client->CreateKeyPair($keyName); if ($result->keyMaterial) { $sshKey->setPrivate($result->keyMaterial); $sshKey->setPublic($sshKey->generatePublicKey()); $sshKey->save(); } //Your requested instance type (m2.2xlarge) is not supported in your requested Availability Zone (us-east-1a). Please retry your request by not specifying an Availability Zone or choosing us-east-1c, us-east-1b, us-east-1 } else { if (stristr($e->getMessage(), "The requested Availability Zone is no longer supported") || stristr($e->getMessage(), "is not supported in your requested Availability Zone")) { $availZone = $RunInstancesType->placement->availabilityZone; $DBServer->GetEnvironmentObject()->setPlatformConfig(array("aws.{$launchOptions->cloudLocation}.{$availZone}.unavailable" => time()), false); throw $e; } else { throw $e; } } } if ($result->instancesSet) { $DBServer->SetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE, (string) $result->instancesSet->item->placement->availabilityZone); $DBServer->SetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID, (string) $result->instancesSet->item->instanceId); $DBServer->SetProperty(EC2_SERVER_PROPERTIES::INSTANCE_TYPE, $RunInstancesType->instanceType); $DBServer->SetProperty(EC2_SERVER_PROPERTIES::AMIID, $RunInstancesType->imageId); $DBServer->SetProperty(EC2_SERVER_PROPERTIES::REGION, $launchOptions->cloudLocation); try { if ($DBServer->farmId != 0) { $CreateTagsType = new CreateTagsType(array((string) $result->instancesSet->item->instanceId), array("scalr-farm-id" => $DBServer->farmId, "scalr-farm-name" => $DBServer->GetFarmObject()->Name, "scalr-farm-role-id" => $DBServer->farmRoleId, "scalr-role-name" => $DBServer->GetFarmRoleObject()->GetRoleObject()->name, "scalr-server-id" => $DBServer->serverId)); $EC2Client->CreateTags($CreateTagsType); } } catch (Exception $e) { Logger::getLogger('EC2')->warn("Cannot add tags to server: {$e->getMessage()}"); } return $DBServer; } else { throw new Exception(sprintf(_("Cannot launch new instance. %s"), serialize($result))); } }