当前位置: 首页>>代码示例>>PHP>>正文


PHP DBFarm::GetEnvironmentObject方法代码示例

本文整理汇总了PHP中DBFarm::GetEnvironmentObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarm::GetEnvironmentObject方法的具体用法?PHP DBFarm::GetEnvironmentObject怎么用?PHP DBFarm::GetEnvironmentObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBFarm的用法示例。


在下文中一共展示了DBFarm::GetEnvironmentObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: farmSave

 public static function farmSave(DBFarm $DBFarm, array $roles)
 {
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != SERVER_PLATFORMS::EUCALYPTUS) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
         if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
             $key_name = "FARM-{$DBFarm->ID}";
             $eucaClient = Scalr_Service_Cloud_Eucalyptus::newCloud($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::SECRET_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::ACCESS_KEY, true, $location), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Eucalyptus::EC2_URL, true, $location));
             $result = $eucaClient->CreateKeyPair($key_name);
             if ($result->keyMaterial) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->clientId = $DBFarm->ClientID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = SERVER_PLATFORMS::EUCALYPTUS;
                 $sshKey->setPrivate($result->keyMaterial);
                 $sshKey->save();
             }
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:26,代码来源:Eucalyptus.php

示例2: farmSave

 public static function farmSave(\DBFarm $DBFarm, array $roles)
 {
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != \SERVER_PLATFORMS::EC2) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $sshKey = \Scalr_Model::init(\Scalr_Model::SSH_KEY);
         if (!$sshKey->loadGlobalByFarmId($DBFarm->EnvID, $DBFarm->ID, $location, \SERVER_PLATFORMS::EC2)) {
             $key_name = "FARM-" . $DBFarm->ID . "-" . SCALR_ID;
             $aws = $DBFarm->GetEnvironmentObject()->aws($location);
             $result = $aws->ec2->keyPair->create($key_name);
             if (!empty($result->keyMaterial)) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = \Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = \SERVER_PLATFORMS::EC2;
                 $sshKey->setPrivate($result->keyMaterial);
                 $sshKey->save();
             }
         }
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:25,代码来源:Ec2Helper.php

示例3: farmSave

 public static function farmSave(DBFarm $DBFarm, array $roles)
 {
     foreach ($roles as $DBFarmRole) {
         if (!in_array($DBFarmRole->Platform, array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD))) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $platform = PlatformFactory::NewPlatform($DBFarmRole->Platform);
         $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($platform->getConfigVariable(Modules_Platforms_Cloudstack::API_URL, $DBFarm->GetEnvironmentObject()), $platform->getConfigVariable(Modules_Platforms_Cloudstack::API_KEY, $DBFarm->GetEnvironmentObject()), $platform->getConfigVariable(Modules_Platforms_Cloudstack::SECRET_KEY, $DBFarm->GetEnvironmentObject()), $DBFarmRole->Platform);
         $networkId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_ID);
         $set = fasle;
         foreach ($cs->listNetworks("", "", "", $networkId) as $network) {
             if ($network->id == $networkId) {
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE, $network->type, DBFarmRole::TYPE_LCL);
                 $set = true;
             }
         }
         if (!$set) {
             throw new Exception("Unable to get GuestIPType for Network #{$networkId}. Please try again later or choose another network offering.");
         }
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:22,代码来源:Cloudstack.php

