Class: Azure::Roles
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#roles ⇒ Object
Returns the value of attribute roles.
Instance Method Summary collapse
-
#all ⇒ Object
do not use this unless you want a list of all roles(vms) in your subscription.
- #alone_on_hostedservice(found_role) ⇒ Object
- #delete(name, params) ⇒ Object
- #exists?(name) ⇒ Boolean
- #find(role_name, params = nil) ⇒ Object
- #find_in_hosted_service(role_name, hostedservicename) ⇒ Object
- #find_roles_within_hostedservice(hostedservicename) ⇒ Object
-
#initialize(connection) ⇒ Roles
constructor
A new instance of Roles.
Methods included from AzureUtility
#error_from_response_xml, #xml_content
Constructor Details
#initialize(connection) ⇒ Roles
Returns a new instance of Roles.
23 24 25 26 |
# File 'lib/azure/role.rb', line 23 def initialize(connection) @connection = connection @roles = nil end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
22 23 24 |
# File 'lib/azure/role.rb', line 22 def connection @connection end |
#roles ⇒ Object
Returns the value of attribute roles.
22 23 24 |
# File 'lib/azure/role.rb', line 22 def roles @roles end |
Instance Method Details
#all ⇒ Object
do not use this unless you want a list of all roles(vms) in your subscription
28 29 30 31 32 33 34 35 36 |
# File 'lib/azure/role.rb', line 28 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
65 66 67 68 69 70 71 |
# File 'lib/azure/role.rb', line 65 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(name, params) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/azure/role.rb', line 77 def delete(name, params) role = find(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') storage_account_name = 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, storage_account_name) end end |
#exists?(name) ⇒ Boolean
73 74 75 |
# File 'lib/azure/role.rb', line 73 def exists?(name) find(name) != nil end |
#find(role_name, params = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/azure/role.rb', line 49 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
43 44 45 46 47 |
# File 'lib/azure/role.rb', line 43 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
38 39 40 41 |
# File 'lib/azure/role.rb', line 38 def find_roles_within_hostedservice(hostedservicename) host = @connection.hosts.find(hostedservicename) (host) ? host.roles : nil # nil says invalid hosted service end |