Inheritance: extends Scalr_UI_Controller
Ejemplo n.º 1
0
 function Run()
 {
     global $db;
     $time = microtime(true);
     //TODO:
     /*
     $db->Execute("CREATE TABLE `sys_dns_zones` (
       `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
       `farm_id` int(11) DEFAULT NULL,
       `account_id` int(11) DEFAULT NULL,
       `env_id` int(11) DEFAULT NULL,
       `zone_name` varchar(255) DEFAULT NULL,
       `status` varchar(255) DEFAULT NULL,
       `isonnsserver` tinyint(1) DEFAULT '0',
       `iszoneconfigmodified` tinyint(1) DEFAULT '0',
       PRIMARY KEY (`id`),
       UNIQUE KEY `zones_index3945` (`zone_name`),
       KEY `env_id` (`env_id`)
     ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
     ");
     */
     $db->Execute("ALTER TABLE  `services_chef_runlists` ADD  `chef_environment` VARCHAR( 255 ) NULL");
     $db->Execute("ALTER TABLE  `services_chef_servers` ADD  `v_username` VARCHAR( 255 ) NULL , ADD  `v_auth_key` TEXT NULL");
     $db->Execute("CREATE TABLE `servers_stats` (\r\n\t\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t  `usage` int(11) DEFAULT NULL,\r\n\t\t\t\t  `instance_type` varchar(15) DEFAULT NULL,\r\n\t\t\t\t  `env_id` int(11) DEFAULT NULL,\r\n\t\t\t\t  `month` int(2) DEFAULT NULL,\r\n\t\t\t\t  `year` int(4) DEFAULT NULL,\r\n\t\t\t\t  `farm_id` int(11) DEFAULT NULL,\r\n\t\t\t\t  `cloud_location` varchar(25) DEFAULT NULL,\r\n\t\t\t\t  PRIMARY KEY (`id`),\r\n\t\t\t\t  UNIQUE KEY `main` (`instance_type`,`cloud_location`,`farm_id`,`env_id`,`month`,`year`),\r\n\t\t\t\t  KEY `envid` (`env_id`),\r\n\t\t\t\t  KEY `farm_id` (`farm_id`)\r\n\t\t\t\t) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\r\n\t\t\t");
     $db->Execute("ALTER TABLE  `script_revisions` ADD  `variables` TEXT NULL");
     $dbVersions = $db->Execute("SELECT * FROM script_revisions WHERE `variables` IS NULL");
     while ($version = $dbVersions->FetchRow()) {
         $data = array();
         foreach ((array) Scalr_UI_Controller_Scripts::getCustomVariables($version["script"]) as $var) {
             if (!in_array($var, array_keys(CONFIG::getScriptingBuiltinVariables()))) {
                 $data[$var] = ucwords(str_replace("_", " ", $var));
             }
         }
         $db->Execute("UPDATE script_revisions SET `variables` = ? WHERE id = ?", array(serialize($data), $version['id']));
     }
     $db->Execute("ALTER TABLE  `scalr`.`servers_stats` ADD INDEX  `year` (  `year` )");
     print "Done.\n";
     $t = round(microtime(true) - $time, 2);
     print "Upgrade process took {$t} seconds\n\n\n";
 }
