Skip to content

Commit

Permalink
Merge pull request projectatomic#201 from budhrg/fix-200
Browse files Browse the repository at this point in the history
Fix projectatomic#200: Simplify the eval hint for 'vagrant service-manager env command
  • Loading branch information
navidshaikh committed May 4, 2016
2 parents 763de28 + f26909f commit afeaf1c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Adds @budhrg as co-maintainer for the plugin @navidshaikh
- Fix #191: 'vagrant service-manager restart' not handled correctly @budhrg
- Fixes #187, Updated commands in the Available Commands section @preeticp
- Fix #200: Simplify the eval hint for `vagrant service-manager env` command @budhrg

## v1.0.1 Apr 12, 2016
- Updated SPEC (v1.0.0) for url, date and format @budhrg
Expand Down
3 changes: 3 additions & 0 deletions lib/vagrant-service-manager/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def execute_status_display(service = nil)

def print_all_provider_info(options = {})
with_target_vms(nil, single_target: true) do |machine|
options[:all] = true # flag to mark all providers
running_service_classes = PluginUtil.running_services(machine, class: true)

running_service_classes.each do |service_class|
Expand All @@ -158,6 +159,8 @@ def print_all_provider_info(options = {})
service_class.info(machine, @env.ui, options)
end
end

PluginUtil.print_shell_configure_info(@env.ui) unless options[:script_readable]
end
end

Expand Down
12 changes: 12 additions & 0 deletions lib/vagrant-service-manager/plugin_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def self.execute_and_exit_on_fail(machine, ui, command)
end
exit_code
end

def self.print_shell_configure_info(ui, command = '')
label = if OS.unix?
'unix_configure_info'
elsif OS.windows_cygwin?
'windows_cygwin_configure_info'
end

unless label.nil?
ui.info "\n" + I18n.t("servicemanager.commands.env.#{label}", command: command)
end
end
end
end
end
34 changes: 18 additions & 16 deletions lib/vagrant-service-manager/services/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,36 @@ def self.status(machine, ui, service)

def self.info(machine, ui, options = {})
if PluginUtil.service_running?(machine, 'docker')
secrets_path = PluginUtil.host_docker_path(machine)
options[:secrets_path] = PluginUtil.host_docker_path(machine)
options[:guest_ip] = PluginUtil.machine_ip(machine)

# Verify valid certs and copy if invalid
unless PluginUtil.certs_present_and_valid?(secrets_path, machine)
unless PluginUtil.certs_present_and_valid?(options[:secrets_path], machine)
# Log the message prefixed by #
PluginUtil.copy_certs_to_host(machine, secrets_path, ui, true)
PluginUtil.copy_certs_to_host(machine, options[:secrets_path], ui, true)
end

api_version = ''
docker_api_version = "docker version --format '{{.Server.APIVersion}}'"
unless machine.communicate.test(docker_api_version)
docker_api_version_cmd = "docker version --format '{{.Server.APIVersion}}'"
unless machine.communicate.test(docker_api_version_cmd)
# fix for issue #152: Fallback to older Docker version (< 1.9.1)
docker_api_version.gsub!(/APIVersion/, 'ApiVersion')
docker_api_version_cmd.gsub!(/APIVersion/, 'ApiVersion')
end

machine.communicate.execute(docker_api_version) do |type, data|
api_version << data.chomp if type == :stdout
machine.communicate.execute(docker_api_version_cmd) do |type, data|
options[:api_version] = data.chomp if type == :stdout
end

# Display the information, irrespective of the copy operation
print_env_info(ui, PluginUtil.machine_ip(machine), secrets_path,
api_version, options[:script_readable])
print_env_info(ui, options)
else
ui.error I18n.t('servicemanager.commands.env.service_not_running',
name: 'Docker')
exit 126
end
end

