Class: Azure::Deploys

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/deploy.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Deploys

Returns a new instance of Deploys.



21
22
23
# File 'lib/azure/deploy.rb', line 21

def initialize(connection)
  @connection=connection
end

Instance Method Details

#allObject



45
46
47
# File 'lib/azure/deploy.rb', line 45

def all
  self.load
end

#create(params) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/azure/deploy.rb', line 60

def create(params)
  if params[:azure_connect_to_existing_dns]
    unless @connection.hosts.exists?(params[:azure_dns_name])
      Chef::Log.fatal 'The specified Azure DNS Name does not exist.'
      exit 1
    end
  else
    ret_val = @connection.hosts.create(params)
    if ret_val.css('Error Code').length > 0
      Chef::Log.fatal 'Unable to create DNS:' + ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
      exit 1
    end
  end
  unless @connection.storageaccounts.exists?(params[:azure_storage_account])
    @connection.storageaccounts.create(params)
  end
  if params[:identity_file]
    params[:fingerprint] = @connection.certificates.create(params)
  end
  params['deploy_name'] = get_deploy_name_for_hostedservice(params[:azure_dns_name])

  if params['deploy_name'] != nil
    role = Role.new(@connection)
    roleXML = role.setup(params)
    ret_val = role.create(params, roleXML)
  else
    params['deploy_name'] = params[:azure_dns_name]
    deploy = Deploy.new(@connection)
    deployXML = deploy.setup(params)
    ret_val = deploy.create(params, deployXML)
  end
  if ret_val.css('Error Code').length > 0
      Chef::Log.fatal 'Unable to create role:' + ret_val.at_css('Error Code').content + ' : ' + ret_val.at_css('Error Message').content
      exit 1
  end
  @connection.roles.find_in_hosted_service(params[:azure_vm_name], params[:azure_dns_name])
end

#delete(rolename) ⇒ Object



97
98
# File 'lib/azure/deploy.rb', line 97

def delete(rolename)
end

#get_deploy_name_for_hostedservice(hostedservicename) ⇒ Object

TODO - Current knife-azure plug-in seems to have assumption that single hostedservice will always have one deployment (production). see Deploy#retrieve below



51
52
53
54
55
56
57
58
# File 'lib/azure/deploy.rb', line 51

def get_deploy_name_for_hostedservice(hostedservicename)
  host = @connection.hosts.find(hostedservicename)
  if host && host.deploys.length > 0
    host.deploys[0].name
  else
    nil
  end
end

#load(force_load = false) ⇒ Object

force_load should be true when there is something in local cache and we want to reload first call is always load.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/azure/deploy.rb', line 26

def load(force_load = false)
  if not @deploys || force_load
    @deploys = begin
      deploys = Array.new
      hosts = @connection.hosts.all
      hosts.each do |host|
        deploy = Deploy.new(@connection)
        deploy.retrieve(host.name)
        if deploy.name
          host.add_deploy(deploy)
          deploys << deploy
        end
      end
      deploys
    end
  end
  @deploys
end