Exemple #1
0
        /**
         * setDefinition
         *
         * @param string $name
         * @param array $def
         * @return bool
         */
        public function setDefinition($name,$def){
                $this->Out->debug(__METHOD__,func_get_args());

                if(!isset($def['key']) || !is_string($def['key'])) {
                        $this->Out->error("Package definition missing 'key' in: ".$name);
                        return false;
                }

                if(strlen($def['key']) < 16) {
                        $this->Out->error("Package 'key' must be 16 characters or more in: ".$name);
                        return false;
                }

                if(!isset($def['source_path']) || !is_string($def['source_path'])) {
                        $this->Out->error("Package definition missing 'source_path' in: ".$name);
                        return false;
                }

                if(!isset($def['install_path']) || !is_string($def['install_path'])) {
                        $this->Out->error("Package definition missing 'install_path' in: ".$name);
                        return false;
                }

                $this->definition[str_replace('package_','',$name)] = $def;
                return true;
        }
Exemple #2
0
        /**
         * setDefinition
         *
         * @param string $name
         * @param array $def
         * @return bool
         */
        public function setDefinition($name,$def){
                $this->Out->debug(__METHOD__,func_get_args());

                if(!isset($def['volume_id']) || !is_string($def['volume_id'])) {
                        $this->Out->error("Volume definition missing 'volume_id' in: ".$name);
                        return false;
                }

                if(!isset($def['device']) || !is_string($def['device'])) {
                        $this->Out->error("Volume definition missing 'device' in: ".$name);
                        return false;
                }

                if(!isset($def['mount']) || !is_string($def['mount'])) {
                        $this->Out->error("Volume definition missing 'mount' in: ".$name);
                        return false;
                }

                if(!isset($def['availability_zone']) || !is_string($def['availability_zone'])) {
                        $this->Out->error("Volume definition missing 'availability_zone' in: ".$name);
                        return false;
                }

                if(isset($def['command_before_snap'])) {

                        // Convert $def['command_before'] into an array
                        if(is_string($def['command_before_snap'])) {
                                $def['command_before_snap'] = split(',',$def['command_before_snap']);
                        }

                        foreach($def['command_before_snap'] as $command) {
                                if(!empty($command) && !in_array($command,$this->Cloud->Command->getNames())) {
                                        $this->Out->error("Volume definition 'command_before_snap' references command '".$command."' which could not be found in: ".$name);
                                        return false;
                                }
                        }
                }

                if(isset($def['command_after_snap'])) {

                        // Convert $def['command_before'] into an array
                        if(is_string($def['command_after_snap'])) {
                                $def['command_after_snap'] = split(',',$def['command_after_snap']);
                        }

                        foreach($def['command_after_snap'] as $command) {
                                if(!empty($command) && !in_array($command,$this->Cloud->Command->getNames())) {
                                        $this->Out->error("Volume definition 'command_after_snap' references command '".$command."' which could not be found in: ".$name);
                                        return false;
                                }
                        }
                }

                $this->definition[str_replace('volume_','',$name)] = $def;
                return true;
        }
Exemple #3
0
        /**
         * parseConfig
         * @param string $filename
         */
        protected function parseConfig($filename) {
			$this->Out->debug(__METHOD__);

			// Make sure the file is there
			if(!is_file($filename)) {
				$this->Out->error('Unable to locate configuration file: '.$filename);
				exit(1);
			}

			// Parse the config file
			$config = parse_ini_file($filename,true);

			// Check required config sections are present
			$missing = null;

			// credentials
			if(!isset($config['aws']['access_key'])) { $missing = '[aws] access_key'; }
			if(!isset($config['aws']['secret_key'])) { $missing = '[aws] secret_key'; }

			// ec2
			if(!isset($config['ec2']['region'])) { $missing = '[ec2] region'; }
			if(isset($config['ec2']['region']) && isset($config['ec2']['hostname'])) {
				trigger_error('Must only set region -or- hostname in config [ec2]');
				exit(1);
			}

			// s3
			if(!isset($config['s3']['region'])) { $missing = '[s3] region'; }
			if(!isset($config['s3']['bucket_name'])) { $missing = '[s3] bucket_name'; }
			if(isset($config['s3']['region']) && isset($config['s3']['hostname'])) {
				trigger_error('Must only set region -or- hostname in config [s3]');
				exit(1);
			}

			// Check $config['s3']['package_bucket_name'] name is valid
			if(strlen(preg_replace("/[a-zA-Z0-9]|-/",'',$config['s3']['bucket_name']))) {
				trigger_error('Invalid S3 bucket name in [s3] bucket_name');
				exit(1);
			}

			if($missing) {
				trigger_error('Missing required configuration item: '.$missing);
				exit(1);
			}

			// Set debug mode if set in config file
			if(isset($config['core']['debug']) && 1 == $config['core']['debug']) {
				$this->debug = true;
			} else {
				$this->debug = false;
			}

			return $config;
        }
