Class: Algo::Dsl::Network::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/algo/dsl/network.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cluster) ⇒ Context

Returns a new instance of Context.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/algo/dsl/network.rb', line 29

def initialize name, cluster
  @cluster = cluster
  @context = {
    'Name' => "#{cluster_prefix}#{name}",
    'Driver' => 'overlay',
    'CheckDuplicate' => true,
    'EnableIPv6' => false,
    'IPAM' => {
      'Config' => [],
      'Driver' => 'default',
      'Options' => {}
    },
    'Internal' => false,
    'Labels' => cluster['labels'],
    'Options' => {}
  }
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



27
28
29
# File 'lib/algo/dsl/network.rb', line 27

def context
  @context
end

Instance Method Details

#internalObject



47
48
49
# File 'lib/algo/dsl/network.rb', line 47

def internal
  @context['Internal'] = true
end

#ipam(&block) ⇒ Object



59
60
61
62
63
64
# File 'lib/algo/dsl/network.rb', line 59

def ipam &block
  ctx = Network::IPAMContext.new.tap do |ctx|
    ctx.instance_eval(&block) if block_given?
  end
  @context['IPAM']['Config'] << ctx.context
end

#ipv6Object



55
56
57
# File 'lib/algo/dsl/network.rb', line 55

def ipv6
  @context['EnableIPv6'] = true
end

#label(key, val) ⇒ Object



51
52
53
# File 'lib/algo/dsl/network.rb', line 51

def label key, val
  @context['Labels'][key] = val
end