コード例 #1
0
ファイル: NdJCloudPackage.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }
コード例 #2
0
ファイル: NdJCloudVolume.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }
コード例 #3
0
ファイル: cloudcli.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }
コード例 #4
0
ファイル: NdJCloud.php プロジェクト: ndejong/cloudcli
        /**
         * refreshCloudData
         *
         * @param bool $update
         * @return array
         */
        public function refreshCloudData($update=true,$class=null) {
			$this->Out->debug(__METHOD__,func_get_args());

			if($class) {
				$this->$class->getData(null,$update);
				return true;
			}
			
			$this->Address->getData(null,$update);
			$this->Instance->getData(null,$update);
			$this->Volume->getData(null,$update);
			$this->Spot->getData(null,$update);
			
			return true;
        }
コード例 #5
0
ファイル: NdJCloudAddress.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }
コード例 #6
0
ファイル: NdJCloudCommand.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }
コード例 #7
0
ファイル: NdJShell.php プロジェクト: ndejong/libs-php-NdJ
        /**
         * outCommandUsage()
         *
         * @param string $command_name
         */
        public function outCommandUsage($command_name) {
                $this->Out->debug(__METHOD__,func_get_args());

                // Display each line item of help
                $is_first_line = true;
                foreach($this->command_metas[$command_name]['sub_commands'] as $sub_command=>$sub_command_data) {

                        if(isset($sub_command_data['__usage'])) {

                                if($is_first_line) {
                                        $this->Out->msg('Usage: ',false);
                                        $is_first_line = false;
                                } else {
                                        $this->Out->msg('       ',false);
                                }

                                $this->Out->msg($command_name.' '.$sub_command.' '.$sub_command_data['__usage']);
                        }
                }

                $this->Out->msg();
        }
コード例 #8
0
ファイル: NdJCloudSpot.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }
コード例 #9
0
ファイル: NdJCloudInstance.php プロジェクト: ndejong/cloudcli
        /**
         * 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;
        }