Class: VMC::Cli::Command::Knife

Inherits:
Base
  • Object
show all
Includes:
KNIFE::Cli
Defined in:
lib/vmc_knife/commands/knife_cmds.rb

Constant Summary

Constants included from KNIFE::Cli

KNIFE::Cli::VERSION

Instance Method Summary collapse

Methods included from KNIFE::Cli

#load_manifest

Instance Method Details

#configure_all(manifest_file_path_or_uri = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/vmc_knife/commands/knife_cmds.rb', line 96

def configure_all(manifest_file_path_or_uri=nil)
  begin
    display "Stop applications ..."
    VMC::Cli::Command::Knifeapps.new(@options).stop_applications(nil,manifest_file_path_or_uri)
  rescue
    #nevermind. sometimes a wrong config we can't login and we can't stop the apps.
  end
  display "Configure_cloud_controller ..."
  change = configure_cloud_controller(nil,manifest_file_path_or_uri)
  display "Configure_etc_hosts ..."
  configure_etc_hosts(nil,manifest_file_path_or_uri)
  display "Login again ..."
  new_knife = VMC::Cli::Command::Knifemisc.new(@options)
  new_knife.(manifest_file_path_or_uri)
  # set the new client object to the old command.
  @client = new_knife.client
  display "Configure_applications ..."
  VMC::Cli::Command::Knifeapps.new(@options).configure_applications(nil,manifest_file_path_or_uri)
  display "Configure_etc_avahi_aliases ..."
  configure_etc_avahi_aliases(nil,manifest_file_path_or_uri)
  display "Start applications ..."
  VMC::Cli::Command::Knifeapps.new(@options).restart_applications(nil,manifest_file_path_or_uri)
end

#configure_cloud_controller(cloud_controller_yml = nil, manifest_file_path_or_uri = nil) ⇒ Object

updates the cloud_controller



58
59
60
# File 'lib/vmc_knife/commands/knife_cmds.rb', line 58

def configure_cloud_controller(cloud_controller_yml=nil,manifest_file_path_or_uri=nil)
  __update(manifest_file_path_or_uri,cloud_controller_yml,VMC::KNIFE::VCAPUpdateCloudControllerConfig,"cloud_controller")
end

#configure_etc_avahi_aliases(etc_avahi_aliases = nil, manifest_file_path = nil) ⇒ Object

updates /etc/avahi/aliases



89
90
91
92
93
94
# File 'lib/vmc_knife/commands/knife_cmds.rb', line 89

def configure_etc_avahi_aliases(etc_avahi_aliases=nil,manifest_file_path=nil)
  man = load_manifest(manifest_file_path)
  update_aliases = VMC::KNIFE::VCAPUpdateAvahiAliases.new(etc_avahi_aliases,man,client)
  update_aliases.do_exec = true
  update_aliases.execute
end

#configure_etc_hosts(etc_hosts = nil, manifest_file_path = nil, client = nil) ⇒ Object

updates /etc/hosts



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vmc_knife/commands/knife_cmds.rb', line 62

def configure_etc_hosts(etc_hosts=nil,manifest_file_path=nil,client=nil)
  #__update(manifest_file_path_or_uri,etc_hosts,VMC::KNIFE::VCAPUpdateEtcHosts,"/etc/hosts")

  # this will configure /etc/hosts with the urls of your applications as well as the cloudcontroller.
  # it is not be necessary if avahi is correctly configured on your VM.
  unless manifest_file_path.nil?
    if File.exists? manifest_file_path
      man = load_manifest(manifest_file_path)
      uri = man['target']
    else
      uri = manifest_file_path
    end
  else
    man = load_manifest(nil)
    uri = man['target']
  end
  # if there is a port remove it.
  uri = uri.split(':')[0] if uri
  update_aliases = VMC::KNIFE::VCAPUpdateAvahiAliases.new(nil,man,client,/.*/)
  update_hosts = VMC::KNIFE::VCAPUpdateEtcHosts.new(uri,manifest_file_path,client)
  update_hosts.set_all_uris(update_aliases.all_uris)
  if update_hosts.update_pending()
    display "Configuring /etc/hosts with uri: #{uri}" if VMC::Cli::Config.trace
    update_hosts.execute()
  end
end

#expand_manifest(manifest_file_path = ENV['VMC_KNIFE_DEFAULT_RECIPE'], destination = nil) ⇒ Object

expands the json manifest. outputs it in the destination path.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vmc_knife/commands/knife_cmds.rb', line 42

def expand_manifest(manifest_file_path=ENV['VMC_KNIFE_DEFAULT_RECIPE'], destination=nil)
  res = VMC::KNIFE::JSON_EXPANDER.expand_json manifest_file_path
  if destination
    display "Expanding the manifest #{manifest_file_path} into #{destination}"
    if VMC::Cli::Config.trace
      display JSON.pretty_generate(res)
    end
    File.open(destination, 'w') {|f| f.write(JSON.pretty_generate(res)) }
  else
    STDERR.puts "Expanding the manifest #{manifest_file_path}"
    STDOUT.puts JSON.pretty_generate(res)
  end

end