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.
@@ -0,0 +1,27 @@
1
+ # Subutai Console REST API container model
2
+
3
+ module VagrantSubutai
4
+ module Models
5
+ module Console
6
+ class Container
7
+ attr_accessor :id,
8
+ :environmentId,
9
+ :hostname,
10
+ :ip,
11
+ :templateName,
12
+ :templateId,
13
+ :type,
14
+ :arch,
15
+ :tags, # JSON array
16
+ :peerId,
17
+ :hostId,
18
+ :local, # boolean
19
+ :state,
20
+ :rhId,
21
+ :quota, # JSON object {"containerSize": string, "cpu": string, "ram": string, "disk": string}
22
+ :dataSource,
23
+ :containerName
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # Subutai Console REST API environment model
2
+
3
+ module VagrantSubutai
4
+ module Models
5
+ module Console
6
+ class Environment
7
+ attr_accessor :id,
8
+ :name,
9
+ :status,
10
+ :containers, # Array of Container models
11
+ :ansible_host_id, # Ansible host id
12
+ :ansible_container_state # Ansible container state
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ # Blueprint container model
2
+
3
+ module VagrantSubutai
4
+ module Models
5
+ class Container
6
+ attr_accessor :hostname,
7
+ :name,
8
+ :container_size,
9
+ :owner,
10
+ :resource_host_id,
11
+ :peer_id,
12
+ :peer_criteria,
13
+ :port_mapping
14
+
15
+ def template=(value)
16
+ temp = value.split('@')
17
+ @template = value
18
+ @name = temp[0]
19
+ @owner = temp[1]
20
+ end
21
+
22
+ def template
23
+ @template
24
+ end
25
+
26
+ def ansible
27
+ @hostname = "generic-ansible"
28
+ @container_size = "TINY"
29
+ @name = "generic-ansible"
30
+ @owner = "subutai" # ec54e1cff2341cdc55be5e961cfd15b4f97087e8
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantSubutai
2
+ module Models
3
+ class Domain
4
+ attr_accessor :protocol, # protocol HTTP, HTTPS or tcp etc
5
+ :name, # domain name ex: subutai.io
6
+ :internal_port, # internal container port
7
+ :external_port, # external port
8
+ :container_hostname # Container hostname
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # Blueprint environment model
2
+
3
+ module VagrantSubutai
4
+ module Models
5
+ class Environment
6
+ attr_accessor :name, # value for Peer Os
7
+ :containers, # Model 'Container'
8
+ :environment_name, # value for Bazaar
9
+ :exchange_ssh_keys, # value for Bazaar
10
+ :register_hosts # value for Bazaar
11
+ end
12
+ end
13
+ end
@@ -35,6 +35,14 @@ module SubutaiConfig
35
35
  AUTHORIZED_KEYS
36
36
  PASSWORD_OVERRIDE
37
37
  DISK_SIZE
38
+ SUBUTAI_ENV_TYPE
39
+ SUBUTAI_NAME
40
+ SUBUTAI_SCOPE
41
+ SUBUTAI_USERNAME
42
+ SUBUTAI_PASSWORD
43
+ USER_VARIABLES
44
+ BAZAAR_EMAIL
45
+ BAZAAR_PASSWORD
38
46
  ].freeze
39
47
 
