DBServer::GetCloudUserData PHP Method

GetCloudUserData() public method

public GetCloudUserData ( )
    public function GetCloudUserData()
    {
        $dbFarmRole = $this->GetFarmRoleObject();
        $baseurl = \Scalr::config('scalr.endpoint.scheme') . "://" . \Scalr::config('scalr.endpoint.host');
        if ($this->isOpenstack() && $this->platform != SERVER_PLATFORMS::VERIZON) {
            $platform = SERVER_PLATFORMS::OPENSTACK;
        } else {
            $platform = $this->platform;
        }
        $retval = array("farmid" => $this->farmId, "role" => implode(",", $dbFarmRole->GetRoleObject()->getBehaviors()), "httpproto" => \Scalr::config('scalr.endpoint.scheme'), "region" => $this->GetCloudLocation(), "hash" => $this->GetFarmObject()->Hash, "realrolename" => $dbFarmRole->GetRoleObject()->name, "szr_key" => $this->GetKey(), "serverid" => $this->serverId, 'p2p_producer_endpoint' => $baseurl . "/messaging", 'queryenv_url' => $baseurl . "/query-env", 'behaviors' => implode(",", $dbFarmRole->GetRoleObject()->getBehaviors()), 'farm_roleid' => $dbFarmRole->ID, 'roleid' => $dbFarmRole->RoleID, 'env_id' => $dbFarmRole->GetFarmObject()->EnvID, 'platform' => $platform, 'server_index' => $this->index, 'cloud_server_id' => $this->GetCloudServerID(), 'cloud_location_zone' => $this->cloudLocationZone, "owner_email" => $dbFarmRole->GetFarmObject()->createdByUserEmail);
        $retval['message_format'] = 'json';
        if (PlatformFactory::isOpenstack($this->platform) && $this->platform != SERVER_PLATFORMS::VERIZON) {
            $retval["cloud_storage_path"] = "swift://";
        } else {
            switch ($this->platform) {
                case SERVER_PLATFORMS::EC2:
                    $retval["s3bucket"] = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::AWS_S3_BUCKET);
                    $retval["cloud_storage_path"] = "s3://" . $dbFarmRole->GetSetting(Entity\FarmRoleSetting::AWS_S3_BUCKET);
                    break;
                case SERVER_PLATFORMS::GCE:
                    $retval["cloud_storage_path"] = "gcs://";
                    break;
            }
        }
        // Custom settings
        foreach ($dbFarmRole->GetSettingsByFilter("user-data") as $k => $v) {
            $retval[str_replace("user-data", "custom", $k)] = $v;
        }
        return $retval;
    }

Usage Example

コード例 #1
0
ファイル: Openstack.php プロジェクト: rakesh-mohanta/scalr
 /**
 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));
     }
 }
All Usage Examples Of DBServer::GetCloudUserData