def self.print_env_info(ui, guest_ip, secrets_path, api_version, script_readable)
label = if script_readable
def self.print_env_info(ui, options)
label = if options[:script_readable]
'script_readable'
elsif OS.unix?
'non_windows'
Expand All @@ -67,13 +66,16 @@ def self.print_env_info(ui, guest_ip, secrets_path, api_version, script_readable
'windows'
end

secrets_path = PluginUtil.windows_path(secrets_path) unless OS.unix?
options[:secrets_path] = PluginUtil.windows_path(options[:secrets_path]) unless OS.unix?
message = I18n.t("servicemanager.commands.env.docker.#{label}",
ip: guest_ip, port: PORT, path: secrets_path,
api_version: api_version)
ip: options[:guest_ip], port: PORT, path: options[:secrets_path],
api_version: options[:api_version])
# Puts is used to escape and render the back slashes in Windows path
message = puts(message) if OS.windows?
ui.info(message)
unless options[:script_readable] || options[:all]
PluginUtil.print_shell_configure_info(ui, ' docker')
end
end
end
end
Expand Down
23 changes: 12 additions & 11 deletions lib/vagrant-service-manager/services/open_shift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ def self.info(machine, ui, options = {})
options[:script_readable] ||= false

if PluginUtil.service_running?(machine, 'openshift')
url = "https://#{PluginUtil.machine_ip(machine)}:#{OPENSHIFT_PORT}"
print_info(ui, url, "#{url}/console", options[:script_readable])
options[:url] = "https://#{PluginUtil.machine_ip(machine)}:#{OPENSHIFT_PORT}"
options[:console_url] = "#{options[:url]}/console"
print_info(ui, options)
else
ui.error I18n.t('servicemanager.commands.env.service_not_running',
name: 'OpenShift')
exit 126
end
end

def self.print_info(ui, url, console_url, script_readable)
message = if script_readable
I18n.t('servicemanager.commands.env.openshift.script_readable',
openshift_url: url, openshift_console_url: console_url)
else
I18n.t('servicemanager.commands.env.openshift.default',
openshift_url: url, openshift_console_url: console_url)
end

def self.print_info(ui, options)
label = 'default'
label = 'script_readable' if options[:script_readable]
message = I18n.t("servicemanager.commands.env.openshift.#{label}",
openshift_url: options[:url],
openshift_console_url: options[:console_url])
ui.info(message)
unless options[:script_readable] || options[:all]
PluginUtil.print_shell_configure_info(ui, ' openshift')
end
end

private
Expand Down
10 changes: 6 additions & 4 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,13 @@ en:
export DOCKER_CERT_PATH=%{path}
export DOCKER_TLS_VERIFY=1
export DOCKER_API_VERSION=%{api_version}
# run following command to configure your shell:
# eval "$(vagrant service-manager env docker)"
windows_cygwin: |-
# Set the following environment variables to enable access to the
# docker daemon running inside of the vagrant virtual machine:
export DOCKER_HOST=tcp://%{ip}:%{port}
export DOCKER_CERT_PATH='%{path}'
export DOCKER_TLS_VERIFY=1
export DOCKER_API_VERSION=%{api_version}
# run following command to configure your shell:
# eval "$(VAGRANT_NO_COLOR=1 vagrant service-manager env docker | tr -d '\r')"
script_readable: |-
DOCKER_HOST=tcp://%{ip}:%{port}
DOCKER_CERT_PATH='%{path}'
Expand All @@ -122,6 +118,12 @@ en:
script_readable: |-
OPENSHIFT_URL=%{openshift_url}
OPENSHIFT_WEB_CONSOLE=%{openshift_console_url}
windows_cygwin_configure_info: |-
# run following command to configure your shell:
# eval "$(VAGRANT_NO_COLOR=1 vagrant service-manager env%{command} | tr -d '\r')"
unix_configure_info: |-
# run following command to configure your shell:
# eval "$(vagrant service-manager env%{command})"
service_not_running: |-
# %{name} service is not running in the vagrant box.
restart:
Expand Down

0 comments on commit afeaf1c

Please sign in to comment.