Ejemplo n.º 2
0
 public function xGetScriptsAction()
 {
     $filterSql = " AND (";
     // Show shared roles
     $filterSql .= " origin='" . SCRIPT_ORIGIN_TYPE::SHARED . "'";
     // Show custom roles
     $filterSql .= " OR (origin='" . SCRIPT_ORIGIN_TYPE::CUSTOM . "' AND clientid='" . $this->user->getAccountId() . "')";
     //Show approved contributed roles
     $filterSql .= " OR (origin='" . SCRIPT_ORIGIN_TYPE::USER_CONTRIBUTED . "' AND (approval_state='" . APPROVAL_STATE::APPROVED . "' OR clientid='" . $this->user->getAccountId() . "'))";
     $filterSql .= ")";
     $scripts = $this->db->Execute("SELECT * FROM scripts WHERE 1=1 {$filterSql}");
     $scriptsList = array();
     $builtInVariables = array_keys(CONFIG::getScriptingBuiltinVariables());
     while ($script = $scripts->FetchRow()) {
         $dbversions = $this->db->Execute("SELECT * FROM script_revisions WHERE scriptid=? AND (approval_state=? OR (SELECT clientid FROM scripts WHERE scripts.id=script_revisions.scriptid) = '" . $this->user->getAccountId() . "')", array($script['id'], APPROVAL_STATE::APPROVED));
         $versions = array();
         while ($version = $dbversions->FetchRow()) {
             $vars = Scalr_UI_Controller_Scripts::GetCustomVariables($version["script"]);
             $data = array();
             foreach ($vars as $var) {
                 if (!in_array($var, $builtInVariables)) {
                     $data[$var] = ucwords(str_replace("_", " ", $var));
                 }
             }
             $versions[] = array("revision" => $version['revision'], "fields" => $data);
         }
         $scr = array('id' => $script['id'], 'name' => $script['name'], 'description' => $script['description'], 'issync' => $script['issync'], 'timeout' => $script['issync'] == 1 ? CONFIG::$SYNCHRONOUS_SCRIPT_TIMEOUT : CONFIG::$ASYNCHRONOUS_SCRIPT_TIMEOUT, 'revisions' => $versions);
         $scriptsList[$script['id']] = $scr;
     }
     $dbRole = DBRole::loadById($this->getParam('roleId'));
     if ($dbRole->origin == ROLE_TYPE::CUSTOM) {
         $this->user->getPermissions()->validate($dbRole);
     }
     $this->response->data(array('scripts' => $scriptsList, 'events' => array(EVENT_TYPE::HOST_UP => EVENT_TYPE::GetEventDescription(EVENT_TYPE::HOST_UP), EVENT_TYPE::HOST_INIT => EVENT_TYPE::GetEventDescription(EVENT_TYPE::HOST_INIT), EVENT_TYPE::HOST_DOWN => EVENT_TYPE::GetEventDescription(EVENT_TYPE::HOST_DOWN), EVENT_TYPE::REBOOT_COMPLETE => EVENT_TYPE::GetEventDescription(EVENT_TYPE::REBOOT_COMPLETE), EVENT_TYPE::INSTANCE_IP_ADDRESS_CHANGED => EVENT_TYPE::GetEventDescription(EVENT_TYPE::INSTANCE_IP_ADDRESS_CHANGED), EVENT_TYPE::NEW_MYSQL_MASTER => EVENT_TYPE::GetEventDescription(EVENT_TYPE::NEW_MYSQL_MASTER), EVENT_TYPE::EBS_VOLUME_MOUNTED => EVENT_TYPE::GetEventDescription(EVENT_TYPE::EBS_VOLUME_MOUNTED), EVENT_TYPE::BEFORE_INSTANCE_LAUNCH => EVENT_TYPE::GetEventDescription(EVENT_TYPE::BEFORE_INSTANCE_LAUNCH), EVENT_TYPE::BEFORE_HOST_TERMINATE => EVENT_TYPE::GetEventDescription(EVENT_TYPE::BEFORE_HOST_TERMINATE), EVENT_TYPE::DNS_ZONE_UPDATED => EVENT_TYPE::GetEventDescription(EVENT_TYPE::DNS_ZONE_UPDATED), EVENT_TYPE::EBS_VOLUME_ATTACHED => EVENT_TYPE::GetEventDescription(EVENT_TYPE::EBS_VOLUME_ATTACHED), EVENT_TYPE::BEFORE_HOST_UP => EVENT_TYPE::GetEventDescription(EVENT_TYPE::BEFORE_HOST_UP)), 'roleScripts' => $dbRole->getScripts()));
 }