Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #143 from Azure/release-0.6.4
Browse files Browse the repository at this point in the history
Release 0.6.4
  • Loading branch information
guangyang committed May 7, 2014
2 parents 4e7c485 + 293780c commit 9d5f660
Show file tree
Hide file tree
Showing 25 changed files with 529 additions and 302 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2014.05.06 - version 0.6.4
* Upgraded Service Management Versioning to 2014-04-01
* Created separate API for add role
* Logical Unit Number(lun) is optional argument in API add_data_disk
* Cloud service should delete only if there are no other VMs/Deployments in the cloud service
* Added more sizes(Basic_A0, Basic_A1, Basic_A2, Basic_A3, Basic_A4) options for Virtual Machine and Cloud Service.

2014.03.28 - version 0.6.3
* Added get_cloud_service_properties method, which returns all cloud service properties (embed-detail=true), including info about all VMs
* Added winrm_http_port and winrm_https_port to get_virtual_machine method to allow the users to configure custom ports for winrm-http and winrm-https
Expand Down
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ virtual_machine_service.start_virtual_machine('vm_name', 'cloud_service_name')
virtual_machine_service.restart_virtual_machine('vm_name', 'cloud_service_name')
#API for add disk to Virtual Machine
lun = 1 #Valid LUN values are 0 through 15.
options = {
:disk_label => 'disk-label',
:disk_size => 100, #In GB
:import => false
:import => false,
:disk_name => 'Disk name' #Required when import is true
}
virtual_machine_service.add_data_disk('vm_name', 'cloud_service_name', lun, options)
virtual_machine_service.add_data_disk('vm_name', 'cloud_service_name', options)
#API to add/update Virtual Machine endpoints
endpoint1 = {
Expand Down Expand Up @@ -422,19 +422,35 @@ options = {
:private_key_file => 'c:/private_key.key', #required for ssh or winrm(https) certificate.
:certificate_file => 'c:/certificate.pem', #required for ssh or winrm(https) certificate.
:ssh_port => 2222,
:vm_size => 'Small', #valid choices are (ExtraSmall, Small, Medium, Large, ExtraLarge, A6, A7)
:vm_size => 'Small', #valid choices are (ExtraSmall Small Medium Large ExtraLarge A5 A6 A7 Basic_A0 Basic_A1 Basic_A2 Basic_A3 Basic_A4)
:affinity_group_name => 'affinity1',
:virtual_network_name => 'xplattestvnet',
:subnet_name => 'subnet1',
:availability_set_name => 'availabiltyset1'
}
virtual_machine_service.create_virtual_machine(params,options,add_role=false)
# Here add_role is used as a flag to create multiple roles under the same cloud service. This parameter is false
# by default. Atleast a single deployment should be created under a hosted service prior to setting this flag.
virtual_machine_service.create_virtual_machine(params,options)
#API usage to add new roles under cloud service creating VM
virtual_machine_service.create_virtual_machine(params,options,add_role=true)
#API add_role create multiple roles under the same cloud service. Atleast a single deployment should be created under a hosted service.
params = {
:vm_name => 'vm_name',
:cloud_service_name => 'cloud_service_name',
:vm_user => 'azureuser',
:image => 'a699494373c04fc0bc8f2bb1389d6106__Win2K8R2SP1-Datacenter-201305.01-en.us-127GB.vhd',
:password => 'ComplexPassword',
}
options = {
:storage_account_name => 'storage_suse',
:winrm_transport => ['https','http'], #Currently http is supported. To enable https, set the transport protocol to https, simply rdp to the VM once VM is in ready state, export the certificate ( CN name would be the deployment name) from the certstore of the VM and install to your local machine and communicate WinRM via https.
:tcp_endpoints => '80,3389:3390',
:private_key_file => 'c:/private_key.key', #required for ssh or winrm(https) certificate.
:certificate_file => 'c:/certificate.pem', #required for ssh or winrm(https) certificate.
:winrm_https_port => 5999,
:winrm_http_port => 6999, #Used to open different powershell port
:vm_size => 'Small', #valid choices are (ExtraSmall Small Medium Large ExtraLarge A5 A6 A7 Basic_A0 Basic_A1 Basic_A2 Basic_A3 Basic_A4)
:availability_set_name => 'availabiltyset'
}
virtual_machine_service.add_role(params, options)
#Get a list of available virtual machine images
virtual_machine_image_service = Azure::VirtualMachineImageManagementService.new
Expand Down
2 changes: 1 addition & 1 deletion lib/azure/base_management/management_http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(method, path, body = nil)
@warn = false
content_length = body ? body.bytesize.to_s : '0'
@headers = {
'x-ms-version' => '2013-06-01',
'x-ms-version' => '2014-04-01',
'Content-Type' => 'application/xml',
'Content-Length' => content_length
}
Expand Down
2 changes: 1 addition & 1 deletion lib/azure/cloud_service_management/cloud_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
module Azure
module CloudServiceManagement
class CloudService

def initialize
yield self if block_given?
end
Expand All @@ -33,6 +32,7 @@ def initialize
attr_accessor :extended_properties
attr_accessor :default_winrm_certificate_thumbprint
attr_accessor :virtual_machines
attr_accessor :deployment_name
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
module Azure
module CloudServiceManagement
class CloudServiceManagementService < BaseManagementService

def initialize
super()
end
Expand Down Expand Up @@ -48,12 +47,12 @@ def initialize
#
# Returns None
def create_cloud_service(name, options = {})
Loggerx.error_with_exit "Cloud service name is not valid " unless name
Loggerx.error_with_exit 'Cloud service name is not valid ' unless name
if get_cloud_service(name)
Loggerx.warn "Cloud service #{name} already exists. Skipped..."
else
Loggerx.info "Creating cloud service #{name}."
request_path = "/services/hostedservices"
request_path = '/services/hostedservices'
body = Serialization.cloud_services_to_xml(name, options)
request = ManagementHttpRequest.new(:post, request_path, body)
request.call
Expand All @@ -64,7 +63,7 @@ def create_cloud_service(name, options = {})
#
# Returns an array of Azure::CloudServiceManagement::CloudService objects
def list_cloud_services
request_path = "/services/hostedservices"
request_path = '/services/hostedservices'
request = ManagementHttpRequest.new(:get, request_path, nil)
response = request.call
Serialization.cloud_services_from_xml(response)
Expand Down Expand Up @@ -95,7 +94,7 @@ def get_cloud_service_properties(name)
request_path = "/services/hostedservices/#{name}?embed-detail=true"
request = ManagementHttpRequest.new(:get, request_path)
response = request.call
Serialization.cloud_services_from_xml(response)
Serialization.cloud_services_from_xml(response).first
end

# Public: Deletes the specified cloud service of given subscription id from Windows Azure.
Expand All @@ -106,7 +105,7 @@ def get_cloud_service_properties(name)
#
# Returns: None
def delete_cloud_service(cloud_service_name)
request_path= "/services/hostedservices/#{cloud_service_name}"
request_path = "/services/hostedservices/#{cloud_service_name}"
request = ManagementHttpRequest.new(:delete, request_path)
Loggerx.info "Deleting cloud service #{cloud_service_name}. \n"
request.call
Expand All @@ -122,21 +121,20 @@ def delete_cloud_service(cloud_service_name)
#
# Returns NONE
def delete_cloud_service_deployment(cloud_service_name)
request_path= "/services/hostedservices/#{cloud_service_name}/deploymentslots/production"
request_path = "/services/hostedservices/#{cloud_service_name}/deploymentslots/production"
request = ManagementHttpRequest.new(:delete, request_path)
Loggerx.info "Deleting deployment of cloud service \"#{cloud_service_name}\" ..."
request.call
end

def upload_certificate(cloud_service_name, ssh)
data = export_der(ssh[:cert], ssh[:key])
request_path= "/services/hostedservices/#{cloud_service_name}/certificates"
request_path = "/services/hostedservices/#{cloud_service_name}/certificates"
body = Serialization.add_certificate_to_xml(data)
Loggerx.info "Uploading certificate to cloud service #{cloud_service_name}..."
request = ManagementHttpRequest.new(:post, request_path, body)
request.call
end

end
end
end
end
17 changes: 9 additions & 8 deletions lib/azure/cloud_service_management/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ def self.cloud_services_from_xml(cloud_xml)

cloud.label = Base64.decode64(xml_content(props_xml, 'Label'))
cloud.description = xml_content(props_xml, 'Description')
cloud.location = xml_content(props_xml, 'Location')
cloud.affinity_group = xml_content(props_xml, 'AffinityGroup')
location = xml_content(props_xml, 'Location')
cloud.location = location unless location.empty?
affinity_group = xml_content(props_xml, 'AffinityGroup')
cloud.affinity_group = affinity_group unless affinity_group
cloud.status = xml_content(props_xml, 'Status')
cloud.date_created = xml_content(props_xml, 'DateCreated')
cloud.date_modified = xml_content(props_xml, 'DateLastModified')
Expand All @@ -82,16 +84,16 @@ def self.cloud_services_from_xml(cloud_xml)
cloud.default_winrm_certificate_thumbprint = xml_content(
cloud_service_xml, 'DefaultWinRMCertificateThumbprint'
)

deployment_xml = cloud_services_xml.css('Deployments Deployment')
cloud.deployment_name = xml_content(deployment_xml, 'Name')
vms_in_deployment = {}

cloud_service_xml.css('Deployments').each do |deployxml|
deployment_name = xml_content(deployxml, 'Deployment Name')
vms = Azure::VirtualMachineManagement::Serialization.virtual_machines_from_xml(
deployxml, cloud.name
)

vms_in_deployment[deployment_name.to_sym] = vms
vms_in_deployment[deployment_name.to_sym] = vms if vms
end

cloud.virtual_machines = vms_in_deployment
Expand All @@ -102,15 +104,14 @@ def self.cloud_services_from_xml(cloud_xml)

def self.add_certificate_to_xml(data)
builder = Nokogiri::XML::Builder.new do |xml|
xml.CertificateFile('xmlns'=>'http://schemas.microsoft.com/windowsazure') {
xml.CertificateFile('xmlns' => 'http://schemas.microsoft.com/windowsazure') do
xml.Data data
xml.CertificateFormat 'pfx'
xml.Password nil
}
end
end
builder.doc.to_xml
end

end
end
end
4 changes: 2 additions & 2 deletions lib/azure/storage_management/storage_management_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def get_storage_account(name)
end

# Public: Gets the properties of the storage account specified.
#
#
# ==== Attributes
#
# * +name+ - String. The name of the storage account. Required.
#
# See http://msdn.microsoft.com/en-us/library/windowsazure/ee460802.aspx
#
#
# Returns the storage account
def get_storage_account_properties(name)
request_path = "/services/storageservices/#{name}"
Expand Down
2 changes: 1 addition & 1 deletion lib/azure/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Azure
class Version
MAJOR = 0 unless defined? MAJOR
MINOR = 6 unless defined? MINOR
UPDATE = 3 unless defined? UPDATE
UPDATE = 4 unless defined? UPDATE
PRE = nil unless defined? PRE

class << self
Expand Down
10 changes: 4 additions & 6 deletions lib/azure/virtual_machine_image_management/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
module Azure
module VirtualMachineImageManagement
module Serialization

def self.virtual_machine_images_from_xml(imageXML)
os_images = Array.new
os_images = []
virtual_machine_images = imageXML.css('Images OSImage')
virtual_machine_images.each do |image_node|
image = VirtualMachineImage.new
Expand All @@ -34,20 +33,19 @@ def self.virtual_machine_images_from_xml(imageXML)
end

def self.disks_from_xml(diskXML)
os_disks = Array.new
os_disks = []
disks = diskXML.css('Disks Disk')
disks.each do |disk_node|
disk = VirtualMachineDisk.new
disk.name = xml_content(disk_node, 'Name')
disk.os_type = xml_content(disk_node, 'OS')
disk.attached = !xml_content(disk_node,'AttachedTo').empty?
disk.attached = !xml_content(disk_node, 'AttachedTo').empty?
disk.image = xml_content(disk_node, 'SourceImageName')
disk.size = xml_content(disk_node, 'LogicalDiskSizeInGB')
os_disks << disk
end
os_disks
end

end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
module Azure
module VirtualMachineImageManagement
class VirtualMachineDisk

def initialize
yield self if block_given?
end

attr_accessor :name, :attached, :os_type, :image, :size

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
module Azure
module VirtualMachineImageManagement
class VirtualMachineImage

def initialize
yield self if block_given?
end

attr_accessor :os_type, :name, :category, :locations

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
require "azure/virtual_machine_image_management/serialization"
require 'azure/virtual_machine_image_management/serialization'

module Azure
module VirtualMachineImageManagement
class VirtualMachineImageManagementService < BaseManagementService

def initialize
super()
end
Expand All @@ -26,16 +25,14 @@ def initialize
#
# Returns an array of Azure::VirtualMachineImageManagementService objects
def list_virtual_machine_images
request_path = "/services/images"
request_path = '/services/images'
request = ManagementHttpRequest.new(:get, request_path, nil)
response = request.call
Serialization.virtual_machine_images_from_xml(response)
end

end

class VirtualMachineDiskManagementService < BaseManagementService

def initialize
super()
end
Expand All @@ -44,14 +41,14 @@ def initialize
#
# Returns an array of Azure::VirtualMachineDiskManagementService objects
def list_virtual_machine_disks
request_path = "/services/disks"
request_path = '/services/disks'
request = ManagementHttpRequest.new(:get, request_path, nil)
response = request.call
Serialization.disks_from_xml(response)
end

def get_virtual_machine_disk(disk_name)
disk = list_virtual_machine_disks.select {|x| x.name == disk_name}
disk = list_virtual_machine_disks.select { |x| x.name == disk_name }
disk.first
end

Expand All @@ -64,8 +61,6 @@ def delete_virtual_machine_disk(disk_name)
request = ManagementHttpRequest.new(:delete, path)
request.call
end

end
end
end

Loading

0 comments on commit 9d5f660

Please sign in to comment.