Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-13645 - Updating help messaging and adding undefined environment catching in create and delete commands #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions lib/vagrant-skytap/command/publish_url/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant publish-url create [options]"
o.separator ""
o.separator "Share an environment via the Skytap Cloud UI."
o.separator ""
o.separator "Options:"
o.separator ""

Expand All @@ -44,7 +46,7 @@ def execute
options[:password] = p
end

o.on("-np", "--no-password", "Do not set a password") do |np|
o.on("-n", "--no-password", "Do not set a password") do |n|
options[:no_password] = true
end

Expand All @@ -62,20 +64,25 @@ def execute
end
password ||= ""

ps = fetch_environment.create_publish_set(
name: "Vagrant publish set",
publish_set_type: "single_url",
vms: target_skytap_vms.collect do |vm|
{
vm_ref: vm.url,
access: "run_and_use",
}
end,
password: password
)
@logger.debug("New publish set: #{ps.url}")
environment = fetch_environment
if (environment).nil?
@env.ui.info(I18n.t("vagrant_skytap.commands.publish_urls.fetch_environment_is_undefined"))
else
ps = environment.create_publish_set(
name: "Vagrant publish set",
publish_set_type: "single_url",
vms: target_skytap_vms.collect do |vm|
{
vm_ref: vm.url,
access: "run_and_use",
}
end,
password: password
)
@logger.debug("New publish set: #{ps.url}")

@env.ui.info(I18n.t("vagrant_skytap.commands.publish_urls.created", url: ps.desktops_url))
@env.ui.info(I18n.t("vagrant_skytap.commands.publish_urls.created", url: ps.desktops_url))
end

# Success, exit status 0
0
Expand Down
9 changes: 6 additions & 3 deletions lib/vagrant-skytap/command/publish_url/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def execute

opts = OptionParser.new do |o|
o.separator ""
o.separator "Deletes all published URLs for this project, including any"
o.separator "created through the Skytap UI."
o.separator "Delete the sharing portal. Users can no longer access"
o.separator "the environment through the URL."

o.banner = "Usage: vagrant publish-url delete [options]"
o.separator ""
Expand All @@ -50,7 +50,10 @@ def execute

return unless argv = parse_options(opts)

if publish_sets = fetch_environment.publish_sets.presence
environment = fetch_environment
if (environment).nil?
@env.ui.info(I18n.t("vagrant_skytap.commands.publish_urls.fetch_environment_is_undefined"))
elsif publish_sets = environment.publish_sets.presence
unless options[:force]
confirm = @env.ui.ask(I18n.t("vagrant_skytap.commands.publish_urls.confirm_delete"))
return unless confirm.downcase == 'y'
Expand Down
2 changes: 2 additions & 0 deletions lib/vagrant-skytap/command/publish_url/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def help
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant publish-url <subcommand> [<args>]"
opts.separator ""
opts.separator "Manages Skytap sharing portals."
opts.separator ""
opts.separator "Available subcommands:"

# Add the available subcommands as separators in order to print them
Expand Down
18 changes: 17 additions & 1 deletion lib/vagrant-skytap/command/publish_url/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

require 'optparse'
require 'vagrant-skytap/command/helpers'

module VagrantPlugins
Expand All @@ -30,7 +31,22 @@ class Show < Vagrant.plugin("2", :command)
include Command::Helpers

def execute
if publish_sets = fetch_environment.publish_sets.presence
options = {}
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant publish-url show [<args>]"
o.separator ""
o.separator "Show the sharing portal, the VMs included, and whether"
o.separator "the URL is password-protected."
o.separator ""
o.separator "Available subcommands:"
end

return unless argv = parse_options(opts)

environment = fetch_environment
if (environment).nil?
@env.ui.info(I18n.t("vagrant_skytap.commands.publish_urls.fetch_environment_is_undefined"))
elsif publish_sets = environment.publish_sets.presence
results = publish_sets.collect do |ps|
"#{ps.desktops_url || 'n/a'}\n" \
" VMs: #{machine_names(ps.vm_ids).join(', ').presence || '(none)'}" \
Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ en:
created through the Skytap UI) have been deleted. Users cannot
manage these VMs, or access them through SmartClient, unless they
have a Skytap user account with appropriate permissions.
fetch_environment_is_undefined: |-
The command failed because the environment does not exist. Run `vagrant up` to create the environment.
halt:
not_allowed_if_suspended: |-
Suspended machines cannot be halted gracefully. Run `vagrant up`
Expand Down