Exemple #4
0
		/**
		 * __mapAwsRegion
		 * 
		 * provided to implement backward compatibility with previous AWSSDK versions
		 * @param string $region_name 
		 */
		private function __mapAwsRegion($region_name) {
			
			switch($region_name) {
				
				case 'ap-northeast-1':
					return AmazonEC2::REGION_APAC_NE1;
				break;
				
				case 'ap-southeast-1':
					return AmazonEC2::REGION_APAC_SE1;
				break;
			
                case 'ap-southeast-2':
                        return AmazonEC2::REGION_APAC_SE2;
                break;

				case 'eu-west-1':
					return AmazonEC2::REGION_EU_W1;
				break;
			
				case 'sa-east-1':
					return AmazonEC2::REGION_SA_E1;
				break;
			
				case 'sa-east-1':
					return AmazonEC2::REGION_SA_E1;
				break;
				
				case 'us-east-1':
					return AmazonEC2::REGION_US_E1;
				break;
			
				case 'us-west-1':
					return AmazonEC2::REGION_US_W1;
				break;
			
				case 'us-west-2':
					return AmazonEC2::REGION_US_W2;
				break;
			
				case 'us-gov-west-1':
					return AmazonEC2::REGION_US_GOV1;
				break;
			}
			
			// catch situations where the full aws hostname was passed through
			if(strstr($region_name,'.amazonaws.com') && strstr($region_name,'ec2.')) {
				return $region_name;
			}

			$this->Out->error('Unknown AWS region "'.$region_name.'"');
			exit(1);
		}
Exemple #5
0
        /**
         * setDefinition
         *
         * @param string $name
         * @param array $def
         * @return bool
         */
        public function setDefinition($name,$def){
                $this->Out->debug(__METHOD__,func_get_args());

                if(!isset($def['address']) || !is_string($def['address'])) {
                        $this->Out->error("Address 'address' definition missing in: ".$name);
                        return false;
                }

                if(!isset($def['region']) || !is_string($def['region'])) {
                        $this->Out->error("Address 'region' definition missing in: ".$name);
                        return false;
                }

                $this->definition[str_replace('address_','',$name)] = $def;
                return true;
        }
Exemple #6
0
        /**
         * setDefinition
         *
         * @param string $name
         * @param array $def
         * @return bool
         */
        public function setDefinition($name,$def){
                $this->Out->debug(__METHOD__,func_get_args());

                if(!isset($def['command']) || !is_string($def['command'])) {
                        $this->Out->error("Command definition missing 'command' in: ".$name);
                        return false;
                }

                if(!isset($def['response']) || !is_string($def['response'])) {
                        $this->Out->error("Command definition missing 'response' in: ".$name);
                        return false;
                }

                $this->definition[str_replace('command_','',$name)] = $def;
                return true;
        }
Exemple #7
0
        /**
         * setDefinition *
         *
         * @param string $name
         * @param array $def
         * @return bool
         */
        public function setDefinition($name,$def){
			$this->Out->debug(__METHOD__,func_get_args());

			if(!isset($def['type']) || !is_string($def['type'])) {
				$this->Out->error("Spot Request definition missing 'type' in: ".$name);
				return false;
			}

			if(!isset($def['instance']) || !is_string($def['instance'])) {
				$this->Out->error("Spot Request definition missing 'instance' in: ".$name);
				return false;
			}
			
			if(!in_array($def['instance'],$this->Cloud->Instance->getNames('config'))) {
					$this->Out->error("Spot Request definition ".$name.":packages references instance '".$def['instance']."' that is not defined");
					return false;
			}

			// All clear to add this host definition
			$this->definition[str_replace('spot_','',$name)] = $def;
			return true;
        }
