Class: BuildCloud
- Inherits:
-
Object
- Object
- BuildCloud
- Defined in:
- lib/build-cloud.rb
Defined Under Namespace
Modules: Component Classes: ASGroup, CacheCluster, CacheParameterGroup, CacheSubnetGroup, DHCPOptionsSet, DbParameterGroup, DbSubnetGroup, EBSVolume, IAMGroup, IAMManagedPolicy, IAMRole, IAMUser, Instance, InternetGateway, LaunchConfiguration, LoadBalancer, NetworkInterface, R53RecordSet, RDSServer, Route, RouteTable, S3Bucket, SQSQueue, SecurityGroup, Subnet, VPC, Zone
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #find(component, options) ⇒ Object
-
#initialize(options) ⇒ BuildCloud
constructor
A new instance of BuildCloud.
- #pry ⇒ Object
Constructor Details
#initialize(options) ⇒ BuildCloud
Returns a new instance of BuildCloud.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/build-cloud.rb', line 14 def initialize( ) @log = [:logger] or Logger.new( STDERR ) @mock = [:mock] or false # Parse the first config file. We'll merge the remainder (if any) into # this one, regardless of whether they're passed on the command line # or in the YAML for this file itself. first_config_file = [:config].shift @config = YAML::load( File.open( first_config_file ) ) # include_files is going to be a list of files that we're going to # merge in to the first file. include_files = [] # Work out the full, standardised pathnames for any further files # specified on the command line. note that options[:config] only # contains the extra files at this point, as we shifted the first # one off the array earlier. # # IMPORTANT: relative paths given on the command line are considered # to be relative to $CWD. This decision is based on the principle of # least surprise, as that is how everything else works. cli_include_files = [:config] cli_include_files.each do |inc| include_files << File.absolute_path( inc ) end # Now look in the :include key in the YAML of the first file for # either a single, or an array of files to include. Work out the # standardised paths for each of these files, and push them onto # the include_files array. # # IMPORTANT: relative paths given in the :include key in the YAML # are considered to be relative to the config file specified, not # $CWD. This is to ensure consistency of application and backwards # compatibility. If this were relative to $CWD, a relative path # specified in the file could have different meanings, and would end # up being unpredictable. if include_yaml = @config.delete(:include) if include_yaml.is_a?(Array) # the :include key is an array, we need to iterate over it include_yaml.each do |yml| include_files << File.( yml, File.dirname( File.absolute_path(first_config_file) ) ) end else # the :include key is a scalar, so just standardise that path include_files.push( File.( include_yaml, File.dirname( File.absolute_path(first_config_file) ) ) ) end end include_files.each do |include_path| if File.exists?( include_path ) @log.info( "Including YAML file #{include_path}" ) included_conf = YAML::load( File.open( include_path ) ) @config = @config.merge(included_conf) do |keys, oldval, newval| # we're iterating over elements that are in both the # config we've parsed so far, and the new file. (newval.is_a?(Array) ? (oldval + newval).uniq : newval) # oldval is from the existing config, newval is the incoming # value from this file. if newval is an array, merge it in with # what we already have, and make it unique. if newval is a # string, the new value takes precedence over what we have # already. # # edge cases: # 1. if we have a key :foo which is a scalar, and then a # :foo in a subsequent file which is an array (or v.v.) # then this will blow up. I think this is acceptable. # 2. if we have, eg. an instance, defined twice in # separate files, then the behaviour of uniq is to use # the entire hash as a test for uniqueness. Therefore # if the definition of those instances varies slightly, # the attempt to create those instances will likely fail. end end end @log.debug( @config.inspect ) new_config = recursive_interpolate_config(@config) @config = new_config @log.debug( @config.inspect ) connect_fog BuildCloud::dispatch.each_pair do |component, klass| if @config.has_key?(component) klass.load( @config[component], @fog_interfaces, @log ) end end end |
Class Method Details
.create_order ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/build-cloud.rb', line 177 def self.create_order [ :dhcp_options_sets, :vpcs, :internet_gateways, :iam_managed_policies, :iam_roles, :iam_users, :iam_groups, :subnets, :db_subnet_groups, :cache_subnet_groups, :route_tables, :zones, :security_groups, :network_interfaces, :routes, :db_parameter_groups, :rds_servers, :cache_parameter_groups, :cache_clusters, :launch_configurations, :load_balancers, :as_groups, :r53_record_sets, :s3_buckets, :sqs_queues, :ebs_volumes, :instances, ] end |
.dispatch ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/build-cloud.rb', line 143 def self.dispatch { :vpcs => BuildCloud::VPC, :internet_gateways => BuildCloud::InternetGateway, :subnets => BuildCloud::Subnet, :route_tables => BuildCloud::RouteTable, :zones => BuildCloud::Zone, :security_groups => BuildCloud::SecurityGroup, :network_interfaces => BuildCloud::NetworkInterface, :routes => BuildCloud::Route, :launch_configurations => BuildCloud::LaunchConfiguration, :load_balancers => BuildCloud::LoadBalancer, :as_groups => BuildCloud::ASGroup, :r53_record_sets => BuildCloud::R53RecordSet, :rds_servers => BuildCloud::RDSServer, :db_subnet_groups => BuildCloud::DbSubnetGroup, :db_parameter_groups => BuildCloud::DbParameterGroup, :cache_subnet_groups => BuildCloud::CacheSubnetGroup, :cache_clusters => BuildCloud::CacheCluster, :cache_parameter_groups => BuildCloud::CacheParameterGroup, :iam_roles => BuildCloud::IAMRole, :iam_managed_policies => BuildCloud::IAMManagedPolicy, :iam_groups => BuildCloud::IAMGroup, :iam_users => BuildCloud::IAMUser, :s3_buckets => BuildCloud::S3Bucket, :instances => BuildCloud::Instance, :ebs_volumes => BuildCloud::EBSVolume, :dhcp_options_sets => BuildCloud::DHCPOptionsSet, :sqs_queues => BuildCloud::SQSQueue, } end |
.search(type, options) ⇒ Object
209 210 211 |
# File 'lib/build-cloud.rb', line 209 def self.search( type, ) BuildCloud::dispatch[type].search() end |
Instance Method Details
#all ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/build-cloud.rb', line 128 def all objects = [] BuildCloud::create_order.each do |component| next unless BuildCloud::dispatch.has_key?( component ) objects.concat BuildCloud::dispatch[component].objects() end objects end |
#find(component, options) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/build-cloud.rb', line 118 def find( component, ) if BuildCloud::dispatch.has_key?( component ) BuildCloud::dispatch[component].search() else [] end end |
#pry ⇒ Object
114 115 116 |
# File 'lib/build-cloud.rb', line 114 def pry binding.pry end |