class RHC::Commands::Domain

Public Instance Methods

create(namespace) click to toggle source
# File lib/rhc/commands/domain.rb, line 13
def create(namespace)
  paragraph { say "Creating domain with namespace '#{namespace}'" }
  rest_client.add_domain(namespace)

  results do
    say "Success!"
    say "You may now create an application using the 'rhc app create' command"
  end

  0
end
delete(namespace) click to toggle source
# File lib/rhc/commands/domain.rb, line 109
def delete(namespace)
  domain = rest_client.find_domain namespace

  say "Deleting domain '#{namespace}'"

  begin
    domain.destroy
  rescue RHC::Rest::ClientErrorException #FIXME: I am insufficiently specific
    raise RHC::Exception.new("Domain contains applications. Delete applications first.", 128)
  end

  results { say "Success!" }
  0
end
show() click to toggle source
# File lib/rhc/commands/domain.rb, line 51
def show
  domain = rest_client.domains.first

  if domain
    paragraph do
      say "Applications in #{domain.id}:"
      apps = domain.applications
      if apps.length == 0
        say "No applications.  You can use 'rhc app create' to create new applications."
      else
        apps.each_with_index do |a,i|
          carts = a.cartridges
          section(:top => (i == 0 ? 1 : 2)) do
            header "%s @ %s" % [a.name, a.app_url]
            say "Created: #{date(a.creation_time)}"
            #say "         UUID: #{a.uuid}"
            say "Git URL: #{a.git_url}" if a.git_url
            say "Aliases: #{a.aliases.join(', ')}" if a.aliases and not a.aliases.empty?
            if carts.present?
              say "\nCartridges:"
              carts.each do |c|
                connection_url = c.property(:cart_data, :connection_url) || c.property(:cart_data, :job_url) || c.property(:cart_data, :monitoring_url)
                value = connection_url ? " - #{connection_url['value']}" : ""
                say "  #{c.name}#{value}"
              end
            else
              say "Cartridges: none"
            end
          end
        end
      end
    end
  else
    say "No domain exists.  You can use 'rhc domain create' to create a namespace for applications." unless domain
  end
  0
end
status() click to toggle source
# File lib/rhc/commands/domain.rb, line 91
def status
  args = []

  options.__hash__.each do |key, value|
    value = value.to_s
    if value.length > 0 && value.to_s.strip.length == 0; value = "'#{value}'" end
    args << "--#{key} #{value}"
  end

  Kernel.system("rhc-chk #{args.join(' ')} 2>&1")
  $?.exitstatus.nil? ? 1 : $?.exitstatus
end
update(namespace) click to toggle source
# File lib/rhc/commands/domain.rb, line 30
def update(namespace)
  # TODO: Support multiple domains.  Right now we assume one domain so
  #       you don't have to send in the name of the domain you want to change
  #       but in the future this will be manditory if you have more than one
  #       domain.  Figure out how to support overloading of commands
  domain = rest_client.domains
  raise RHC::DomainNotFoundException, "No domains are registered to the user #{config.username}. Please use 'rhc domain create' to create one." if domain.empty?

  say "Changing namespace '#{domain[0].id}' to '#{namespace}'..."

  domain[0].update(namespace)

  results do
    say "Success!"
    say "You can use 'rhc domain show' to view any url changes.  Be sure to update any links including the url in your local git config: <local_git_repo>/.git/config"
  end

  0
end