示例4: farmSave

 public static function farmSave(DBFarm $DBFarm, array $roles)
 {
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != SERVER_PLATFORMS::CLOUDSTACK) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Cloudstack::API_URL), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Cloudstack::API_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Cloudstack::SECRET_KEY));
         $sshKey = Scalr_SshKey::init();
         if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
             $key_name = "FARM-{$DBFarm->ID}";
             $result = $cs->createSSHKeyPair($key_name);
             if ($result->keypair->privatekey) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->clientId = $DBFarm->ClientID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = SERVER_PLATFORMS::CLOUDSTACK;
                 $sshKey->setPrivate($result->keypair->privatekey);
                 $sshKey->setPublic($sshKey->generatePublicKey());
                 $sshKey->save();
             }
         }
         $networkId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_ID);
         $set = fasle;
         foreach ($cs->listNetworks("", "", "", $networkId) as $network) {
             if ($network->id == $networkId) {
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE, $network->type);
                 $set = true;
             }
         }
         if (!$set) {
             throw new Exception("Unable to get GuestIPType for Network #{$networkId}. Please try again later or choose another network offering.");
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:38,代码来源:Cloudstack.php

示例5: onFarmSave

 public function onFarmSave(DBFarm $dbFarm, DBFarmRole $dbFarmRole)
 {
     $vpcId = $dbFarm->GetSetting(Entity\FarmSetting::EC2_VPC_ID);
     if (!$vpcId) {
         //REMOVE VPC RELATED SETTINGS
         return;
     }
     if ($dbFarmRole->GetSetting(self::ROLE_VPC_ROUTER_CONFIGURED) == 1) {
         // ALL OBJECTS ALREADY CONFIGURED
         return true;
     }
     $aws = $dbFarm->GetEnvironmentObject()->aws($dbFarmRole->CloudLocation);
     $niId = $dbFarmRole->GetSetting(self::ROLE_VPC_NID);
     // If there is no public IP allocate it and associate with NI
     $publicIp = $dbFarmRole->GetSetting(self::ROLE_VPC_IP);
     if ($niId && !$publicIp) {
         $filter = array(array('name' => AddressFilterNameType::networkInterfaceId(), 'value' => $niId));
         $addresses = $aws->ec2->address->describe(null, null, $filter);
         $address = $addresses->get(0);
         $associate = false;
         if (!$address) {
             $address = $aws->ec2->address->allocate('vpc');
             $associate = true;
         }
         $publicIp = $address->publicIp;
         if ($associate) {
             $associateAddressRequestData = new AssociateAddressRequestData();
             $associateAddressRequestData->networkInterfaceId = $niId;
             $associateAddressRequestData->allocationId = $address->allocationId;
             $associateAddressRequestData->allowReassociation = true;
             //Associate PublicIP with NetworkInterface
             $aws->ec2->address->associate($associateAddressRequestData);
         }
         $dbFarmRole->SetSetting(self::ROLE_VPC_IP, $publicIp, Entity\FarmRoleSetting::TYPE_LCL);
         $dbFarmRole->SetSetting(self::ROLE_VPC_AID, $address->allocationId, Entity\FarmRoleSetting::TYPE_LCL);
     }
     $dbFarmRole->SetSetting(self::ROLE_VPC_ROUTER_CONFIGURED, 1, Entity\FarmRoleSetting::TYPE_LCL);
 }
开发者ID:mheydt,项目名称:scalr,代码行数:38,代码来源:Router.php

示例6: onFarmSave

 public function onFarmSave(DBFarm $dbFarm, DBFarmRole $dbFarmRole)
 {
     $vpcId = $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_ID);
     if (!$vpcId) {
         //REMOVE VPC RELATED SETTINGS
         return;
     }
     if ($dbFarmRole->GetSetting(self::ROLE_VPC_ROUTER_CONFIGURED) == 1) {
         // ALL OBJECTS ALREADY CONFIGURED
         return true;
     }
     $aws = $dbFarm->GetEnvironmentObject()->aws($dbFarmRole->CloudLocation);
     $filter = array(array('name' => SubnetFilterNameType::vpcId(), 'value' => $vpcId), array('name' => SubnetFilterNameType::tagKey(), 'value' => 'scalr-sn-type'), array('name' => SubnetFilterNameType::tagValue(), 'value' => self::INTERNET_ACCESS_FULL));
     // Try to find scalr FULL subnet
     $subnets = $aws->ec2->subnet->describe(null, $filter);
     if ($subnets->count() > 0) {
         $subnetId = $subnets->get(0)->subnetId;
     }
     if (!$subnetId) {
         $platform = PlatformFactory::NewPlatform(SERVER_PLATFORMS::EC2);
         $subnet = $platform->AllocateNewSubnet($aws->ec2, $vpcId, null);
         $subnetId = $subnet->subnetId;
         //ADD TAGS
         try {
             $subnet->createTags(array(array('key' => "scalr-id", 'value' => SCALR_ID), array('key' => "scalr-sn-type", 'value' => self::INTERNET_ACCESS_FULL), array('key' => "Name", 'value' => 'Scalr System Subnet')));
         } catch (Exception $e) {
         }
         $routingTableId = $platform->getRoutingTable(self::INTERNET_ACCESS_FULL, $aws, null, $vpcId);
         //Associate Routing table with subnet
         $aws->ec2->routeTable->associate($routingTableId, $subnetId);
     }
     $niId = $dbFarmRole->GetSetting(self::ROLE_VPC_NID);
     if (!$niId) {
         //Create Network interface
         $createNetworkInterfaceRequestData = new CreateNetworkInterfaceRequestData($subnetId);
         // Check and create security group
         $filter = array(array('name' => SecurityGroupFilterNameType::groupName(), 'value' => array('SCALR-VPC')), array('name' => SecurityGroupFilterNameType::vpcId(), 'value' => $vpcId));
         try {
             $list = $aws->ec2->securityGroup->describe(null, null, $filter);
             if ($list->count() > 0 && $list->get(0)->groupName == 'SCALR-VPC') {
                 $sgId = $list->get(0)->groupId;
             }
         } catch (Exception $e) {
             throw new Exception("Cannot get list of security groups (1): {$e->getMessage()}");
         }
         if (!$sgId) {
             $sgId = $aws->ec2->securityGroup->create('SCALR-VPC', 'System SG for Scalr VPC integration', $vpcId);
             $ipRangeList = new IpRangeList();
             $ipRangeList->append(new IpRangeData('0.0.0.0/0'));
             $ipRangeListLocal = new IpRangeList();
             $ipRangeListLocal->append(new IpRangeData('10.0.0.0/8'));
             $aws->ec2->securityGroup->authorizeIngress(array(new IpPermissionData('tcp', 8008, 8013, $ipRangeList), new IpPermissionData('tcp', 80, 80, $ipRangeList), new IpPermissionData('tcp', 443, 443, $ipRangeList), new IpPermissionData('tcp', 0, 65535, $ipRangeListLocal), new IpPermissionData('udp', 0, 65535, $ipRangeListLocal)), $sgId);
         }
         $createNetworkInterfaceRequestData->setSecurityGroupId(array('groupId' => $sgId));
         $networkInterface = $aws->ec2->networkInterface->create($createNetworkInterfaceRequestData);
         // Disable sourceDeskCheck
         $networkInterface->modifyAttribute(NetworkInterfaceAttributeType::sourceDestCheck(), 0);
         $niId = $networkInterface->networkInterfaceId;
         $dbFarmRole->SetSetting(self::ROLE_VPC_NID, $niId, DBFarmRole::TYPE_LCL);
         try {
             $networkInterface->createTags(array(array('key' => "scalr-id", 'value' => SCALR_ID), array('key' => "Name", 'value' => 'Scalr System ENI')));
         } catch (Exception $e) {
         }
     }
     // If there is no public IP allocate it and associate with NI
     $publicIp = $dbFarmRole->GetSetting(self::ROLE_VPC_IP);
     if ($niId && !$publicIp) {
         $address = $aws->ec2->address->allocate('vpc');
         $publicIp = $address->publicIp;
         $dbFarmRole->SetSetting(self::ROLE_VPC_IP, $publicIp, DBFarmRole::TYPE_LCL);
         $dbFarmRole->SetSetting(self::ROLE_VPC_AID, $address->allocationId, DBFarmRole::TYPE_LCL);
         $associateAddressRequestData = new AssociateAddressRequestData();
         $associateAddressRequestData->networkInterfaceId = $niId;
         $associateAddressRequestData->allocationId = $address->allocationId;
         //Associate PublicIP with NetworkInterface
         $aws->ec2->address->associate($associateAddressRequestData);
     }
     $dbFarmRole->SetSetting(self::ROLE_VPC_ROUTER_CONFIGURED, 1, DBFarmRole::TYPE_LCL);
 }
