Class: Knife::Clc::ServerLaunch::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/knife-clc/server_launch/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Validator

Returns a new instance of Validator.



7
8
9
10
# File 'lib/knife-clc/server_launch/validator.rb', line 7

def initialize(params)
  @config = params.fetch(:config)
  @errors = params.fetch(:errors)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/knife-clc/server_launch/validator.rb', line 5

def config
  @config
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/knife-clc/server_launch/validator.rb', line 5

def errors
  @errors
end

Instance Method Details

#validateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/knife-clc/server_launch/validator.rb', line 12

def validate
  unless config[:clc_name]
    errors << 'Name is required'
  end

  unless config[:clc_group]
    errors << 'Group ID is required'
  end

  unless config[:clc_source_server]
    errors << 'Source server ID is required'
  end

  unless config[:clc_cpu]
    errors << 'Number of CPUs is required'
  end

  unless config[:clc_memory]
    errors << 'Number of memory GBs is required'
  end

  unless config[:clc_type]
    errors << 'Type is required'
  end

  custom_fields = config[:clc_custom_fields]
  if custom_fields && custom_fields.any?
    parse_custom_fields(custom_fields)
  end

  disks = config[:clc_disks]
  if disks && disks.any?
    parse_disks(disks)
  end

  packages = config[:clc_packages]
  if packages && packages.any?
    parse_packages(packages)
  end
end