Class: Hetzner::Network
- Inherits:
-
Object
- Object
- Hetzner::Network
- Defined in:
- lib/hetzner/infra/network.rb
Instance Method Summary collapse
- #create(location:) ⇒ Object
- #delete ⇒ Object
- #find_network ⇒ Object
- #get ⇒ Object
-
#initialize(hetzner_client:, cluster_name:, existing_network:) ⇒ Network
constructor
A new instance of Network.
Constructor Details
#initialize(hetzner_client:, cluster_name:, existing_network:) ⇒ Network
Returns a new instance of Network.
5 6 7 8 9 |
# File 'lib/hetzner/infra/network.rb', line 5 def initialize(hetzner_client:, cluster_name:, existing_network:) @hetzner_client = hetzner_client @cluster_name = cluster_name @existing_network = existing_network end |
Instance Method Details
#create(location:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hetzner/infra/network.rb', line 11 def create(location:) @location = location puts if (network = find_network) puts 'Private network already exists, skipping.' puts return network['id'] end puts 'Creating private network...' response = hetzner_client.post('/networks', network_config).body puts '...private network created.' puts JSON.parse(response)['network']['id'] end |
#delete ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hetzner/infra/network.rb', line 31 def delete if (network = find_network) if network['name'] == existing_network puts 'Network existed before cluster, skipping.' else puts 'Deleting network...' hetzner_client.delete('/networks', network['id']) puts '...network deleted.' end else puts 'Network no longer exists, skipping.' end puts end |
#find_network ⇒ Object
47 48 49 50 |
# File 'lib/hetzner/infra/network.rb', line 47 def find_network network_name = existing_network || cluster_name hetzner_client.get('/networks')['networks'].detect { |network| network['name'] == network_name } end |
#get ⇒ Object
52 53 54 |
# File 'lib/hetzner/infra/network.rb', line 52 def get find_network end |