vagrant-subutai 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,116 +2,110 @@ require_relative '../vagrant-subutai'
2
2
  require 'optparse'
3
3
  require 'io/console'
4
4
  require 'net/https'
5
- require_relative 'subutai_commands'
6
5
  require 'fileutils'
7
6
 
8
7
  module VagrantSubutai
9
- module Subutai
10
- class Command < Vagrant.plugin('2', :command)
11
- # shows description when `vagrant list-commands` is triggered
12
- def self.synopsis
13
- 'Vagrant Subutai Plugin - executes Subutai scripts in target hosts'
14
- end
8
+ class Command < Vagrant.plugin('2', :command)
9
+ attr_accessor :box
10
+ # shows description when `vagrant list-commands` is triggered
11
+ def self.synopsis
12
+ 'Vagrant Subutai Plugin - executes Subutai scripts in target hosts'
13
+ end
15
14
 
16
- def execute
17
- cli_info
18
15
 
19
- # Gets Subutai console url and box name from Vagrantfile
20
- with_target_vms(nil, single_target: true) do |machine|
21
- $SUBUTAI_BOX_NAME = machine.config.vm.box
22
- end
16
+ def execute
17
+ cli_info
23
18
 
24
- subutai_cli = VagrantSubutai::Commands.new(ARGV, @env)
19
+ # Gets Subutai console url and box name from Vagrantfile
20
+ with_target_vms(nil, single_target: true) do |machine|
21
+ @box = machine.config.vm.box
22
+ end
25
23
 
26
- case ARGV[1]
27
- when 'register'
28
- check_subutai_console_url(subutai_cli)
29
- subutai_cli.register(nil, nil)
30
- when 'fingerprint'
31
- check_subutai_console_url(subutai_cli)
32
- subutai_cli.fingerprint($SUBUTAI_CONSOLE_URL)
33
- when 'disk'
34
- disk = SubutaiConfig.get(:DISK_SIZE)
24
+ subutai_cli = Commands.new(ARGV, @env)
35
25
 
36
- if disk.nil?
37
- STDOUT.puts " \e[32mSubutai disk capacity is 100 gb.\e[0m"
38
- else
39
- STDOUT.puts " \e[32mSubutai disk capacity is #{disk} gb.\e[0m"
40
- end
41
- when '-h'
42
- STDOUT.puts cli_info
43
- when '--help'
44
- STDOUT.puts cli_info
45
- else
46
- # All Agent CLI commands implemented here
26
+ case ARGV[1]
27
+ when 'register'
28
+ subutai_cli.register(nil, nil, check_subutai_console_url(subutai_cli))
29
+ when 'fingerprint'
30
+ subutai_cli.fingerprint(check_subutai_console_url(subutai_cli))
31
+ when 'open'
32
+ subutai_cli.open(check_subutai_console_url(subutai_cli))
33
+ when 'blueprint'
34
+ subutai_cli.blueprint(check_subutai_console_url(subutai_cli))
35
+ when '-h'
36
+ STDOUT.puts cli_info
37
+ when '--help'
38
+ STDOUT.puts cli_info
39
+ else
40
+ # All Agent CLI commands implemented here
47
41
 
48
- command = ARGV
49
- command.shift
42
+ command = ARGV
43
+ command.shift
50
44
 
51
- if command.empty?
52
- STDOUT.puts cli_info
53
- else
54
- subutai_cli.ssh("#{subutai_cli.base} #{command.join(' ')}")
55
- end
56
- end
45
+ if command.empty?
46
+ STDOUT.puts cli_info
47
+ else
48
+ subutai_cli.ssh("#{subutai_cli.base} #{command.join(' ')}")
49
+ end
57
50
  end
51
+ end
58
52
 
59
- def check_subutai_console_url(subutai_cli)
60
- ip = subutai_cli.info(VagrantCommand::ARG_IP_ADDR)
53
+ def check_subutai_console_url(subutai_cli)
54
+ ip = subutai_cli.info(Configs::VagrantCommand::ARG_IP_ADDR)
61
55
 
62
- if ip.nil?
63
- STDOUT.puts "We can't detect your Subutai Console ip address!"
64
- exit
65
- end
66
- $SUBUTAI_CONSOLE_URL = "https://#{ip}:#{SubutaiConsoleAPI::PORT}"
56
+ if ip.nil?
57
+ STDOUT.puts 'We can\'t detect your Subutai Console ip address!'
58
+ exit
67
59
  end
60
+ "https://#{ip}:#{Configs::SubutaiConsoleAPI::PORT}"
61
+ end
68
62
 
