Class: UKCloud::Vcloud::Ipsec::Main
- Inherits:
-
Object
- Object
- UKCloud::Vcloud::Ipsec::Main
- Defined in:
- lib/main.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #configure_firewall(firewall) ⇒ Object
- #configure_firewalls(firewalls) ⇒ Object
- #get_current_config(edge_href, connection) ⇒ Object
- #get_edge_href(edge_name, connection) ⇒ Object
-
#initialize(config_file) ⇒ Main
constructor
A new instance of Main.
- #monitor_task(task_id, connection) ⇒ Object
- #vcloud_login(creds) ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/main.rb', line 9 def config @config end |
Instance Method Details
#configure_firewall(firewall) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/main.rb', line 22 def configure_firewall(firewall) creds = firewall[:Creds] connection = vcloud_login(creds) edge_id = get_edge_href(creds[:Edge],connection).split('/').last puts "Configuring VPN Service For Firewall: #{creds[:Edge]}" task = connection.post_configure_edge_gateway_services(edge_id,firewall).body monitor_task(task[:href].split('/').last,connection) puts "Finished Configuring VPN Service For Firewall: #{creds[:Edge]}" #TO DO: SUPPORT MERGING CONFIG WITH EXISTING #current_config = get_current_config(edge_href,connection) #new_config = merge_configs(current_config, new_config) end |
#configure_firewalls(firewalls) ⇒ Object
16 17 18 19 20 |
# File 'lib/main.rb', line 16 def configure_firewalls(firewalls) firewalls.each do |firewall| configure_firewall(firewall) end end |
#get_current_config(edge_href, connection) ⇒ Object
64 65 66 67 68 |
# File 'lib/main.rb', line 64 def get_current_config(edge_href,connection) configuration = connection.get_edge_gateway(edge_href.split('/').last).body vpn_service = configuration[:Configuration][:EdgeGatewayServiceConfiguration][:GatewayIpsecVpnService] end |
#get_edge_href(edge_name, connection) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/main.rb', line 54 def get_edge_href(edge_name, connection) puts "Getting vShield Edge HREF From Query" results = connection.get_execute_query(type="edgeGateway", :filter => "name==#{edge_name}").body raise "Edge #{edge_name} Not Found!" unless results[:total] == "1" raise "Edge Name #{edge_name} Not Unique!" if results[:total].to_i > 1 puts "Finished Getting vShield Edge HREF From Query" result = results[:EdgeGatewayRecord][:href] end |
#monitor_task(task_id, connection) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/main.rb', line 70 def monitor_task(task_id,connection) task = connection.get_task(task_id).body while(task[:status] == "running") do puts " Task: #{task[:operation]} Still Running" task = connection.get_task(task_id).body sleep(3) end puts " Task: #{task[:operation]} Completed With Status: #{task[:status]}" end |
#vcloud_login(creds) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/main.rb', line 38 def vcloud_login(creds) puts "Connecting to vCloud Director API" connection = Fog::Compute::VcloudDirector.new( :vcloud_director_username => "#{creds[:User]}@#{creds[:Org]}", :vcloud_director_password => creds[:Password], :vcloud_director_host => creds[:Url], :vcloud_director_show_progress => true, # task progress bar on/off :connection_options => { :omit_default_port => true } ) puts "Connected to vCloud Director API" connection end |