40
48
  GENERATED_PARAMETERS = %i[
@@ -72,6 +80,8 @@ module SubutaiConfig
72
80
  SUBUTAI_PEER: true, # to provision or not console (peer)
73
81
  SUBUTAI_RAM: 4096, # RAM memory assigned to the vm
74
82
  SUBUTAI_CPU: 2, # virtual CPU's assign to the vm
83
+ SUBUTAI_NAME: 'My Peer', # PeerOS name
84
+ SUBUTAI_SCOPE: 'Public', # PeerOS scope
75
85
 
76
86
  # Configuration parameters below have not been implemented
77
87
  SUBUTAI_SNAP: nil, # alternative snap to provision
@@ -225,7 +235,7 @@ module SubutaiConfig
225
235
  # Stores ONLY generated configuration from YAML files
226
236
  def self.store
227
237
  FileUtils.mkdir_p(PARENT_DIR) unless Dir.exist?(PARENT_DIR)
228
- stringified = Hash[@generated.map { |k, v| [k.to_s, v.to_s] }]
238
+ stringified = Hash[@generated.map { |k, v| [k.to_s, v] }]
229
239
  File.open(GENERATED_FILE, 'w') { |f| f.write stringified.to_yaml }
230
240
 
231
241
  true
@@ -297,6 +307,11 @@ module SubutaiConfig
297
307
 
298
308
  # Load overrides from the environment, and generated configurations
299
309
  ENV.each do |key, value|
310
+ if value == 'true'
311
+ value = true
312
+ elsif value == 'false'
313
+ value = false
314
+ end
300
315
  put(key.to_sym, value, false) if USER_PARAMETERS.include? key.to_sym
301
316
  end
302
317
  do_handlers
@@ -357,6 +372,7 @@ module SubutaiConfig
357
372
  end
358
373
  end
359
374
 
375
+ # TODO remove Openssl verify (if certificate expired in cdn this code will be crashed)
360
376
  def self.get_latest_id_artifact(owner, artifact_name)
361
377
  url = url_of_cdn + '/raw/info?owner=' + owner + '&name=' + artifact_name
362
378
  uri = URI(url)
@@ -1,7 +1,8 @@
1
1
  module VagrantSubutai
2
2
  module Subutai
3
3
  class Plugin < Vagrant.plugin(2)
4
- name 'Subutai'
4
+ name 'subutai'
5
+
5
6
  description <<-DESC
6
7
  Vagrant Subutai CLI - executes Subutai scripts in target hosts
7
8
  DESC
@@ -11,9 +12,15 @@ module VagrantSubutai
11
12
  Command
12
13
  end
13
14
 
15
+ provisioner "blueprint" do
16
+ require_relative "provisioner"
17
+ Provisioner
18
+ end
19
+
20
+
14
21
  config 'subutai_console' do
15
- require_relative 'config'
16
- Config
22
+ require_relative 'config'
23
+ Config
17
24
  end
18
25
  end
19
26
  end
@@ -0,0 +1,63 @@
1
+ require_relative '../vagrant-subutai'
2
+
3
+
4
+ module VagrantSubutai
5
+ class Provisioner < Vagrant.plugin(2, :provisioner)
6
+ attr_reader :machine
7
+ attr_reader :config
8
+
9
+ # Initializes the provisioner with the machine that it will be
10
+ # provisioning along with the provisioner configuration (if there
11
+ # is any).
12
+ #
13
+ # The provisioner should _not_ do anything at this point except
14
+ # initialize internal state.
15
+ #
16
+ # @param [Machine] machine The machine that this will be provisioning.
17
+ # @param [Object] config Provisioner configuration, if one was set.
18
+ def initialize(machine, config)
19
+ @machine = machine
20
+ @config = config
21
+ end
22
+
23
+ # Called with the root configuration of the machine so the provisioner
24
+ # can add some configuration on top of the machine.
25
+ #
26
+ # During this step, and this step only, the provisioner should modify
27
+ # the root machine configuration to add any additional features it
28
+ # may need. Examples include sharing folders, networking, and so on.
29
+ # This step is guaranteed to be called before any of those steps are
30
+ # done so the provisioner may do that.
31
+ #
32
+ # No return value is expected.
33
+ def configure(root_config)
34
+ end
35
+
36
+ # This is the method called when the actual provisioning should be
37
+ # done. The communicator is guaranteed to be ready at this point,
38
+ # and any shared folders or networks are already setup.
39
+ #
40
+ # No return value is expected.
41
+ def provision
42
+ # If Subutai.json exist
43
+ if File.exist?("#{Dir.pwd}/#{Configs::Blueprint::FILE_NAME}")
44
+ subutai_cli = Commands.new(ARGV, @machine.env)
45
+ ip = subutai_cli.info(Configs::VagrantCommand::ARG_IP_ADDR)
46
+
47
+ if ip.nil?
48
+ STDOUT.puts 'We can\'t detect your Subutai Console ip address!'
49
+ exit
50
+ end
51
+ url = "https://#{ip}:#{Configs::SubutaiConsoleAPI::PORT}"
52
+
53
+ subutai_cli.blueprint(url)
54
+ end
55
+ end
56
+
57
+ # This is the method called when destroying a machine that allows
58
+ # for any state related to the machine created by the provisioner
59
+ # to be cleaned up.
60
+ def cleanup
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,21 @@
1
+ module Put
2
+ # Color yellow
3
+ def self.warn(msg)
4
+ STDOUT.puts "\e[33m#{msg}\e[0m"
5
+ end
6
+
7
+ # Color gray
8
+ def self.info(msg)
9
+ STDOUT.puts "\e[37m#{msg}\e[0m"
10
+ end
11
+
12
+ # Color green
13
+ def self.success(msg)
14
+ STDOUT.puts "\e[32m#{msg}\e[0m"
15
+ end
16
+
17
+ # Color red
18
+ def self.error(msg)
19
+ STDOUT.puts "\e[31m#{msg}\e[0m"
20
+ end
21
+ end
@@ -0,0 +1,141 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require_relative '../../vagrant-subutai'
4
+ require 'json'
5
+
6
+ module VagrantSubutai
7
+ module Rest
8
+ class Bazaar
9
+
10
+ def self.variables(subutai_json, peers_id, cookies)
11
+ uri = URI.parse(url + Configs::Bazaar::V1::VARIABLES)
12
+ https = Net::HTTP.new(uri.host, uri.port)
13
+ https.use_ssl = true
14
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
15
+ https.read_timeout = 3600 # an hour
16
+
17
+ request = Net::HTTP::Put.new(uri.request_uri, {'Cookie' => cookies, 'Content-Type' => 'application/x-www-form-urlencoded'})
18
+ request.set_form_data({'blueprint' => subutai_json.to_json, 'peers' => [peers_id]})
19
+
20
+ https.request(request)
21
+ end
22
+
23
+ def self.blueprint(blueprint, variables, peer_id, cookies)
24
+ uri = URI.parse(url + Configs::Bazaar::V1::BLUEPRINT)
25
+ https = Net::HTTP.new(uri.host, uri.port)
26
+ https.use_ssl = true
27
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
+ https.read_timeout = 3600 # an hour
29
+
30
+ request = Net::HTTP::Post.new(uri.request_uri, {'Cookie' => cookies, 'Content-Type' => 'application/x-www-form-urlencoded'})
31
+ request.set_form_data({'blueprint' => blueprint.to_json, 'variables'=> variables.to_json, 'peers' => peer_id})
32
+
33
+ https.request(request)
34
+ end
35
+
36
+ def self.login(email, password)
37
+ uri = URI.parse(url + Configs::Bazaar::V1::LOGIN)
38
+ https = Net::HTTP.new(uri.host, uri.port)
39
+ https.use_ssl = true
40
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
+ https.read_timeout = 3600 # an hour
42
+
43
+ request = Net::HTTP::Post.new(uri.request_uri)
44
+ request.set_form_data({'email' => email, 'password' => password})
45
+
46
+ https.request(request)
47
+ end
48
+
49
+ # Check is Peer Os registered to Bazaar
50
+ def self.registered(fingerprint)
51
+ uri = URI.parse(url + Configs::Bazaar::V1::PEER.gsub('{FINGERPRINT}', fingerprint))
52
+ https = Net::HTTP.new(uri.host, uri.port)
53
+ https.use_ssl = true
54
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
55
+ https.read_timeout = 3600 # an hour
56
+
57
+ request = Net::HTTP::Get.new(uri.request_uri)
58
+ https.request(request)
59
+ end
60
+
61
+ # Creates Environment
62
+ def self.environment(cookies, params)
63
+ uri = URI.parse(url + Configs::Bazaar::V1::ENVIRONMENTS)
64
+
65
+ https = Net::HTTP.new(uri.host, uri.port)
66
+ https.use_ssl = true
67
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
68
+ https.read_timeout = 21600 # 6 hours
69
+
70
+ request = Net::HTTP::Post.new(uri.request_uri, {'Cookie' => cookies, 'Content-Type' => 'application/json'})
71
+ request.body = params.to_json
72
+
73
+ https.request(request)
74
+ end
75
+
76
+ # Tracks environment create state logs
77
+ def self.log(cookies, subutai_id)
78
+ uri = URI.parse(url + Configs::Bazaar::V1::LOG.gsub('{SUBUTAI_ID}', subutai_id))
79
+
80
+ https = Net::HTTP.new(uri.host, uri.port)
81
+ https.use_ssl = true
82
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
83
+ https.read_timeout = 3600 # an hour
84
+
85
+ request = Net::HTTP::Get.new(uri.request_uri, {'Cookie' => cookies, 'Content-Type' => 'application/json'})
86
+
87
+ https.request(request)
88
+ end
89
+
90
+ def self.domains(cookies)
91
+ uri = URI.parse(url + Configs::Bazaar::V1::DOMAIN_LIST)
92
+
93
+ https = Net::HTTP.new(uri.host, uri.port)
94
+ https.use_ssl = true
95
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
96
+ https.read_timeout = 3600 # an hour
97
+
98
+ request = Net::HTTP::Get.new(uri.request_uri, {'Cookie' => cookies, 'Content-Type' => 'application/json'})
99
+
100
+ https.request(request)
101
+ end
102
+
103
+ # List of environments
104
+ def self.list(cookies)
105
+ uri = URI.parse(url + Configs::Bazaar::V1::ENVIRONMENTS)
106
+ https = Net::HTTP.new(uri.host, uri.port)
107
+ https.use_ssl = true
108
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
109
+ https.read_timeout = 3600 # an hour
110
+
111
+ request = Net::HTTP::Get.new(uri.request_uri, {'Cookie' => cookies})
112
+ https.request(request)
113
+ end
114
+
115
+ # Reserve domain
116
+ def self.reserve(cookies, domain)
117
+ uri = URI.parse(url + Configs::Bazaar::V1::DOMAIN_RESERVE.gsub('{DOMAIN}', domain))
118
+ https = Net::HTTP.new(uri.host, uri.port)
119
+ https.use_ssl = true
120
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
121
+ https.read_timeout = 3600 # an hour
122
+
123
+ request = Net::HTTP::Put.new(uri.request_uri, {'Cookie' => cookies})
124
+ https.request(request)
125
+ end
126
+
127
+ def self.url
128
+ env = SubutaiConfig.get(:SUBUTAI_ENV)
129
+ env = env.to_s
130
+
131
+ if env == VagrantSubutai::Configs::Environment::PROD
132
+ return VagrantSubutai::Configs::Bazaar::BASE_PROD
133
+ elsif env == VagrantSubutai::Configs::Environment::MASTER
134
+ return VagrantSubutai::Configs::Bazaar::BASE_MASTER
135
+ elsif env == VagrantSubutai::Configs::Environment::DEV
136
+ return VagrantSubutai::Configs::Bazaar::BASE_DEV
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,40 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'json'
4
+ require_relative '../../vagrant-subutai'
5
+
6
+ module VagrantSubutai
7
+ module Rest
8
+ class Gorjun
9
+ def self.template_id(name, owner)
10
+ uri = URI.parse("#{url}?name=#{name}&owner=#{owner}")
11
+ https = Net::HTTP.new(uri.host, uri.port)
12
+ https.use_ssl = true
13
+
14
+ request = Net::HTTP::Get.new(uri.request_uri)
15
+ response = https.request(request)
16
+
17
+ case response
18
+ when Net::HTTPOK
19
+ response = JSON.parse(response.body)
20
+ response[0]['id']
21
+ else
22
+ Put.error "Try again! #{response.body} template name #{name}, owner #{owner}"
23
+ end
24
+ end
25
+
26
+ def self.url
27
+ env = SubutaiConfig.get(:SUBUTAI_ENV)
28
+ env = env.to_s
29
+
30
+ if env == VagrantSubutai::Configs::Environment::PROD
31
+ return VagrantSubutai::Configs::Gorjun::INFO_PROD
32
+ elsif env == VagrantSubutai::Configs::Environment::MASTER
33
+ return VagrantSubutai::Configs::Gorjun::INFO_MASTER
34
+ elsif env == VagrantSubutai::Configs::Environment::DEV
35
+ return VagrantSubutai::Configs::Gorjun::INFO_DEV
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end