69
- def cli_info
70
- commands = <<-EOF
71
-
63
+ def cli_info
64
+ commands = <<-EOF
65
+
72
66
  Usage: vagrant subutai command [command options] [arguments...]
73
67
 
74
68
  COMMANDS:
75
- attach - attach to Subutai container
76
- backup - backup Subutai container
77
- batch - batch commands execution
78
- checkpoint - checkpoint/restore in user space
79
- clone - clone Subutai container
80
- cleanup - clean Subutai environment
81
- config - edit container config
82
- daemon - start Subutai agent
83
- demote - demote Subutai container
84
- destroy - destroy Subutai container
85
- export - export Subutai container
86
- import - import Subutai template
87
- info - information about host system
88
- hostname - Set hostname of container or host
89
- list - list Subutai container
90
- log - print application logs
91
- map - Subutai port mapping
92
- metrics - list Subutai container
93
- migrate - migrate Subutai container
94
- p2p - P2P network operations
95
- promote - promote Subutai container
96
- proxy - Subutai reverse proxy
97
- quota - set quotas for Subutai container
98
- rename - rename Subutai container
99
- restore - restore Subutai container
100
- stats - statistics from host
101
- start - start Subutai container
102
- stop - stop Subutai container
103
- tunnel - SSH tunnel management
104
- update - update Subutai management, container or Resource host
105
- vxlan - VXLAN tunnels operation
106
- register - register Subutai Peer to Hub
107
- fingerprint - shows fingerprint Subutai Console
108
- disk - shows Subutai disk size
69
+ attach - attach to Subutai container
70
+ backup - backup Subutai container
71
+ batch - batch commands execution
72
+ checkpoint - checkpoint/restore in user space
73
+ clone - clone Subutai container
74
+ cleanup - clean Subutai environment
75
+ config - edit container config
76
+ daemon - start Subutai agent
77
+ demote - demote Subutai container
78
+ destroy - destroy Subutai container
79
+ export - export Subutai container
80
+ import - import Subutai template
81
+ info - information about host system
82
+ hostname - Set hostname of container or host
83
+ list - list Subutai container
84
+ log - print application logs
85
+ map - Subutai port mapping
86
+ metrics - list Subutai container
87
+ migrate - migrate Subutai container
88
+ p2p - P2P network operations
89
+ promote - promote Subutai container
90
+ proxy - Subutai reverse proxy
91
+ quota - set quotas for Subutai container
92
+ rename - rename Subutai container
93
+ restore - restore Subutai container
94
+ stats - statistics from host
95
+ start - start Subutai container
96
+ stop - stop Subutai container
97
+ tunnel - SSH tunnel management
98
+ update - update Subutai management, container or Resource host
99
+ vxlan - VXLAN tunnels operation
100
+ register - register Subutai PeerOS to Bazaar
101
+ fingerprint - shows fingerprint Subutai Console
102
+ open - open the Subutai PeerOS in browser
103
+ blueprint - run blueprint provisioning
109
104
 
110
105
  GLOBAL OPTIONS:
111
- -h, --help - show help
112
- EOF
113
- commands
114
- end
106
+ -h, --help - show help
107
+ EOF
108
+ commands
115
109
  end
116
110
  end
117
111
  end
@@ -1,52 +1,17 @@
1
1
  require_relative '../vagrant-subutai'
2
2
 
3
- module SubutaiAgentCommand
4
- BASE = "sudo /snap/bin/subutai"
5
- UPDATE = " update" # arg required
6
- LOG = " log"
7
- INFO = " info" # arg required
8
- TEMPLATE_IMPORT = " import ubuntu16"
9
- TEMPLATE_CLONE = " clone ubuntu16" # arg required
10
- TEMPLATE_ATTACH = " attach" # arg required
11
- TEMPLATE_EXPORT = " export" # arg required
12
- LIST = " list"
13
- end
14
-
15
- module SubutaiConsoleAPI
16
- PORT = "8443"
17
- module V1
18
- TOKEN = "/rest/v1/identity/gettoken"
19
- REGISTER_HUB = "/rest/v1/hub/register?sptoken="
20
- APPROVE = "/rest/v1/registration/requests"
21
- FINGERPRINT = "/rest/v1/security/keyman/getpublickeyfingerprint"
22
- REQUESTS = "/rest/v1/registration/requests?sptoken="
23
- end
24
- end
25
-
26
3
  module VagrantSubutai
27
- module Subutai
28
- RH_FOLDER_NAME = "RH"
29
-
30
- class Config < Vagrant.plugin('2', :config)
31
- attr_accessor :url
4
+ class Config < Vagrant.plugin('2', :config)
5
+ attr_accessor :url
32
6
 
