Class: OVH::Provisioner::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/ovh/provisioner/cli.rb,
lib/ovh/provisioner/self_cli.rb

Overview

The command line runner

Constant Summary collapse

NAME_SCHEME =
[
  :name_scheme,
  desc: 'Name scheme to use for the servers, ex: %<flavor_tag>s-%<id>s',
  aliases: ['-n']
].freeze
NAME_DOMAIN =
[
  :name_domain,
  desc: 'Domain of the servers, ex: test.com',
  aliases: ['-d']
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ThorPatching

#banner

Class Method Details

.all(targets) ⇒ Object



49
50
51
# File 'lib/ovh/provisioner/self_cli.rb', line 49

def self.all(targets)
  targets.empty? ? [''] : targets
end

.ask_validation(question, what = nil) ⇒ Object



30
31
32
33
34
# File 'lib/ovh/provisioner/self_cli.rb', line 30

def self.ask_validation(question, what = nil)
  say question
  say what unless what.nil?
  exit unless HighLine.agree('Do you want to proceed?')
end

.check_service_input(search, services, allow_many = true) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ovh/provisioner/self_cli.rb', line 36

def self.check_service_input(search, services, allow_many = true)
  ok = true
  if services.empty?
    puts "No registered services of your account match #{search}"
    ok = false
  end
  if !allow_many && services.size > 1
    puts "Need one service, got many: #{services.map(&:id)}"
    ok = false
  end
  ok
end

.exit_on_failure?Boolean

Exit 1 on failure

Returns:

  • (Boolean)


26
27
28
# File 'lib/ovh/provisioner/self_cli.rb', line 26

def self.exit_on_failure?
  true
end

Instance Method Details

#get(url) ⇒ Object



148
149
150
151
# File 'lib/ovh/provisioner/cli.rb', line 148

def get(url)
  Provisioner.init(options)
  puts Provisioner.client.get url
end

#install(*targets) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/ovh/provisioner/cli.rb', line 88

def install(*targets)
  spawner = Provisioner.init(options)
  servers = spawner.get('DedicatedServer', *self.class.all(targets))
  self.class.ask_validation(
    'You are going to (re)install those servers:',
    servers.format('install_status', 'flavor')
  )
  servers.puts_each(:install)
end

#ipmi(*targets) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ovh/provisioner/cli.rb', line 135

def ipmi(*targets)
  spawner = Provisioner.init(options)
  servers = spawner.get('DedicatedServer', *self.class.all(targets))
  list = servers.list
  unless list.size == 1
    puts 'Please select one and only one target! You have targeted:'
    puts servers.format('flavor')
    exit 1
  end
  list.first.ipmi
end

#list(*targets) ⇒ Object



52
53
54
55
56
57
# File 'lib/ovh/provisioner/cli.rb', line 52

def list(*targets)
  spawner = Provisioner.init(options)
  puts spawner
    .get('DedicatedServer', *self.class.all(targets))
    .format('vrack', 'flavor')
end

#rename(*targets) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ovh/provisioner/cli.rb', line 112

def rename(*targets)
  servers, domain = init_rename(targets)
  # Add check on duplication?
  self.class.ask_validation(
    'You are going to rename those servers:',
    servers.list.map do |s|
      "  #{s.reverse} => #{s.newname}.#{domain.id}"
    end.join("\n")
  )
  servers.puts_each(:rename, [domain])
  puts 'To complete renaming, call "set_reverse" in a few minute'
end

#set_reverse(*targets) ⇒ Object

rubocop:disable Style/AccessorMethodName



128
129
130
131
# File 'lib/ovh/provisioner/cli.rb', line 128

def set_reverse(*targets) # rubocop:disable Style/AccessorMethodName
  servers, domain = init_rename(targets)
  servers.puts_each(:define_reverse, [domain])
end

#versionObject



46
47
48
# File 'lib/ovh/provisioner/cli.rb', line 46

def version
  say "OVH Provisioner version #{OVH::Provisioner::VERSION}"
end