Exemple #8
0
        /**
         * validateCommandArgs()
         *
         * @param array $args
         * @param array $command_meta
         * @param bool $output_fail_message
         */
        public function validateCommandArgs($args,$command_name,$output_messages=true) {
                $this->Out->debug(__METHOD__,func_get_args());

                // Tweak the $command_name if a __FUNCTION__ name was supplied
                if(preg_match("/^cmd_/",$command_name)) { $command_name = str_replace('cmd_','',$command_name); }

                // Make sure the args array is not empty
                if(empty($args)) {
                        if($output_messages) {
                                $this->Out->error('Missing command argument(s)');
                                $this->Out->msg();
                                $this->outCommandUsage($command_name);
                        }
                        return false;
                }

                // Run through the args to make sure they *seem* valid
                $arg_path = array($command_name);
                foreach($args as $arg_level=>$arg) {

                        // Obtain the list of sub commands at this point
                        $sub_commands = $this->getTabSubs($arg_path);

                        // Try and find this arg using a preg
                        $is_found = false;
                        foreach($sub_commands as $sub_command) {
                                if('[*]'==$sub_command) {
                                        $is_found = true;
                                        break;
                                }
                                elseif(preg_match("/^\[(.*?)\]$/",$sub_command,$matches)) {
                                        if(isset($matches[1]) && in_array($matches[1],$args)) {
                                                $is_found = true;
                                                break;
                                        }
                                }
                                elseif(strstr($sub_command,'*') && !preg_match("/^\[.*?\]$/",$sub_command)) {
                                        if(preg_match("/^".str_replace('*','',$sub_command).".*?/",$arg)) {
                                                $is_found = true;
                                                break;
                                        }
                                } else {
                                        if(preg_match("/^".$sub_command."$/",$arg)) {
                                                $is_found = true;
                                                break;
                                        }
                                }
                        }

                        // Check if we found this arg at this sub level
                        if($is_found) {
                                //$arg_path[] = $arg;
                                $arg_path[] = $sub_command;
                        } else {
                                if($output_messages) {
                                        $this->Out->error('Unexpected input argument: >'.$arg.'<');
                                        $this->Out->msg();
                                }
                                return false;
                        }

                        // Check if this is the last arg and if there are supposed to be more args
                        if($arg_level == (count($args)-1) ) {
                                if(count($this->getTabSubs($arg_path)) > 0) {

                                        // Check these are not intended to be optional args
                                        foreach($this->getTabSubs($arg_path) as $tab_sub) {
                                                if(preg_match("/^\[.*?\]$/",$tab_sub)) {
                                                        return true;
                                                }
                                        }

                                        if($output_messages) {
                                                $this->Out->error('Missing command argument(s)');
                                                $this->Out->msg();
                                                $this->outCommandUsage($command_name);
                                        }
                                        return false;
                                }
                        }
                }

                //print_r($args);
                //print_r($arg_path);
                //print_r($sub_commands);

                return true;
        }
        /**
         * setDefinition
         *
         * @param string $name
         * @param array $def
         * @return bool
         */
        public function setDefinition($name,$def){
                $this->Out->debug(__METHOD__,func_get_args());

                if(!isset($def['type']) || !is_string($def['type'])) {
                        $this->Out->error("Host definition missing 'type' in: ".$name);
                        return false;
                }

                if(!isset($def['ami_id']) || !is_string($def['ami_id'])) {
                        $this->Out->error("Host definition missing 'ami_id' in: ".$name);
                        return false;
                }

                /**
                if(!isset($def['kernel_id']) || !is_string($def['kernel_id'])) {
                        $this->Out->error("Host definition missing 'kernel_id' in: ".$name);
                        return false;
                }
                **/

                if(!isset($def['keypair']) || !is_string($def['keypair'])) {
                        $this->Out->error("Host definition missing 'keypair' in: ".$name);
                        return false;
                }

                if(!isset($def['username']) || !is_string($def['username'])) {
                        $this->Out->error("Host definition missing 'username' in: ".$name);
                        return false;
                }

                // Convert packages to array
                if(isset($def['packages']) && is_string($def['packages'])) {
                        $def['packages'] = split(',',$def['packages']);

                        // Make sure each package exists
                        foreach($def['packages'] as $package_name) {

                                if(!in_array($package_name,$this->Cloud->Package->getNames())) {
                                        $this->Out->error("Host definition ".$name.":packages references package '".$package_name."' that is not defined");
                                        return false;
                                }
                        }
                }

                // Convert volumes to array
                if(isset($def['volumes']) && is_string($def['volumes'])) {
                        $def['volumes'] = split(',',$def['volumes']);

                        // Make sure each volume exists
                        foreach($def['volumes'] as $volume_name) {
                                if(!in_array($volume_name,$this->Cloud->Volume->getNames('config') )) {
                                        $this->Out->error("Host definition ".$name.":volumes references volume '".$volume_name."' that is not defined");
                                        return false;
                                }
                        }
                }

                // Convert $def['groups'] to an array
                if(isset($def['groups']) || is_string($def['groups'])) {
                        $def['groups'] = split(',',$def['groups']);
                }

                // Convert $def['recipes'] to an array
                if(isset($def['recipes']) && is_string($def['recipes'])) {
                        $def['recipes'] = split(',',$def['recipes']);
                }

                // All clear to add this host definition
                $this->definition[str_replace('instance_','',$name)] = $def;
                return true;
        }