Class: DPL::Provider::CloudControl

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/cloudcontrol.rb

Direct Known Subclasses

ExoScale

Instance Attribute Summary collapse

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #cleanup, #commit_msg, context, #create_key, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #log, #needs_key?, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn

Constructor Details

#initialize(context, options) ⇒ CloudControl

Returns a new instance of CloudControl.



11
12
13
14
15
16
17
18
# File 'lib/dpl/provider/cloudcontrol.rb', line 11

def initialize(context, options)
  super
  option(:email) && option(:password) && option(:deployment)
  @app_name, @dep_name = options[:deployment].split('/')

  @http = Net::HTTP.new('api.cloudcontrol.com', 443)
  @http.use_ssl = true
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



8
9
10
# File 'lib/dpl/provider/cloudcontrol.rb', line 8

def app_name
  @app_name
end

#dep_nameObject

Returns the value of attribute dep_name.



9
10
11
# File 'lib/dpl/provider/cloudcontrol.rb', line 9

def dep_name
  @dep_name
end

Instance Method Details

#check_appObject



24
25
26
27
28
# File 'lib/dpl/provider/cloudcontrol.rb', line 24

def check_app
  response = api_call('GET', "/app/#{ app_name }/deployment/#{ dep_name }")
  error('application check failed') if response.code != '200'
  @repository = JSON.parse(response.body)["branch"]
end

#check_authObject



20
21
22
# File 'lib/dpl/provider/cloudcontrol.rb', line 20

def check_auth
  headers_with_token
end

#push_appObject



43
44
45
46
47
# File 'lib/dpl/provider/cloudcontrol.rb', line 43

def push_app
  branch = (dep_name == 'default') ? 'master' : dep_name
  context.shell "git push #{ @repository } HEAD:#{ branch } -f"
  deploy_app
end

#remove_keyObject



38
39
40
41
# File 'lib/dpl/provider/cloudcontrol.rb', line 38

def remove_key
  response = api_call('DELETE', "/user/#{ user['username']}/key/#{ @ssh_key_id }")
  error('key removal failed') if response.code != '204'
end

#setup_key(file) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/dpl/provider/cloudcontrol.rb', line 30

def setup_key(file)
  data = { 'key' => File.read(file).chomp }
  response = api_call('POST', "/user/#{ user['username'] }/key", JSON.dump(data))
  error('adding key failed') if response.code != '200'
  key = JSON.parse response.body
  @ssh_key_id = key['key_id']
end