本文整理汇总了PHP中DBServer::GetCloudUserData方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::GetCloudUserData方法的具体用法?PHP DBServer::GetCloudUserData怎么用?PHP DBServer::GetCloudUserData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBServer
的用法示例。
在下文中一共展示了DBServer::GetCloudUserData方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LaunchServer
/**
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));
}
}
示例2: LaunchServer
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);
//.........这里部分代码省略.........
示例3: LaunchServer
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}"));
//.........这里部分代码省略.........
示例4: LaunchServer
/**
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));
}
}
示例5: LaunchServer
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;
}
}
示例6: LaunchServer
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);
}
}
}
//.........这里部分代码省略.........
示例7: LaunchServer
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));
}
}
示例8: LaunchServer
/**
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;
}
//.........这里部分代码省略.........
示例9: LaunchServer
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();
//.........这里部分代码省略.........