Module: GClouder::Resources::Compute::BGPVPNs::BGPVPN
- Includes:
- Config::CLIArgs, GCloud, Helpers, Logging, Shell
- Defined in:
- lib/gclouder/resources/compute/bgp-vpns.rb
Class Method Summary collapse
Methods included from Config::CLIArgs
check, #cli_args, cli_args, included, load, valid_resources
Methods included from Helpers
#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?
Methods included from Logging
#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning
Methods included from Shell
Methods included from GCloud
Methods included from Config::Project
Class Method Details
.create(region, vpn) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 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 176 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 208 209 210 211 212 213 214 215 |
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 125 def self.create(region, vpn) network = vpn['network'] info "#{vpn['name']} (bgp-vpn-#{vpn['name']})", indent: 3 # check to see if router exists, if it doesn't then assume we need to create interface and bgp peer configure_router = !Resource.resource?("compute routers", "bgp-vpn-#{vpn['name']}", silent: true) # router Resource.ensure :"compute routers", "bgp-vpn-#{vpn['name']}", "--region #{region} \ --network #{network} \ --asn #{vpn['bgp']['local_asn']}", extra_info: "(router)", indent: 4 # VPN gateway Resource.ensure :"compute target-vpn-gateways", "bgp-vpn-#{vpn["name"]}", "--network #{network} \ --region #{region}", extra_info: "(gateway)", indent: 4 address = cli_args[:dry_run] ? "<automatic>" : vpn_address(region, vpn) # forwarding rules Resource.ensure :"compute forwarding-rules", "bgp-vpn-#{vpn['name']}-esp", "--region #{region} \ --ip-protocol ESP \ --address #{address} \ --target-vpn-gateway bgp-vpn-#{vpn['name']}", extra_info: "(forwarding-rule)", indent: 4 Resource.ensure :"compute forwarding-rules", "bgp-vpn-#{vpn['name']}-udp500", "--region #{region} \ --ip-protocol UDP \ --ports 500 \ --address #{address} \ --target-vpn-gateway bgp-vpn-#{vpn['name']}", extra_info: "(forwarding-rule)", indent: 4 Resource.ensure :"compute forwarding-rules", "bgp-vpn-#{vpn['name']}-udp4500", "--region #{region} --ip-protocol UDP --ports 4500 --address #{address} \ --target-vpn-gateway bgp-vpn-#{vpn['name']}", extra_info: "(forwarding-rule)", indent: 4 # tunnel Resource.ensure :"compute vpn-tunnels", "bgp-vpn-#{vpn['name']}", "--region #{region} \ --peer-address #{vpn['peer_address']} \ --ike-version #{vpn['ike_version']} \ --router bgp-vpn-#{vpn['name']} \ --target-vpn-gateway bgp-vpn-#{vpn['name']} \ --shared-secret #{vpn['shared_secret']}", extra_info: "(tunnel)", indent: 4 if configure_router # router interface gcloud("compute routers add-interface bgp-vpn-#{vpn['name']} \ --region #{region} \ --interface-name bgp-vpn-interface-#{vpn['name']} \ --vpn-tunnel bgp-vpn-#{vpn['name']} \ --mask-length #{vpn['bgp']['mask']} \ --ip-address #{vpn['bgp']['local_address']}", failure: false) add "bgp-vpn-#{vpn['name']} (router interface)", indent: 4 # bgp peer gcloud("compute routers add-bgp-peer bgp-vpn-#{vpn['name']} \ --region #{region} \ --interface bgp-vpn-interface-#{vpn['name']} \ --advertised-route-priority #{vpn['bgp']['priority']} \ --peer-asn #{vpn['bgp']['peer_asn']} \ --peer-ip-address #{vpn['bgp']['peer_address']} \ --peer-name #{vpn['name']}", failure: false) add "bgp-vpn-#{vpn['name']} (bgp peer)", indent: 4 else good "bgp-vpn-#{vpn['name']} (router interface)", indent: 4 good "bgp-vpn-#{vpn['name']} (bgp peer)", indent: 4 end end |
.vpn_address(region, vpn) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/gclouder/resources/compute/bgp-vpns.rb', line 115 def self.vpn_address(region, vpn) response = gcloud("--format json compute addresses describe #{vpn['address']} --region=#{region}", force: true) unless response.key?("address") fatal "could not find address for static ip with key: #{vpn['address']} (is key allocated in project config?)" end response["address"] end |