Class: VagrantPlugins::Rancher::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-rancher/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant-rancher/config.rb', line 15

def initialize
  @role = UNSET_VALUE
  @version = UNSET_VALUE
  @hostname = UNSET_VALUE
  @port = UNSET_VALUE
  @rancher_server_image = UNSET_VALUE
  @server_args = UNSET_VALUE
  @labels = UNSET_VALUE
  @deactivate = UNSET_VALUE
  @project = UNSET_VALUE
  @project_type = UNSET_VALUE
end

Instance Attribute Details

#deactivateObject

Returns the value of attribute deactivate.



8
9
10
# File 'lib/vagrant-rancher/config.rb', line 8

def deactivate
  @deactivate
end

#hostnameObject

Returns the value of attribute hostname.



6
7
8
# File 'lib/vagrant-rancher/config.rb', line 6

def hostname
  @hostname
end

#labelsObject

Returns the value of attribute labels.



11
12
13
# File 'lib/vagrant-rancher/config.rb', line 11

def labels
  @labels
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/vagrant-rancher/config.rb', line 7

def port
  @port
end

#projectObject

Returns the value of attribute project.



12
13
14
# File 'lib/vagrant-rancher/config.rb', line 12

def project
  @project
end

#project_typeObject

Returns the value of attribute project_type.



13
14
15
# File 'lib/vagrant-rancher/config.rb', line 13

def project_type
  @project_type
end

#rancher_server_imageObject

Returns the value of attribute rancher_server_image.



9
10
11
# File 'lib/vagrant-rancher/config.rb', line 9

def rancher_server_image
  @rancher_server_image
end

#roleObject

Returns the value of attribute role.



4
5
6
# File 'lib/vagrant-rancher/config.rb', line 4

def role
  @role
end

#server_argsObject

Returns the value of attribute server_args.



10
11
12
# File 'lib/vagrant-rancher/config.rb', line 10

def server_args
  @server_args
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/vagrant-rancher/config.rb', line 5

def version
  @version
end

Instance Method Details

#finalize!Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-rancher/config.rb', line 28

def finalize!
  @role = 'server' if @role == UNSET_VALUE
  @version = 'latest' if @version == UNSET_VALUE
  @hostname = nil if @hostname == UNSET_VALUE
  @port = 8080 if @port == UNSET_VALUE
  @rancher_server_image = 'rancher/server' if @rancher_server_image == UNSET_VALUE
  @server_args = nil if @server_args == UNSET_VALUE
  @labels = nil if @labels == UNSET_VALUE
  @deactivate = false if @deactivate == UNSET_VALUE
  @project = 'Default' if @project == UNSET_VALUE
  @project_type = 'cattle' if @project_type == UNSET_VALUE
end

#validate(_machine) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vagrant-rancher/config.rb', line 41

def validate(_machine)
  errors = _detected_errors

  unless role == 'server' || role == 'agent'
    errors << ':rancher provisioner requires role to either be "server" or "agent"'
  end

  unless version.is_a?(String) || version.nil?
    errors << ':rancher provisioner requires version to be a string'
  end

  unless hostname.is_a?(String)
    errors << ':rancher provisioner requires hostname to be set to a string'
  end

  unless port.is_a?(Fixnum) || port.is_a?(Fixnum)
    errors << ':rancher provisioner requires port to be a number'
  end
  
  unless rancher_server_image.is_a?(String) || rancher_server_image.nil?
    errors << ':rancher provisioner requires rancher_server_image to be a string'
  end
  
  unless server_args.is_a?(String) || server_args.nil?
    errors << ':rancher provisioner requires server_args to be a string'
  end

  unless labels.is_a?(Array) || labels.nil?
    errors << ':rancher provisioner requires labels to be an array'
  end

  unless deactivate.is_a?(TrueClass) || deactivate.is_a?(FalseClass)
    errors << ':rancher provisioner requires deactivate to be a bool'
  end

  unless project.is_a?(String) || project.nil?
    errors << ':rancher provisioner requires project to be a string'
  end

  unless ['cattle', 'kubernetes', 'swarm'].include? project_type || project_type.nil?
    errors << ':rancher provisioner requires project_type to be one of cattle, kubernetes or swarm'
  end

  { 'rancher provisioner' => errors }
end