yadecli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +2 -3
- data/Gemfile +5 -0
- data/Gemfile.lock +44 -2
- data/lib/yadecli/cli/application.rb +19 -4
- data/lib/yadecli/cli/composer.rb +70 -14
- data/lib/yadecli/cli/host.rb +19 -5
- data/lib/yadecli/cli/module.rb +14 -3
- data/lib/yadecli/cli/project.rb +30 -8
- data/lib/yadecli/cli/response/project_start_response.rb +21 -0
- data/lib/yadecli/cli/task.rb +9 -5
- data/lib/yadecli/client/gitlab_client.rb +4 -6
- data/lib/yadecli/command/composer/composer_install_command.rb +166 -0
- data/lib/yadecli/command/composer/composer_list_command.rb +63 -0
- data/lib/yadecli/command/composer/composer_log_command.rb +53 -0
- data/lib/yadecli/command/composer/composer_setup_command.rb +28 -0
- data/lib/yadecli/command/composer/composer_start_command.rb +70 -0
- data/lib/yadecli/command/composer/composer_stop_command.rb +60 -0
- data/lib/yadecli/command/composer/composer_switch_command.rb +51 -0
- data/lib/yadecli/command/composer/composer_uninstall_command.rb +44 -0
- data/lib/yadecli/command/connect_command.rb +29 -0
- data/lib/yadecli/command/host/host_bootstrap_command.rb +132 -0
- data/lib/yadecli/command/host/host_list_command.rb +36 -0
- data/lib/yadecli/command/host/host_provision_command.rb +59 -0
- data/lib/yadecli/command/login_command.rb +26 -0
- data/lib/yadecli/command/module/module_install_command.rb +79 -0
- data/lib/yadecli/command/module/module_list_command.rb +47 -0
- data/lib/yadecli/command/project/project_install_command.rb +58 -0
- data/lib/yadecli/command/project/project_list_command.rb +50 -0
- data/lib/yadecli/command/project/project_setup_command.rb +66 -0
- data/lib/yadecli/command/project/project_start_command.rb +110 -0
- data/lib/yadecli/command/project/project_uninstall_command.rb +44 -0
- data/lib/yadecli/command/task/task_list_command.rb +56 -0
- data/lib/yadecli/io/user_input.rb +1 -1
- data/lib/yadecli/util/cli_util.rb +11 -1
- data/lib/yadecli/util/maven_util.rb +35 -0
- data/lib/yadecli/version.rb +1 -1
- data/lib/yadecli.rb +38 -41
- data/scripts/setup-terminal.sh +1 -1
- data/yadecli.gemspec +6 -2
- metadata +81 -46
- data/lib/.DS_Store +0 -0
- data/lib/yadecli/.DS_Store +0 -0
- data/lib/yadecli/client/authentication_client.rb +0 -24
- data/lib/yadecli/client/base_client.rb +0 -78
- data/lib/yadecli/client/composer_container_client.rb +0 -27
- data/lib/yadecli/client/composer_project_client.rb +0 -27
- data/lib/yadecli/client/composer_service_client.rb +0 -27
- data/lib/yadecli/client/domain_client.rb +0 -23
- data/lib/yadecli/client/host_client.rb +0 -45
- data/lib/yadecli/client/maven_build_step_client.rb +0 -23
- data/lib/yadecli/client/maven_build_task_client.rb +0 -23
- data/lib/yadecli/client/nvm_runtime_client.rb +0 -23
- data/lib/yadecli/client/project_client.rb +0 -28
- data/lib/yadecli/client/project_module_client.rb +0 -35
- data/lib/yadecli/client/pyenv_runtime_client.rb +0 -23
- data/lib/yadecli/client/role_client.rb +0 -23
- data/lib/yadecli/client/rvm_runtime_client.rb +0 -23
- data/lib/yadecli/client/sdk_package_client.rb +0 -28
- data/lib/yadecli/client/vcs_client.rb +0 -23
- data/lib/yadecli/config/app_config.rb +0 -70
- data/lib/yadecli/model/composer_container.rb +0 -19
- data/lib/yadecli/model/composer_project.rb +0 -37
- data/lib/yadecli/model/composer_service.rb +0 -19
- data/lib/yadecli/model/domain.rb +0 -24
- data/lib/yadecli/model/host.rb +0 -24
- data/lib/yadecli/model/ide_type.rb +0 -7
- data/lib/yadecli/model/maven_build_step.rb +0 -19
- data/lib/yadecli/model/maven_build_task.rb +0 -19
- data/lib/yadecli/model/nvm_runtime.rb +0 -18
- data/lib/yadecli/model/project.rb +0 -26
- data/lib/yadecli/model/project_module.rb +0 -29
- data/lib/yadecli/model/pyenv_runtime.rb +0 -18
- data/lib/yadecli/model/role.rb +0 -24
- data/lib/yadecli/model/rvm_runtime.rb +0 -18
- data/lib/yadecli/model/sdk_package.rb +0 -18
- data/lib/yadecli/model/vcs.rb +0 -19
- data/lib/yadecli/service/authentication_service.rb +0 -31
- data/lib/yadecli/service/build_step_service.rb +0 -24
- data/lib/yadecli/service/build_task_service.rb +0 -70
- data/lib/yadecli/service/composer_service.rb +0 -416
- data/lib/yadecli/service/connect_service.rb +0 -19
- data/lib/yadecli/service/host_service.rb +0 -191
- data/lib/yadecli/service/module_service.rb +0 -78
- data/lib/yadecli/service/project_service.rb +0 -205
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
require 'tty-table'
|
5
|
+
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
module Composer
|
9
|
+
class ComposerListCommand < Mutations::Command
|
10
|
+
|
11
|
+
#
|
12
|
+
def execute
|
13
|
+
composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
|
14
|
+
composer_service_client = Yade::Composer::Rest::Client::ComposerServiceClient.new
|
15
|
+
|
16
|
+
composer_projects = composer_project_client.list
|
17
|
+
|
18
|
+
# print table
|
19
|
+
table = TTY::Table.new header: ['Id', 'Name', 'Services', 'Installed', 'Branches', 'Git Url']
|
20
|
+
|
21
|
+
# add as rows to table
|
22
|
+
composer_projects.each do |p|
|
23
|
+
project_id = p.id
|
24
|
+
project_name = p.name
|
25
|
+
project_installed = p.installed?
|
26
|
+
|
27
|
+
composer_services = composer_service_client.get_by_composer_project_id(project_id)
|
28
|
+
service_names = composer_services.collect(&:name).join(', ')
|
29
|
+
|
30
|
+
gitlab_client = Yadecli::Client::GitlabClient.new
|
31
|
+
|
32
|
+
branches = gitlab_client.get_branch_names(p.git_repo_name)
|
33
|
+
default_branch = gitlab_client.get_default_branch(p.git_repo_name)
|
34
|
+
|
35
|
+
if project_installed
|
36
|
+
current_branch = FileUtil.git_current_branch(p.install_dir)
|
37
|
+
else
|
38
|
+
current_branch = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
branches = branches.map do |b|
|
42
|
+
if b == default_branch && b == current_branch
|
43
|
+
"#{b} (Default, Current)"
|
44
|
+
elsif b == default_branch && b != current_branch
|
45
|
+
"#{b} (Default)"
|
46
|
+
elsif b == current_branch && b != default_branch
|
47
|
+
"#{b} (Current)"
|
48
|
+
else
|
49
|
+
b
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
table << [project_id, project_name, service_names , project_installed, branches.join(', '), p.gitUrl]
|
54
|
+
end
|
55
|
+
|
56
|
+
renderer = TTY::Table::Renderer::ASCII.new(table, padding: [0, 1])
|
57
|
+
|
58
|
+
renderer.render
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
|
5
|
+
module Yadecli
|
6
|
+
module Command
|
7
|
+
module Composer
|
8
|
+
class ComposerLogCommand < Mutations::Command
|
9
|
+
|
10
|
+
required do
|
11
|
+
string :project_name, empty: false
|
12
|
+
string :service_name, empty: false
|
13
|
+
end
|
14
|
+
|
15
|
+
optional do
|
16
|
+
hash :options do
|
17
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
def execute
|
23
|
+
composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
|
24
|
+
composer_service_client = Yade::Composer::Rest::Client::ComposerServiceClient.new
|
25
|
+
composer_container_client = Yade::Composer::Rest::Client::ComposerContainerClient.new
|
26
|
+
|
27
|
+
composer_project = composer_project_client.get_by_name(project_name)
|
28
|
+
composer_services = composer_service_client.get_by_composer_project_id(composer_project.id)
|
29
|
+
|
30
|
+
composer_service = composer_services.select { |s| s.name == service_name }.first
|
31
|
+
|
32
|
+
composer_containers = composer_container_client.get_by_composer_service_id(composer_service.id)
|
33
|
+
|
34
|
+
container_names = composer_containers.map(&:name).join(' ')
|
35
|
+
|
36
|
+
begin
|
37
|
+
cmdline = 'docker-compose logs'
|
38
|
+
cmdline += ' -f' if options[:follow]
|
39
|
+
cmdline += " #{container_names}"
|
40
|
+
|
41
|
+
cmd = TTY::Command.new(uuid: false)
|
42
|
+
|
43
|
+
cmd.run(cmdline, chdir: composer_project.install_dir)
|
44
|
+
rescue TTY::Command::ExitError => e
|
45
|
+
puts e
|
46
|
+
end
|
47
|
+
|
48
|
+
'Yade composer service successfully logged'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
module Composer
|
9
|
+
class ComposerSetupCommand < Mutations::Command
|
10
|
+
|
11
|
+
#
|
12
|
+
def execute
|
13
|
+
Yade::Common::Config::ComposerConfig[:git_api_url] = UserInput.ask(' * Gitlab API Url?', :git_api_url)
|
14
|
+
Yade::Common::Config::ComposerConfig[:git_username] = UserInput.ask(' * Gitlab Username?', :git_username)
|
15
|
+
Yade::Common::Config::ComposerConfig[:git_password] = UserInput.ask(' * Gitlab Password?', :git_password)
|
16
|
+
Yade::Common::Config::ComposerConfig[:git_token] = UserInput.ask(' * Gitlab Api Token?', :git_token)
|
17
|
+
Yade::Common::Config::ComposerConfig[:docker_registry_url] = UserInput.ask(' * Docker Registry Url?', :docker_registry_url)
|
18
|
+
Yade::Common::Config::ComposerConfig[:docker_registry_username] = UserInput.ask(' * Docker Registry Username?', :docker_registry_username)
|
19
|
+
Yade::Common::Config::ComposerConfig[:docker_registry_password] = UserInput.ask(' * Docker Registry Password?', :docker_registry_password)
|
20
|
+
|
21
|
+
Yade::Common::Config::ComposerConfig.write!
|
22
|
+
|
23
|
+
'Yade compose successfully setup'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
|
5
|
+
module Yadecli
|
6
|
+
module Command
|
7
|
+
module Composer
|
8
|
+
class ComposerStartCommand < Mutations::Command
|
9
|
+
|
10
|
+
required do
|
11
|
+
string :project_name, empty: false
|
12
|
+
string :service_name, empty: false
|
13
|
+
end
|
14
|
+
|
15
|
+
optional do
|
16
|
+
hash :options do
|
17
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
def execute
|
23
|
+
composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
|
24
|
+
composer_service_client = Yade::Composer::Rest::Client::ComposerServiceClient.new
|
25
|
+
composer_container_client = Yade::Composer::Rest::Client::ComposerContainerClient.new
|
26
|
+
|
27
|
+
begin
|
28
|
+
composer_project = composer_project_client.get_by_name(project_name)
|
29
|
+
composer_services = composer_service_client.get_by_composer_project_id(composer_project.id)
|
30
|
+
|
31
|
+
# load project dotenv
|
32
|
+
dotenv_file = "#{composer_project.install_dir}/.env"
|
33
|
+
Dotenv.load(dotenv_file)
|
34
|
+
|
35
|
+
# check required envs are set fom .env file or system environment variables
|
36
|
+
composer_service = composer_services.select { |s| s.name == service_name }.first
|
37
|
+
|
38
|
+
composer_service.requiredEnvs&.split(',').each do |re|
|
39
|
+
if ENV[re] == nil
|
40
|
+
puts ''
|
41
|
+
puts "Unable to start service. Required environment variable #{re} is not set.".colorize(:red)
|
42
|
+
puts "Either specify the variable and a value in #{dotenv_file} or as a system environment variable an try to run again.".colorize(:red)
|
43
|
+
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
composer_containers = composer_container_client.get_by_composer_service_id(composer_service.id)
|
49
|
+
|
50
|
+
cmdline = "docker-compose up -d #{composer_containers.map(&:name).join(' ')}"
|
51
|
+
|
52
|
+
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
53
|
+
|
54
|
+
puts ''
|
55
|
+
print "Executing command '#{cmdline}'... "
|
56
|
+
|
57
|
+
cmd.run(cmdline, chdir: composer_project.install_dir)
|
58
|
+
|
59
|
+
puts 'done'.colorize(:green)
|
60
|
+
rescue TTY::Command::ExitError => e
|
61
|
+
puts 'failed'.colorize(:red)
|
62
|
+
puts e
|
63
|
+
end
|
64
|
+
|
65
|
+
'Yade composer service successfully started'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
|
5
|
+
module Yadecli
|
6
|
+
module Command
|
7
|
+
module Composer
|
8
|
+
class ComposerStopCommand < Mutations::Command
|
9
|
+
|
10
|
+
required do
|
11
|
+
string :project_name, empty: false
|
12
|
+
string :service_name, empty: false
|
13
|
+
end
|
14
|
+
|
15
|
+
optional do
|
16
|
+
hash :options do
|
17
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
def execute
|
23
|
+
composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
|
24
|
+
composer_service_client = Yade::Composer::Rest::Client::ComposerServiceClient.new
|
25
|
+
composer_container_client = Yade::Composer::Rest::Client::ComposerContainerClient.new
|
26
|
+
|
27
|
+
begin
|
28
|
+
composer_project = composer_project_client.get_by_name(project_name)
|
29
|
+
composer_services = composer_service_client.get_by_composer_project_id(composer_project.id)
|
30
|
+
|
31
|
+
composer_service = composer_services.select { |s| s.name == service_name }.first
|
32
|
+
|
33
|
+
composer_containers = composer_container_client.get_by_composer_service_id(composer_service.id)
|
34
|
+
|
35
|
+
container_names = composer_containers.map(&:name).join(' ')
|
36
|
+
|
37
|
+
cmdline = "docker-compose stop #{container_names}"
|
38
|
+
cmdline += " && docker-compose rm -f #{container_names}" if options[:rm]
|
39
|
+
cmdline += ' && docker-compose down -v' if options[:down]
|
40
|
+
|
41
|
+
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
42
|
+
|
43
|
+
puts ''
|
44
|
+
print "Executing command '#{cmdline}'... "
|
45
|
+
|
46
|
+
cmd.run(cmdline, chdir: composer_project.install_dir)
|
47
|
+
|
48
|
+
puts 'done'.colorize(:green)
|
49
|
+
rescue TTY::Command::ExitError => e
|
50
|
+
puts 'failed'.colorize(:red)
|
51
|
+
puts ''
|
52
|
+
'Stopping Yade composer service failed'
|
53
|
+
end
|
54
|
+
puts ''
|
55
|
+
'Yade composer service successfully stopped'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
|
5
|
+
module Yadecli
|
6
|
+
module Command
|
7
|
+
module Composer
|
8
|
+
class ComposerSwitchCommand < Mutations::Command
|
9
|
+
|
10
|
+
required do
|
11
|
+
string :project_name, empty: false
|
12
|
+
string :target_branch, empty: false
|
13
|
+
end
|
14
|
+
|
15
|
+
optional do
|
16
|
+
hash :options do
|
17
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
def execute
|
23
|
+
composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
|
24
|
+
|
25
|
+
composer_project = composer_project_client.get_by_name(project_name)
|
26
|
+
|
27
|
+
message = "Switching to branch #{target_branch}"
|
28
|
+
message += ' and pull changes' if options[:pull]
|
29
|
+
|
30
|
+
print message
|
31
|
+
|
32
|
+
cmdline = "git fetch && git checkout -B #{target_branch}"
|
33
|
+
cmdline += " && git pull origin #{target_branch}" if options[:pull]
|
34
|
+
|
35
|
+
begin
|
36
|
+
cmd = TTY::Command.new(output: Yadecli.LOGGER)
|
37
|
+
|
38
|
+
cmd.run(cmdline, chdir: composer_project.install_dir)
|
39
|
+
|
40
|
+
puts ' done'.colorize(:green)
|
41
|
+
rescue TTY::Command::ExitError => e
|
42
|
+
puts ' failed'.colorize(:red)
|
43
|
+
puts e
|
44
|
+
end
|
45
|
+
|
46
|
+
'Yade composer project successfully switched'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
|
5
|
+
module Yadecli
|
6
|
+
module Command
|
7
|
+
module Composer
|
8
|
+
class ComposerUninstallCommand < Mutations::Command
|
9
|
+
|
10
|
+
required do
|
11
|
+
string :project_name, empty: false
|
12
|
+
end
|
13
|
+
|
14
|
+
optional do
|
15
|
+
hash :options do
|
16
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
def execute
|
22
|
+
composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
|
23
|
+
|
24
|
+
composer_project = composer_project_client.get_by_name(project_name)
|
25
|
+
|
26
|
+
answer = false
|
27
|
+
unless options[:yes]
|
28
|
+
prompt = TTY::Prompt.new
|
29
|
+
answer = prompt.yes?("Do you really want to uninstall the #{composer_project.project_name} composer project?".colorize(:mode => :bold))
|
30
|
+
end
|
31
|
+
|
32
|
+
if options[:yes] || answer
|
33
|
+
FileUtils.rm_rf(composer_project.install_dir)
|
34
|
+
else
|
35
|
+
puts 'There is nothing more I can do for you. Bye.'
|
36
|
+
exit(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
'Composer project successfully uninstalled'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
class ConnectCommand < Mutations::Command
|
9
|
+
|
10
|
+
required do
|
11
|
+
string :yade_url, matches: URI.regexp
|
12
|
+
end
|
13
|
+
|
14
|
+
# These inputs are optional
|
15
|
+
#optional do
|
16
|
+
# boolean :newsletter_subscribe
|
17
|
+
#end
|
18
|
+
|
19
|
+
# The execute method is called only if the inputs validate. It does your business action.
|
20
|
+
def execute
|
21
|
+
Yade::Common::Config::AppConfig[:yade_url] = self.yade_url
|
22
|
+
|
23
|
+
Yade::Common::Config::AppConfig.write!
|
24
|
+
|
25
|
+
"Successfully connected to Yade at url #{self.yade_url}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
require 'net/ssh'
|
5
|
+
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
module Host
|
9
|
+
class HostBootstrapCommand < Mutations::Command
|
10
|
+
|
11
|
+
required do
|
12
|
+
string :host_fqdn, matches: /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/
|
13
|
+
end
|
14
|
+
|
15
|
+
optional do
|
16
|
+
hash :options do
|
17
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# The execute method is called only if the inputs validate. It does your business action.
|
22
|
+
def execute
|
23
|
+
host_client = Yade::Domain::Rest::Client::HostClient.new
|
24
|
+
domain_client = Yade::Domain::Rest::Client::DomainClient.new
|
25
|
+
role_client = Yade::Domain::Rest::Client::RoleClient.new
|
26
|
+
|
27
|
+
master_host = host_client.master
|
28
|
+
host = host_client.host_by_fqdn(self.host_fqdn)
|
29
|
+
|
30
|
+
domain_id = host.domainId
|
31
|
+
domain = domain_client.get(domain_id)
|
32
|
+
|
33
|
+
role_id = host.roleId
|
34
|
+
role = role_client.get(role_id)
|
35
|
+
|
36
|
+
username = host.username
|
37
|
+
port = host.sshPort || 22
|
38
|
+
|
39
|
+
Net::SSH.start(host.hostName, username, port: port) do |ssh|
|
40
|
+
# checkout_dir = Yade::Common::Config::AppConfig[:yade_home]
|
41
|
+
checkout_dir = "/home/#{username}/.yade"
|
42
|
+
local_repo = "#{checkout_dir}/puppet-bootstrap"
|
43
|
+
|
44
|
+
# clone or update
|
45
|
+
output = ssh.exec!("mkdir -p #{checkout_dir}")
|
46
|
+
puts output if options[:verbose]
|
47
|
+
|
48
|
+
clone_cmd = "git clone -b #{Yade::Common::Config::DomainConfig[:yade_bootstrap_repo_branch]} --depth 1 #{Yade::Common::Config::DomainConfig[:yade_bootstrap_repo_url]} #{local_repo} || (cd #{local_repo} ; git pull)"
|
49
|
+
puts clone_cmd
|
50
|
+
output = ssh.exec!(clone_cmd)
|
51
|
+
puts output if options[:verbose]
|
52
|
+
|
53
|
+
# setup
|
54
|
+
if options[:setup]
|
55
|
+
# output = ssh.exec!("mkdir -p #{local_repo}")
|
56
|
+
# puts output if options[:verbose]
|
57
|
+
|
58
|
+
output = ssh.exec!("sudo #{local_repo}/scripts/ubuntu/setup-managed-host.sh #{host.hostName} #{domain.name} #{host.ip}")
|
59
|
+
puts output if options[:verbose]
|
60
|
+
|
61
|
+
output = ssh.exec!("sudo #{local_repo}/scripts/ubuntu/local-bootstrap.sh \"mc nano\"")
|
62
|
+
puts output if options[:verbose]
|
63
|
+
|
64
|
+
output = ssh.exec!("sudo #{local_repo}/scripts/ubuntu/puppet-install.sh")
|
65
|
+
puts output if options[:verbose]
|
66
|
+
|
67
|
+
# noinspection RubyLiteralArrayInspection
|
68
|
+
modules = Yade::Common::Config::DomainConfig[:yade_bootstrap_puppet_modules]
|
69
|
+
|
70
|
+
FileUtils.rm_rf 'modules'
|
71
|
+
FileUtils.mkdir_p 'modules'
|
72
|
+
|
73
|
+
output = ssh.exec!("echo $HTTP_PROXY")
|
74
|
+
puts output if options[:verbose]
|
75
|
+
|
76
|
+
modules.each do |mod, version|
|
77
|
+
cmd = "puppet module install --modulepath #{local_repo}/modules --version #{version} #{mod}"
|
78
|
+
|
79
|
+
output = ssh.exec!(cmd)
|
80
|
+
puts output if options[:verbose]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# provision
|
85
|
+
cmd_a = [
|
86
|
+
'FACTER_vagrant=1',
|
87
|
+
"FACTER_host_ip=#{host.ip}",
|
88
|
+
"FACTER_host_name=#{host.hostName}",
|
89
|
+
"FACTER_host_domain=#{domain.name}",
|
90
|
+
"FACTER_master_ip=#{master_host.ip}",
|
91
|
+
"FACTER_master_host_name=#{master_host.hostName}",
|
92
|
+
"FACTER_role=#{role.name}",
|
93
|
+
"FACTER_datacenter=#{host.datacenter}",
|
94
|
+
"FACTER_zone=#{host.zone}",
|
95
|
+
"FACTER_is_master=#{host.isMaster}",
|
96
|
+
"FACTER_username=#{username}",
|
97
|
+
'sudo --preserve-env puppet apply',
|
98
|
+
"--hiera_config=#{local_repo}/config/hiera.yml",
|
99
|
+
"--modulepath=#{local_repo}/modules:#{local_repo}/dist",
|
100
|
+
"#{local_repo}/environments/production/manifests/default.pp"
|
101
|
+
]
|
102
|
+
|
103
|
+
cmd_line = cmd_a.join(' ')
|
104
|
+
|
105
|
+
puts cmd_line if options[:verbose]
|
106
|
+
|
107
|
+
channel = ssh.open_channel do |ch|
|
108
|
+
ch.exec cmd_line do |ch, success|
|
109
|
+
raise "could not execute command" unless success
|
110
|
+
|
111
|
+
# "on_data" is called when the process writes something to stdout
|
112
|
+
ch.on_data do |c, data|
|
113
|
+
$stdout.print data if options[:verbose]
|
114
|
+
end
|
115
|
+
|
116
|
+
# "on_extended_data" is called when the process writes something to stderr
|
117
|
+
ch.on_extended_data do |c, type, data|
|
118
|
+
$stderr.print data if options[:verbose]
|
119
|
+
end
|
120
|
+
|
121
|
+
ch.on_close { puts "done!" }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
channel.wait
|
126
|
+
end
|
127
|
+
"Successfully bootstrapped host #{self.host_fqdn}"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
require 'tty-table'
|
5
|
+
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
module Host
|
9
|
+
class HostListCommand < Mutations::Command
|
10
|
+
|
11
|
+
#
|
12
|
+
def execute
|
13
|
+
host_client = Yade::Domain::Rest::Client::HostClient.new
|
14
|
+
domain_client = Yade::Domain::Rest::Client::DomainClient.new
|
15
|
+
role_client = Yade::Domain::Rest::Client::RoleClient.new
|
16
|
+
|
17
|
+
hosts = host_client.list
|
18
|
+
|
19
|
+
table = TTY::Table.new header: ['Name', 'Domain', 'Role', 'Ip', 'OsType', 'Environment']
|
20
|
+
|
21
|
+
hosts.each do |h|
|
22
|
+
domain_id = h.domainId
|
23
|
+
domain = domain_client.get(domain_id)
|
24
|
+
|
25
|
+
role_id = h.roleId
|
26
|
+
role = role_client.get(role_id)
|
27
|
+
|
28
|
+
table << [h.name, domain.name, role.name, h.ip, h.osType, h.environmentType]
|
29
|
+
end
|
30
|
+
|
31
|
+
table.render(:ascii, width: 100, resize: true, padding: [0, 1])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mutations'
|
4
|
+
require 'net/ssh'
|
5
|
+
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
module Host
|
9
|
+
class HostProvisionCommand < Mutations::Command
|
10
|
+
|
11
|
+
required do
|
12
|
+
string :host_fqdn, matches: /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/
|
13
|
+
end
|
14
|
+
|
15
|
+
optional do
|
16
|
+
hash :options do
|
17
|
+
string :* # Allows any key to pass through. Useful for dynamic key / value objects
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
def execute
|
23
|
+
host_client = Yade::Domain::Rest::Client::HostClient.new
|
24
|
+
|
25
|
+
host = host_client.host_by_fqdn(self.host_fqdn)
|
26
|
+
|
27
|
+
username = host.username
|
28
|
+
port = host.sshPort || 22
|
29
|
+
|
30
|
+
Net::SSH.start(host.hostName, username, port: port) do |ssh|
|
31
|
+
# clone or update
|
32
|
+
cmd_line = "sudo puppet agent -t --environment=#{host.environmentType.downcase}"
|
33
|
+
|
34
|
+
channel = ssh.open_channel do |ch|
|
35
|
+
ch.exec cmd_line do |ch, success|
|
36
|
+
raise "could not execute command" unless success
|
37
|
+
|
38
|
+
# "on_data" is called when the process writes something to stdout
|
39
|
+
ch.on_data do |c, data|
|
40
|
+
$stdout.print data if options[:verbose]
|
41
|
+
end
|
42
|
+
|
43
|
+
# "on_extended_data" is called when the process writes something to stderr
|
44
|
+
ch.on_extended_data do |c, type, data|
|
45
|
+
$stderr.print data if options[:verbose]
|
46
|
+
end
|
47
|
+
|
48
|
+
ch.on_close { puts "done!" }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
channel.wait
|
53
|
+
end
|
54
|
+
"Successfully provisioned host #{self.host_fqdn}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
# yadecli cli
|
6
|
+
module Yadecli
|
7
|
+
module Command
|
8
|
+
# login
|
9
|
+
class LoginCommand < Mutations::Command
|
10
|
+
|
11
|
+
required do
|
12
|
+
string :auth_url, matches: URI.regexp
|
13
|
+
string :auth_username, empty: false
|
14
|
+
string :auth_password, empty: false
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
authentication_client = Yade::Common::Client::AuthenticationClient.new
|
19
|
+
|
20
|
+
authentication = authentication_client.login(auth_url, auth_username, auth_password)
|
21
|
+
|
22
|
+
"Successfully logged in user #{authentication.auth_username} with password *** at uaa #{authentication.auth_url}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|