Class: Bosh::Cli::Command::CloudFoundry

Inherits:
Base
  • Object
show all
Includes:
Validation, Bosh::Cloudfoundry, FileUtils
Defined in:
lib/bosh/cli/commands/02_create_cf.rb

Instance Method Summary collapse

Instance Method Details

#change_cf_attributes(*attribute_values) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/bosh/cli/commands/02_create_cf.rb', line 91

def change_cf_attributes(*attribute_values)
  setup_deployment_attributes
  reconstruct_deployment_file

  # TODO fail if setting immutable attributes
  attribute_values.each do |attr_value|
    # FIXME check that correct format of input: xyz=123 and give feedback
    attr_name, value = attr_value.split(/=/)
    previous_value = attrs.validated_color(attr_name)
    step("Checking '#{attr_name}' is a valid mutable attribute",
         "Attribute '#{attr_name}' is not a valid mutable attribute (see 'bosh show cf attributes')", :non_fatal) do
      attrs.mutable_attribute?(attr_name)
    end
    attrs.set_mutable(attr_name, value)
  end

  validate_deployment_attributes
  # TODO show validated attributes like "create cf"

  raise Bosh::Cli::ValidationHalted unless errors.empty?

  perform_deploy(options)

rescue Bosh::Cli::ValidationHalted
  errors.each do |error|
    say error.make_red
  end
  exit 1
end

#create_cfObject



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bosh/cli/commands/02_create_cf.rb', line 20

def create_cf
  auth_required
  bosh_status # preload

  setup_deployment_attributes

  ip_addresses = options[:ip]
  err("USAGE: bosh create cf --ip 1.2.3.4 -- please provide one IP address that will be bound to router.") if ip_addresses.blank?
  err("Only one IP address is supported currently. Please create an issue to mention you need more.") if ip_addresses.size > 1
  attrs.set(:ip_addresses, ip_addresses)

  attrs.set_unless_nil(:name, options[:name])
  attrs.set_unless_nil(:dns, options[:dns])
  attrs.set_unless_nil(:persistent_disk, options[:disk])
  attrs.set_unless_nil(:security_group, options[:security_group])
  attrs.set_unless_nil(:common_password, options[:common_password])
  attrs.set_unless_nil(:deployment_size, options[:deployment_size])
  attrs.set_unless_nil(:skip_dns_validation, options[:skip_dns_validation])

  release_version = ReleaseVersion.latest_version_number
  @release_version_cpi_size = 
    ReleaseVersionCpiSize.new(@release_version_cpi, attrs.deployment_size)

  nl
  say "CPI: #{bosh_cpi.make_green}"
  say "DNS mapping: #{attrs.validated_color(:dns)} --> #{attrs.validated_color(:ip_addresses)}"
  say "Deployment name: #{attrs.validated_color(:name)}"
  say "Deployment size: #{attrs.validated_color(:deployment_size)}"
  say "Persistent disk: #{attrs.validated_color(:persistent_disk)}"
  say "Security group: #{attrs.validated_color(:security_group)}"
  nl

  validate_deployment_attributes

  unless confirmed?("Security group #{attrs.validated_color(:security_group)} exists with ports #{attrs.required_ports.join(", ")}")
    cancel_deployment
  end
  unless confirmed?("Creating Cloud Foundry")
    cancel_deployment
  end

  raise Bosh::Cli::ValidationHalted unless errors.empty?

  @deployment_file = DeploymentFile.new(@release_version_cpi_size, attrs, bosh_status)
  perform_deploy(options)
rescue Bosh::Cli::ValidationHalted
  errors.each do |error|
    say error.make_red
  end
  exit 1
end

#show_cf_attributesObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bosh/cli/commands/02_create_cf.rb', line 74

def show_cf_attributes
  setup_deployment_attributes
  reconstruct_deployment_file
  nl
  say "Immutable attributes:"
  attrs.immutable_attributes.each do |attr_name|
    say "#{attr_name}: #{attrs.validated_color(attr_name.to_sym)}"
  end
  nl
  say "Mutable (changable) attributes:"
  attrs.mutable_attributes.each do |attr_name|
    say "#{attr_name}: #{attrs.validated_color(attr_name.to_sym)}"
  end
end