Beispiel #1
0
 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);
     $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, DBFarmRole::TYPE_LCL);
         $dbFarmRole->SetSetting(self::ROLE_VPC_AID, $address->allocationId, DBFarmRole::TYPE_LCL);
     }
     $dbFarmRole->SetSetting(self::ROLE_VPC_ROUTER_CONFIGURED, 1, DBFarmRole::TYPE_LCL);
 }
Beispiel #2
0
 public static function setupBehavior(Entity\FarmRole $farmRole)
 {
     $farm = $farmRole->farm;
     $vpcId = $farm->settings[Entity\FarmSetting::EC2_VPC_ID];
     if (!$vpcId) {
         //REMOVE VPC RELATED SETTINGS
         return;
     }
     if ($farmRole->settings[self::ROLE_VPC_ROUTER_CONFIGURED] == 1) {
         // ALL OBJECTS ALREADY CONFIGURED
         return;
     }
     $aws = $farm->GetEnvironmentObject()->aws($farmRole->CloudLocation);
     $niId = $farmRole->settings[self::ROLE_VPC_NID];
     // If there is no public IP allocate it and associate with NI
     $publicIp = $farmRole->settings[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);
         }
         $farmRole->settings[static::ROLE_VPC_IP] = (new Entity\FarmRoleSetting())->setValue($publicIp)->setType(Entity\FarmRoleSetting::TYPE_LCL);
         $farmRole->settings[static::ROLE_VPC_AID] = (new Entity\FarmRoleSetting())->setValue($address->allocationId)->setType(Entity\FarmRoleSetting::TYPE_LCL);
     }
     $farmRole->settings[static::ROLE_VPC_ROUTER_CONFIGURED] = (new Entity\FarmRoleSetting())->setValue(1)->setType(Entity\FarmRoleSetting::TYPE_LCL);
 }