Class: Azure::Roles

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AzureUtility

#error_from_response_xml, #xml_content

Constructor Details

#initialize(connection) ⇒ Roles

Returns a new instance of Roles.



26
27
28
29
# File 'lib/azure/service_management/role.rb', line 26

def initialize(connection)
  @connection = connection
  @roles = nil
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



25
26
27
# File 'lib/azure/service_management/role.rb', line 25

def connection
  @connection
end

#rolesObject

Returns the value of attribute roles.



25
26
27
# File 'lib/azure/service_management/role.rb', line 25

def roles
  @roles
end

Instance Method Details

#allObject

do not use this unless you want a list of all roles(vms) in your subscription



32
33
34
35
36
37
38
39
40
# File 'lib/azure/service_management/role.rb', line 32

def all
  @roles = []
  @connection.deploys.all.each do |deploy|
    deploy.roles.each do |role|
      @roles << role
    end
  end
  @roles
end

#alone_on_hostedservice(found_role) ⇒ Object



68
69
70
71
72
73
# File 'lib/azure/service_management/role.rb', line 68

def alone_on_hostedservice(found_role)
  roles = find_roles_within_hostedservice(found_role.hostedservicename)
  return false if roles && roles.length > 1

  true
end

#delete(params) ⇒ Object



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

def delete(params)
  role = find(params[:name])
  unless role.nil?
    roleXML = nil
    roleXML = @connection.query_azure("hostedservices/#{role.hostedservicename}", "get", "", "embed-detail=true")
    osdisk = roleXML.css(roleXML, "OSVirtualHardDisk")
    disk_name = xml_content(osdisk, "DiskName")
     = xml_content(osdisk, "MediaLink").gsub("http://", "").gsub(/.blob(.*)$/, "")

    if !params[:preserve_azure_os_disk] && !params[:preserve_azure_vhd] && !params[:wait]
      # default compmedia = true. So, it deletes role and associated resources
      check_and_delete_role_and_resources(params, role)
    else
      # compmedia = false. So, it deletes only role and not associated resources
      check_and_delete_role_and_resources(params, role, compmedia = false)
      check_and_delete_disks(params, disk_name)
      check_and_delete_service(params)
    end
    check_and_delete_storage(params, disk_name, )
  end
end

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/azure/service_management/role.rb', line 75

def exists?(name)
  find(name) != nil
end

#find(role_name, params = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/azure/service_management/role.rb', line 54

def find(role_name, params = nil)
  if params && params[:azure_dns_name]
    return find_in_hosted_service(role_name, params[:azure_dns_name])
  end

  all if @roles.nil?

  # TODO: - optimize this lookup
  @roles.each do |role|
    return role if role.name == role_name
  end
  nil
end

#find_in_hosted_service(role_name, hostedservicename) ⇒ Object



47
48
49
50
51
52
# File 'lib/azure/service_management/role.rb', line 47

def find_in_hosted_service(role_name, hostedservicename)
  host = @connection.hosts.find(hostedservicename)
  return nil if host.nil?

  host.find_role(role_name)
end

#find_roles_within_hostedservice(hostedservicename) ⇒ Object



42
43
44
45
# File 'lib/azure/service_management/role.rb', line 42

def find_roles_within_hostedservice(hostedservicename)
  host = @connection.hosts.find(hostedservicename)
  host ? host.roles : nil # nil says invalid hosted service
end

#update(name, params) ⇒ Object



171
172
173
174
175
# File 'lib/azure/service_management/role.rb', line 171

def update(name, params)
  role = Role.new(@connection)
  roleExtensionXml = role.setup_extension(params)
  role.update(name, params, roleExtensionXml)
end