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.



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

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

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



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

def connection
  @connection
end

#rolesObject

Returns the value of attribute roles.



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

def roles
  @roles
end

Instance Method Details

#allObject

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



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

def all
  @roles = Array.new
  @connection.deploys.all.each do |deploy|
    deploy.roles.each do |role|
      @roles << role
    end
  end
  @roles
end

#alone_on_hostedservice(found_role) ⇒ Object



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

def alone_on_hostedservice(found_role)
  roles = find_roles_within_hostedservice(found_role.hostedservicename)
  if roles && roles.length > 1
    return false
  end
  return 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])
  if 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



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

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|
    if(role.name == role_name)
      return role
    end
  end
  nil
end

#find_in_hosted_service(role_name, hostedservicename) ⇒ Object



45
46
47
48
49
# File 'lib/azure/service_management/role.rb', line 45

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



40
41
42
43
# File 'lib/azure/service_management/role.rb', line 40

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



169
170
171
172
173
# File 'lib/azure/service_management/role.rb', line 169

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