Class: Azure::Deploys

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

Instance Method Summary collapse

Methods included from AzureUtility

#error_from_response_xml, #xml_content

Constructor Details

#initialize(connection) ⇒ Deploys

Returns a new instance of Deploys.



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

def initialize(connection)
  @connection=connection
end

Instance Method Details

#allObject



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

def all
  self.load
end

#create(params) ⇒ Object



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
97
98
99
100
101
102
103
104
105
106
# File 'lib/azure/service_management/deploy.rb', line 61

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)
    error_code, error_message = error_from_response_xml(ret_val)
    if error_code.length > 0
      Chef::Log.fatal 'Unable to create DNS:' + error_code + ' : ' + error_message
      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
  if params[:cert_path]
    cert_data = File.read (params[:cert_path])
    @connection.certificates.add cert_data, params[:cert_password], 'pfx', params[:azure_dns_name]
  elsif(params[:winrm_transport] == "ssl")
    #TODO: generate certificates for ssl listener
  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
  error_code, error_message = error_from_response_xml(ret_val)
  if error_code.length > 0
    Chef::Log.debug(ret_val.to_s)
    raise Chef::Log.fatal 'Unable to create role:' + error_code + ' : ' + error_message
  end
  @connection.roles.find_in_hosted_service(params[:azure_vm_name], params[:azure_dns_name])
end

#delete(rolename) ⇒ Object



108
109
# File 'lib/azure/service_management/deploy.rb', line 108

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



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

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.



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

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

#queryDeploy(hostedservicename) ⇒ Object



111
112
113
114
115
# File 'lib/azure/service_management/deploy.rb', line 111

def queryDeploy(hostedservicename)
    deploy = Deploy.new(@connection)
    deploy.retrieve(hostedservicename)
    deploy
end