Class: Docker::API::Networks
- Inherits:
-
Collection
- Object
- Collection
- Docker::API::Networks
- Defined in:
- lib/docker/api/collections/networks.rb
Overview
The networks on a daemon.
Instance Attribute Summary
Attributes inherited from Collection
Instance Method Summary collapse
-
#all(filters: nil) ⇒ Array<Docker::API::Network>
Partial resources.
-
#create(name, driver: nil, ipv6: false, internal: false, attachable: false, labels: nil, ipam: nil, options: nil, **attributes) ⇒ Docker::API::Network
Create a network.
-
#ensure(name, **attributes) ⇒ Docker::API::Network
Fetch a network by name, creating it if it does not exist.
- #get(id, verbose: false, scope: nil) ⇒ Docker::API::Network
-
#prune(filters: nil) ⇒ Hash
What was deleted.
Methods inherited from Collection
#exist?, #find, #initialize, #to_s
Constructor Details
This class inherits a constructor from Docker::API::Collection
Instance Method Details
#all(filters: nil) ⇒ Array<Docker::API::Network>
Returns partial resources.
12 13 14 15 |
# File 'lib/docker/api/collections/networks.rb', line 12 def all(filters: nil) operations.network_list(filters: filters) .json!.map { |payload| Network.new(client: client, raw: payload, partial: true) } end |
#create(name, driver: nil, ipv6: false, internal: false, attachable: false, labels: nil, ipam: nil, options: nil, **attributes) ⇒ Docker::API::Network
Create a network.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/docker/api/collections/networks.rb', line 46 def create(name, driver: nil, ipv6: false, internal: false, attachable: false, labels: nil, ipam: nil, options: nil, **attributes) body = Body.build(attributes).merge( "Name" => name, "Driver" => driver, "EnableIPv6" => ipv6, "Internal" => internal, "Attachable" => attachable, "Labels" => labels, "IPAM" => ipam, "Options" => ).compact get(operations.network_create(body: body).json!["Id"]) end |
#ensure(name, **attributes) ⇒ Docker::API::Network
Fetch a network by name, creating it if it does not exist.
Two processes racing to create the same shared network is ordinary rather than exceptional -- parallel test suites do it constantly -- so losing that race is treated as success and the winner's network is returned.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/docker/api/collections/networks.rb', line 67 def ensure(name, **attributes) found = find(name) return found if found begin create(name, **attributes) rescue Conflict get(name) end end |
#get(id, verbose: false, scope: nil) ⇒ Docker::API::Network
22 23 24 25 26 27 28 |
# File 'lib/docker/api/collections/networks.rb', line 22 def get(id, verbose: false, scope: nil) Network.new( client: client, raw: operations.network_inspect(id: id, verbose: verbose, scope: scope).json, partial: false ) end |
#prune(filters: nil) ⇒ Hash
Returns what was deleted.
80 81 82 |
# File 'lib/docker/api/collections/networks.rb', line 80 def prune(filters: nil) operations.network_prune(filters: filters).json end |