33
- def initialize
34
- super
35
- @url = UNSET_VALUE
36
- end
7
+ def initialize
8
+ super
9
+ @url = UNSET_VALUE
10
+ end
37
11
 
38
- def finalize!
39
- @url = "" if @url == UNSET_VALUE
40
- end
12
+ def finalize!
13
+ @url = '' if @url == UNSET_VALUE
41
14
  end
42
15
  end
43
16
  end
44
17
 
45
- module VagrantCommand
46
- INIT = "vagrant init"
47
- UP = "vagrant up"
48
- RH_UP = "SUBUTAI_PEER=false vagrant up"
49
- PROVISION = "vagrant provision"
50
- SUBUTAI_ID = "vagrant subutai --info id"
51
- ARG_IP_ADDR = "ipaddr"
52
- end
@@ -0,0 +1,179 @@
1
+ module VagrantSubutai
2
+ module Configs
3
+ module VagrantCommand
4
+ INIT = 'vagrant init'.freeze
5
+ UP = 'vagrant up'.freeze
6
+ RH_UP = 'SUBUTAI_PEER=false vagrant up'.freeze
7
+ PROVISION = 'vagrant provision'.freeze
8
+ SUBUTAI_ID = 'vagrant subutai --info id'.freeze
9
+ ARG_IP_ADDR = 'ipaddr'.freeze
10
+ end
11
+
12
+ module Ansible
13
+ TEMPLATE_NAME = 'generic-ansible'.freeze
14
+ end
15
+
16
+ module Quota
17
+ # CPU percentage %
18
+ # RAM, DISK unit Gigabytes
19
+ RESOURCE = {
20
+ TINY: { CPU: 10, RAM: 0.25, DISK: 4 },
21
+ SMALL: { CPU: 25, RAM: 0.5, DISK: 10 },
22
+ MEDIUM: { CPU: 50, RAM: 1, DISK: 20 },
23
+ LARGE: { CPU: 75, RAM: 2, DISK: 40 },
24
+ HUGE: { CPU: 100, RAM: 4, DISK: 100 }
25
+ }.freeze
26
+ end
27
+
28
+ module Blueprint
29
+ SCHEME = {
30
+ name: 'name',
31
+ description: 'My static website',
32
+ version: 'Blueprint version',
33
+ 'author': 'Author',
34
+ 'ssh-key': 'ssh-key-name',
35
+ containers: [
36
+ {
37
+ hostname: 'www',
38
+ template: 'apache',
39
+ size: 'TINY',
40
+ 'peer-criteria': 'HTTP-GROUP',
41
+ 'port-mapping': [
42
+ {
43
+ protocol: 'http',
44
+ domain: '${domain}',
45
+ 'internal-port': '80',
46
+ 'external-port': '80'
47
+ },
48
+ {
49
+ protocol: 'tcp',
50
+ domain: '${domain}',
51
+ 'internal-port': '22',
52
+ 'external-port': '4040'
53
+ }
54
+ ]
55
+ }
56
+ ],
57
+ 'peer-criteria': [
58
+ {
59
+ name: 'HTTP-GROUP',
60
+ 'max-price': '5',
61
+ 'avg-cpu-load': '50',
62
+ 'min-free-ram': '128',
63
+ 'min-free-disk-space': '10'
64
+ }
65
+ ],
66
+ 'ansible-configuration': {
67
+ 'source-url': 'zip_file_url',
68
+ 'ansible-playbook': 'any_name',
69
+ 'extra-vars': [
70
+ {
71
+ 'key': 'any_name',
72
+ 'value': 'any_name_value'
73
+ }
74
+ ],
75
+ 'groups': [
76
+ {
77
+ 'name': 'any_name',
78
+ 'python-interpreter': '/usr/bin/python3',
79
+ 'hostnames': [
80
+ 'hostname_of_container'
81
+ ]
82
+ }
83
+ ]
84
+ },
85
+ 'user-variables': {
86
+ any_name: {
87
+ description: 'Select your domain or create new one',
88
+ type: 'domain',
89
+ default: 'site.env.subutai.cloud',
90
+ validation: '[a-zA-Z0-9.-]+'
91
+ }
92
+ }
93
+ }.freeze
94
+ CONTAINER_SIZES = %w(TINY SMALL MEDIUM LARGE HUGE).freeze
95
+
96
+ module MODE
97
+ PEER = 'peer'.freeze
98
+ BAZAAR = 'bazaar'.freeze
99
+ end
100
+ end
101
+
102
+ module Environment
103
+ PROD = 'prod'.freeze
104
+ DEV = 'dev'.freeze
105
+ SYSNET = 'sysnet'.freeze
106
+ MASTER = 'master'.freeze
107
+ end
108
+
109
+ module SubutaiConsoleAPI
110
+ PORT = '8443'.freeze
111
+ COMMAND = '/rest/ui/commands?sptoken='.freeze
112
+
113
+ module V1
114
+ TOKEN = '/rest/v1/identity/gettoken'.freeze
115
+ REGISTER_HUB = '/rest/v1/hub/register?sptoken='.freeze
116
+ APPROVE = '/rest/v1/registration/requests'.freeze
117
+ FINGERPRINT = '/rest/v1/security/keyman/getpublickeyfingerprint'.freeze
118
+ REQUESTS = '/rest/v1/registration/requests?sptoken='.freeze
119
+ ENVIRONMENT = '/rest/v1/environments?sptoken='.freeze
120
+ HOSTS = '/rest/v1/hosts?sptoken='.freeze
121
+ ENVIRONMENTS = '/rest/v1/environments?sptoken='.freeze
122
+ LOG = '/rest/v1/tracker/operations/ENVIRONMENT%20MANAGER/'.freeze
123
+ RESOURCES = '/rest/v1/peer/resources?sptoken='.freeze
124
+ DOMAIN = '/rest/ui/environments/'.freeze
125
+ end
126
+ end
127
+
128
+ module Gorjun
129
+ INFO_DEV = 'https://devcdn.subutai.io:8338/kurjun/rest/template/info'.freeze
130
+ INFO_MASTER = 'https://mastercdn.subutai.io:8338/kurjun/rest/template/info'.freeze
131
+ INFO_PROD = 'https://cdn.subutai.io:8338/kurjun/rest/template/info'.freeze
132
+ end
133
+
134
+ module Bazaar
135
+ BASE_DEV = 'https://devbazaar.subutai.io'.freeze
136
+ BASE_MASTER = 'https://masterbazaar.subutai.io'.freeze
137
+ BASE_PROD = 'https://bazaar.subutai.io'.freeze
138
+
139
+ module V1
140
+ PEER = '/rest/v1/tray/peers/{FINGERPRINT}'.freeze
141
+ LOGIN = '/rest/v1/client/login'.freeze
142
+ ENVIRONMENTS = '/rest/v1/client/environments'.freeze
143
+ LOG = '/rest/v1/client/environments/{SUBUTAI_ID}'.freeze
144
+ DOMAIN_RESERVE = '/rest/v1/client/domains/{DOMAIN}'
145
+ VARIABLES = '/rest/v1/client/blueprint/variables'.freeze
146
+ BLUEPRINT = '/rest/v1/client/blueprint/build'.freeze
147
+ DOMAIN_LIST = '/rest/v1/client/domains'.freeze
148
+ end
149
+ end
150
+
151
+ module Blueprint
152
+ FILE_NAME = 'Subutai.json'.freeze
153
+ end
154
+
155
+ module EnvironmentState
156
+ FAILED = 'FAILED'.freeze
157
+ SUCCEEDED = 'SUCCEEDED'.freeze
158
+ HEALTHY = 'HEALTHY'.freeze
159
+ UNHEALTHY = 'UNHEALTHY'.freeze
160
+ end
161
+
162
+ module ApplicationState
163
+ INSTALLING = 'INSTALLING'.freeze
164
+ INSTALLED = 'INSTALLED'.freeze
165
+ end
166
+
167
+ module SubutaiAgentCommand
168
+ BASE = 'sudo /snap/bin/subutai'.freeze
169
+ UPDATE = ' update'.freeze # arg required
170
+ LOG = ' log'.freeze
171
+ INFO = ' info'.freeze # arg required
172
+ LIST = ' list'.freeze
173
+ TEMPLATE_IMPORT = ' import ubuntu16'.freeze
174
+ TEMPLATE_CLONE = ' clone ubuntu16'.freeze # arg required
175
+ TEMPLATE_ATTACH = ' attach'.freeze # arg required
176
+ TEMPLATE_EXPORT = ' export'.freeze # arg required
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,18 @@
1
+ # Blueprint ansible model
2
+
3
+ module VagrantSubutai
4
+ module Models
5
+ class Ansible
6
+ attr_accessor :extra_vars, # Array of JSON objects { "key": string, "value": string }
7
+ :source_url,
8
+ :ansible_playbook,
9
+ :groups # Array of JSON objects { "name": string, "hostnames": [ string ] }
10
+
11
+ def context
12
+ self.instance_variables.map do |attribute|
13
+ { attribute => self.instance_variable_get(attribute) }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end