Class: Azure::ServiceManagement::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AzureUtility

#error_from_response_xml, #xml_content

Constructor Details

#initialize(rest) ⇒ Connection

Returns a new instance of Connection.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/azure/service_management/connection.rb', line 37

def initialize(rest)
  @images = Images.new(self)
  @roles = Roles.new(self)
  @deploys = Deploys.new(self)
  @hosts = Hosts.new(self)
  @rest = rest
  @lbs = Loadbalancer.new(self)
  @vnets = Vnets.new(self)
  @ags = AGs.new(self)
  @storageaccounts = StorageAccounts.new(self)
  @certificates = Certificates.new(self)
  @disks = Disks.new(self)
end

Instance Attribute Details

#agsObject

Returns the value of attribute ags.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def ags
  @ags
end

#certificatesObject

Returns the value of attribute certificates.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def certificates
  @certificates
end

#deploysObject

Returns the value of attribute deploys.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def deploys
  @deploys
end

#disksObject

Returns the value of attribute disks.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def disks
  @disks
end

#hostsObject

Returns the value of attribute hosts.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def hosts
  @hosts
end

#imagesObject

Returns the value of attribute images.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def images
  @images
end

#lbsObject

Returns the value of attribute lbs.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def lbs
  @lbs
end

#restObject

Returns the value of attribute rest.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def rest
  @rest
end

#rolesObject

Returns the value of attribute roles.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def roles
  @roles
end

#storageaccountsObject

Returns the value of attribute storageaccounts.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def storageaccounts
  @storageaccounts
end

#vnetsObject

Returns the value of attribute vnets.



35
36
37
# File 'lib/azure/service_management/connection.rb', line 35

def vnets
  @vnets
end

Instance Method Details

#query_azure(service_name, verb = "get", body = "", params = "", wait = true, services = true, content_type = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/azure/service_management/connection.rb', line 51

def query_azure(service_name,
  verb = "get",
  body = "",
  params = "",
  wait = true,
  services = true,
  content_type = nil)
  Chef::Log.info "calling " + verb + " " + service_name + (wait ? " synchronously" : " asynchronously")
  Chef::Log.debug body unless body == ""
  response = @rest.query_azure(service_name, verb, body, params, services, content_type)
  if response.code.to_i == 200
    ret_val = Nokogiri::XML response.body
  elsif !wait && response.code.to_i == 202
    Chef::Log.debug "Request accepted in asynchronous mode"
    ret_val = Nokogiri::XML response.body
  elsif response.code.to_i >= 201 && response.code.to_i <= 299
    ret_val = wait_for_completion
  else
    if response.body
      ret_val = Nokogiri::XML response.body
      Chef::Log.debug ret_val.to_xml
      error_code, error_message = error_from_response_xml(ret_val)
      Chef::Log.debug error_code + " : " + error_message if error_code.length > 0
    else
      Chef::Log.warn "http error: " + response.code
    end
  end
  ret_val
end

#wait_for_completionObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/azure/service_management/connection.rb', line 81

def wait_for_completion
  status = "InProgress"
  Chef::Log.info "Waiting while status returns InProgress"
  while status == "InProgress"
    response = @rest.query_for_completion
    ret_val = Nokogiri::XML response.body
    status = xml_content(ret_val, "Status")
    if status == "InProgress"
      print "."
      sleep(0.5)
    elsif status == "Succeeded"
      Chef::Log.debug "not InProgress : " + ret_val.to_xml
    else
      error_code, error_message = error_from_response_xml(ret_val)
      Chef::Log.debug status + error_code + " : " + error_message if error_code.length > 0
    end
  end
  ret_val
end