开发者ID:recipe,项目名称:scalr,代码行数:79,代码来源:Router.php

示例7: farmSave

 public static function farmSave(DBFarm $DBFarm, array $roles)
 {
     $buckets = array();
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET)) {
             $buckets[$DBFarmRole->CloudLocation] = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET);
         }
     }
     foreach ($roles as $DBFarmRole) {
         if ($DBFarmRole->Platform != SERVER_PLATFORMS::EC2) {
             continue;
         }
         $location = $DBFarmRole->CloudLocation;
         $sshKey = Scalr_Model::init(Scalr_Model::SSH_KEY);
         if (!$sshKey->loadGlobalByFarmId($DBFarm->ID, $location)) {
             $key_name = "FARM-{$DBFarm->ID}";
             $AmazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($location, $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
             $result = $AmazonEC2Client->CreateKeyPair($key_name);
             if ($result->keyMaterial) {
                 $sshKey->farmId = $DBFarm->ID;
                 $sshKey->clientId = $DBFarm->ClientID;
                 $sshKey->envId = $DBFarm->EnvID;
                 $sshKey->type = Scalr_SshKey::TYPE_GLOBAL;
                 $sshKey->cloudLocation = $location;
                 $sshKey->cloudKeyName = $key_name;
                 $sshKey->platform = SERVER_PLATFORMS::EC2;
                 $sshKey->setPrivate($result->keyMaterial);
                 $sshKey->save();
             }
         }
         try {
             if (!$DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET)) {
                 if (!$buckets[$location]) {
                     $aws_account_id = $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCOUNT_ID);
                     $bucket_name = "farm-{$DBFarm->Hash}-{$aws_account_id}-{$location}";
                     //
                     // Create S3 Bucket (For MySQL, BackUs, etc.)
                     //
                     $AmazonS3 = new AmazonS3($DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
                     $buckets = $AmazonS3->ListBuckets();
                     $create_bucket = true;
                     foreach ($buckets as $bucket) {
                         if ($bucket->Name == $bucket_name) {
                             $create_bucket = false;
                             $buckets[$location] = $bucket_name;
                             break;
                         }
                     }
                     if ($create_bucket) {
                         if ($AmazonS3->CreateBucket($bucket_name, $location)) {
                             $buckets[$location] = $bucket_name;
                         }
                     }
                 }
                 $DBFarmRole->SetSetting(DBFarmRole::SETTING_AWS_S3_BUCKET, $buckets[$location]);
             }
         } catch (Exception $e) {
             throw new Exception("Amazon S3: {$e->getMessage()}");
         }
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:61,代码来源:Ec2.php


注:本文中的DBFarm::GetEnvironmentObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。