1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

Feature #2989: Initial commit MS Azure drivers

This commit is contained in:
Tino Vazquez 2014-06-19 17:03:18 +02:00
parent d40e1395c5
commit e269f72bc7
24 changed files with 1167 additions and 1 deletions

View File

@ -250,12 +250,14 @@ VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/im/xen4-probes.d \
$VAR_LOCATION/remotes/im/vmware.d \
$VAR_LOCATION/remotes/im/ec2.d \
$VAR_LOCATION/remotes/im/az.d \
$VAR_LOCATION/remotes/vmm \
$VAR_LOCATION/remotes/vmm/kvm \
$VAR_LOCATION/remotes/vmm/xen3 \
$VAR_LOCATION/remotes/vmm/xen4 \
$VAR_LOCATION/remotes/vmm/vmware \
$VAR_LOCATION/remotes/vmm/ec2 \
$VAR_LOCATION/remotes/vmm/az \
$VAR_LOCATION/remotes/vnm \
$VAR_LOCATION/remotes/vnm/802.1Q \
$VAR_LOCATION/remotes/vnm/dummy \
@ -410,6 +412,7 @@ INSTALL_FILES=(
IM_PROBES_XEN4_PROBES_FILES:$VAR_LOCATION/remotes/im/xen4-probes.d
IM_PROBES_VMWARE_FILES:$VAR_LOCATION/remotes/im/vmware.d
IM_PROBES_EC2_FILES:$VAR_LOCATION/remotes/im/ec2.d
IM_PROBES_AZ_FILES:$VAR_LOCATION/remotes/im/az.d
IM_PROBES_VERSION:$VAR_LOCATION/remotes
AUTH_SSH_FILES:$VAR_LOCATION/remotes/auth/ssh
AUTH_X509_FILES:$VAR_LOCATION/remotes/auth/x509
@ -423,6 +426,7 @@ INSTALL_FILES=(
VMM_EXEC_XEN4_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen4
VMM_EXEC_VMWARE_SCRIPTS:$VAR_LOCATION/remotes/vmm/vmware
VMM_EXEC_EC2_SCRIPTS:$VAR_LOCATION/remotes/vmm/ec2
VMM_EXEC_AZ_SCRIPTS:$VAR_LOCATION/remotes/vmm/az
TM_FILES:$VAR_LOCATION/remotes/tm
TM_SHARED_FILES:$VAR_LOCATION/remotes/tm/shared
TM_FS_LVM_FILES:$VAR_LOCATION/remotes/tm/fs_lvm
@ -572,6 +576,7 @@ INSTALL_ETC_FILES=(
ETC_FILES:$ETC_LOCATION
VMWARE_ETC_FILES:$ETC_LOCATION
EC2_ETC_FILES:$ETC_LOCATION
AZ_ETC_FILES:$ETC_LOCATION
VMM_EXEC_ETC_FILES:$ETC_LOCATION/vmm_exec
HM_ETC_FILES:$ETC_LOCATION/hm
AUTH_ETC_FILES:$ETC_LOCATION/auth
@ -784,6 +789,28 @@ VMM_EXEC_EC2_SCRIPTS="src/vmm_mad/remotes/ec2/cancel \
src/vmm_mad/remotes/ec2/shutdown \
src/vmm_mad/remotes/ec2/ec2_driver.rb"
#------------------------------------------------------------------------------
# VMM Driver Azure scripts, to be installed under $REMOTES_LOCATION/vmm/az
#------------------------------------------------------------------------------
VMM_EXEC_AZ_SCRIPTS="src/vmm_mad/remotes/az/cancel \
src/vmm_mad/remotes/az/attach_disk \
src/vmm_mad/remotes/az/detach_disk \
src/vmm_mad/remotes/az/attach_nic \
src/vmm_mad/remotes/az/detach_nic \
src/vmm_mad/remotes/az/snapshot_create \
src/vmm_mad/remotes/az/snapshot_revert \
src/vmm_mad/remotes/az/snapshot_delete \
src/vmm_mad/remotes/az/deploy \
src/vmm_mad/remotes/az/migrate \
src/vmm_mad/remotes/az/restore \
src/vmm_mad/remotes/az/reboot \
src/vmm_mad/remotes/az/reset \
src/vmm_mad/remotes/az/save \
src/vmm_mad/remotes/az/poll \
src/vmm_mad/remotes/az/shutdown \
src/vmm_mad/remotes/az/az_driver.rb"
#-------------------------------------------------------------------------------
# Information Manager Probes, to be installed under $REMOTES_LOCATION/im
#-------------------------------------------------------------------------------
@ -831,6 +858,8 @@ IM_PROBES_VMWARE_FILES="src/im_mad/remotes/vmware.d/vmware.rb"
IM_PROBES_EC2_FILES="src/im_mad/remotes/ec2.d/poll"
IM_PROBES_AZ_FILES="src/im_mad/remotes/az.d/poll"
IM_PROBES_VERSION="src/im_mad/remotes/VERSION"
#-------------------------------------------------------------------------------
@ -1103,6 +1132,9 @@ VMWARE_ETC_FILES="src/vmm_mad/remotes/vmware/vmwarerc"
EC2_ETC_FILES="src/vmm_mad/remotes/ec2/ec2_driver.conf \
src/vmm_mad/remotes/ec2/ec2_driver.default"
AZ_ETC_FILES="src/vmm_mad/remotes/az/az_driver.conf \
src/vmm_mad/remotes/az/az_driver.default"
#-------------------------------------------------------------------------------
# Virtualization drivers config. files, to be installed under $ETC_LOCATION
# - ssh, $ETC_LOCATION/vmm_exec

View File

@ -319,6 +319,15 @@ IM_MAD = [
# arguments = "-c -t 1 -r 0 ec2" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Azure Information Driver Manager Configuration
#-------------------------------------------------------------------------------
#IM_MAD = [
# name = "az",
# executable = "one_im_sh",
# arguments = "-c -t 1 -r 0 az" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Information Driver Manager Configuration
#-------------------------------------------------------------------------------
@ -419,6 +428,18 @@ VM_MAD = [
# type = "xml" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Azure Virtualization Driver Manager Configuration
# -r number of retries when monitoring a host
# -t number of threads, i.e. number of actions performed at the same time
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "az",
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 az",
# type = "xml" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Dummy Virtualization Driver Configuration
#-------------------------------------------------------------------------------

View File

@ -20,7 +20,7 @@ end
GROUPS={
:quota => [SQLITE, 'sequel'],
:sunstone => ['json', 'rack', 'sinatra', 'thin', SQLITE],
:cloud => %w{amazon-ec2 rack sinatra thin uuidtools curb json},
:cloud => %w{amazon-ec2 rack sinatra thin uuidtools curb json azure},
:auth_ldap => 'net-ldap',
:vmware => %w{builder trollop},
:oneflow => %w{sinatra json treetop parse-cron},

27
src/im_mad/remotes/az.d/poll Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.join(File.dirname(__FILE__), '../../vmm/az')
require 'az_driver'
host = ARGV[-1]
az_drv = AzureDriver.new(host)
az_drv.monitor_all_vms

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

View File

@ -0,0 +1,126 @@
proxy_uri:
regions:
default:
region_name: "West Europe"
# pem_management_cert --> Absolute path to pem management certificate
# Info on creating certificates:
# http://azure.microsoft.com/en-us/documentation/articles/linux-use-ssh-key/
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small: 5
Medium: 1
Large: 0
west-europe:
region_name: "West Europe"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small: 5
Medium: 1
Large: 0
north-europe:
region_name: "North Europe"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
east-us:
region_name: "East US"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
southcentral-us:
region_name: "South Central US"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
west-us:
region_name: "West US"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
east-asia:
region_name: "East Asia"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
southeast-asia:
region_name: "Southeast Asia"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
japan-west:
region_name: "Japan West"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
brazil-south:
region_name: "Brazil South"
pem_management_cert:
subscription_id:
managament_endpoint:
capacity:
Small:
Medium:
Large:
instance_types:
ExtraSmall:
cpu: 0.1
memory: 0.75
Small:
cpu: 1
memory: 1.75
Medium:
cpu: 2
memory: 3.5
Large:
cpu: 4
memory: 7
ExtraLarge:
cpu: 8
memory: 14
A5:
cpu: 2
memory: 14
A6:
cpu: 4
memory: 28
A7:
cpu: 8
memory: 56
A8:
cpu: 8
memory: 56
A9:
cpu: 16
memory: 112

View File

@ -0,0 +1,55 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
<!--
Default configuration attributes for the Azure driver
(all domains will use these values as defaults)
Valid attributes are: INSTANCE_TYPE, IMAGE, VM_USER, VM_PASSWORD, LOCATION,
STORAGE_ACCOUNT, WIN_RM, CLOUD_SERVICE, TCP_ENDPOINTS, SSHPORT, AFFINITY_GROUP,
VIRTUAL_NETWORK_NAME, SUBNET and AVAILABILITY_SET
Use XML syntax to specify defaults, note elements are UPCASE
Example:
<TEMPLATE>
<AZURE>
<LOCATION>west-europe</LOCATION>
<INSTANCE_TYPE>Small</INSTANCE_TYPE>
<CLOUD_SERVICE>MyDefaultCloudService</CLOUD_SERVICE>
<IMAGE>0b11de9248dd4d87b18621318e037d37__RightImage-Ubuntu-12.04-x64-v13.4</IMAGE>
<VM_USER>MyUser</VM_USER>
<VM_PASSWORD>MyPassword</VM_PASSWORD>
<STORAGE_ACCOUNT>MyStorageAccountName</STORAGE_ACCOUNT>
<WIN_RM>http</WIN_RM>
<CLOUD_SERVICE>MyCloudServiceName</CLOUD_SERVICE>
<TCP_ENDPOINTS>80,3389:3390</TCP_ENDPOINTS>
<SSHPORT>2222</SSHPORT>
<AFFINITY_GROUP>MyAffinityGroup</AFFINITY_GROUP>
<VIRTUAL_NETWORK_NAME>MyVirtualNetwork</VIRTUAL_NETWORK_NAME>
<SUBNET>MySubNet<SUBNET>
<AVAILABILITY_SET>MyAvailabilitySetName<AVAILABILITY_SET>
</AZURE>
</TEMPLATE>
-->
<TEMPLATE>
<AZURE>
<LOCATION>west-europe</LOCATION>
<INSTANCE_TYPE>Small</INSTANCE_TYPE>
</AZURE>
</TEMPLATE>

View File

@ -0,0 +1,497 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
ONE_LOCATION = ENV["ONE_LOCATION"] if !defined?(ONE_LOCATION)
if !ONE_LOCATION
RUBY_LIB_LOCATION = "/usr/lib/one/ruby" if !defined?(RUBY_LIB_LOCATION)
ETC_LOCATION = "/etc/one/" if !defined?(ETC_LOCATION)
else
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby" if !defined?(RUBY_LIB_LOCATION)
ETC_LOCATION = ONE_LOCATION + "/etc/" if !defined?(ETC_LOCATION)
end
AZ_DRIVER_CONF = "#{ETC_LOCATION}/az_driver.conf"
AZ_DRIVER_DEFAULT = "#{ETC_LOCATION}/az_driver.default"
# Load Azure credentials and environment
require 'yaml'
require 'rubygems'
require 'azure'
require 'uri'
$: << RUBY_LIB_LOCATION
require 'CommandManager'
require 'scripts_common'
require 'rexml/document'
require 'VirtualMachineDriver'
# The main class for the Azure driver
class AzureDriver
ACTION = VirtualMachineDriver::ACTION
POLL_ATTRIBUTE = VirtualMachineDriver::POLL_ATTRIBUTE
VM_STATE = VirtualMachineDriver::VM_STATE
# Azure commands constants
AZ = {
:run => {
:cmd => :create_virtual_machine,
:args => {
"INSTANCE_TYPE" => {
:opt => 'vm_size'
},
"IMAGE" => {
:opt => 'image'
},
"VM_USER" => {
:opt => 'vm_user'
},
"VM_PASSWORD" => {
:opt => 'password'
},
"LOCATION" => {
:opt => 'location'
},
"STORAGE_ACCOUNT" => {
:opt => 'storage_account_name'
},
"WIN_RM" => {
:opt => 'winrm_transport',
:proc => lambda { |str| str.split(",") }
},
"CLOUD_SERVICE" => {
:opt => 'cloud_service_name'
},
"TCP_ENDPOINTS" => {
:opt => 'tcp_endpoints'
},
"SSHPORT" => {
:opt => 'ssh_port'
},
"AFFINITY_GROUP" => {
:opt => 'affinity_group_name'
},
"VIRTUAL_NETWORK_NAME" => {
:opt => 'virtual_network_name'
},
"SUBNET" => {
:opt => 'subnet_name'
},
"AVAILABILITY_SET" => {
:opt => 'availability_set_name'
}
}
},
:shutdown => {
:cmd => :shutdown_virtual_machine
},
:reboot => {
:cmd => :restart_virtual_machine
},
:stop => {
:cmd => :shutdown_virtual_machine
},
:start => {
:cmd => :start_virtual_machine
},
:delete => {
:cmd => :delete_virtual_machine
}
}
# Azure attributes that will be retrieved in a polling action
AZ_POLL_ATTRS = [
:availability_set_name,
:cloud_service_name,
:data_disks,
:deployment_name,
:disk_name,
:hostname,
:image,
:ipaddress,
:media_link,
:os_type,
:role_size,
:tcp_endpoints,
:udp_endpoints,
:virtual_network_name
]
# Azure constructor, loads credentials and endpoint
def initialize(host)
@host = host
public_cloud_az_conf = YAML::load(File.read(AZ_DRIVER_CONF))
@instance_types = public_cloud_az_conf['instance_types']
regions = public_cloud_az_conf['regions']
@region = regions[host] || regions["default"]
# Sanitize region data
if @region['pem_management_cert'].nil?
raise "pem_management_cert not defined for #{host}"
end
if @region['subscription_id'].nil?
raise "subscription_id not defined for #{host}"
end
# Set default endpoint if not declared
if @region['managment_endpoint'].nil?
@region['managment_endpoint']="https://management.core.windows.net"
end
Azure.configure do |config|
# Configure these 3 properties to use Storage
config.management_certificate = @region['pem_management_cert']
config.subscription_id = @region['subscription_id']
config.management_endpoint = @region['management_endpoint']
end
@azure_vms = Azure::VirtualMachineManagementService.new
end
# DEPLOY action
def deploy(id, host, xml_text)
az_info = get_deployment_info(host, xml_text)
load_default_template_values
if !az_value(az_info, 'IMAGE')
STDERR.puts("Cannot find IMAGE in deployment file")
exit(-1)
end
csn = az_value(az_info, 'CLOUD_SERVICE_NAME')
csn = "OpenNebulaDefaultCloudServiceName" if !csn
create_params = create_params(id,csn,az_info)
create_options = create_options(id,csn,az_info)
begin
instance = @azure_vms.create_virtual_machine(create_params,
create_options)
rescue => e
STDERR.puts(e.message)
exit(-1)
end
puts(create_params[:vm_name])
end
# Shutdown an Azure instance
def shutdown(deploy_id)
az_action(deploy_id, :shutdown)
az_action(deploy_id, :delete)
end
# Reboot an Azure instance
def reboot(deploy_id)
az_action(deploy_id, :reboot)
end
# Cancel an Azure instance
def cancel(deploy_id)
az_action(deploy_id, :delete)
end
# Stop an Azure instance
def save(deploy_id)
az_action(deploy_id, :shutdown)
end
# Cancel an Azure instance
def restore(deploy_id)
az_action(deploy_id, :start)
end
# Get info (IP, and state) for an Azure instance
def poll(id, deploy_id)
i = get_instance(deploy_id)
puts parse_poll(i)
end
# Get the info of all Aure instances. An Azure instance must have
# a name compliant with the "one-#####" format, where ##### are intengers
def monitor_all_vms
totalmemory = 0
totalcpu = 0
@region['capacity'].each { |name, size|
cpu, mem = instance_type_capacity(name)
totalmemory += mem * size.to_i
totalcpu += cpu * size.to_i
}
host_info = "HYPERVISOR=AZURE\n"
host_info << "PUBLIC_CLOUD=YES\n"
host_info << "PRIORITY=-1\n"
host_info << "TOTALMEMORY=#{totalmemory.round}\n"
host_info << "TOTALCPU=#{totalcpu}\n"
host_info << "HOSTNAME=\"#{@host}\"\n"
vms_info = "VM_POLL=YES\n"
usedcpu = 0
usedmemory = 0
begin
@azure_vms.list_virtual_machines.each do |vm|
poll_data=parse_poll(vm)
if vm.vm_name.start_with?('one-') and
vm.vm_name.match(/([^_]+)_(.+)/) and
vm.vm_name.match(/([^_]+)_(.+)/).size > 1
one_id = vm.vm_name.match(/([^_]+)_(.+)/)[1].split("-")[1]
end
vms_info << "VM=[\n"
vms_info << " ID=#{one_id || -1},\n"
vms_info << " DEPLOY_ID=#{vm.vm_name},\n"
vms_info << " POLL=\"#{poll_data}\" ]\n"
if one_id
cpu, mem = instance_type_capacity(vm.role_size)
usedcpu += cpu
usedmemory += mem
end
end
rescue => e
STDERR.puts(e.message)
exit(-1)
end
host_info << "USEDMEMORY=#{usedmemory.round}\n"
host_info << "USEDCPU=#{usedcpu.round}\n"
host_info << "FREEMEMORY=#{(totalmemory - usedmemory).round}\n"
host_info << "FREECPU=#{(totalcpu - usedcpu).round}\n"
puts host_info
puts vms_info
end
private
# Get the associated capacity of the instance_type as cpu (in 100 percent
# e.g. 800 for 8 cores) and memory (in KB)
def instance_type_capacity(name)
return 0, 0 if @instance_types[name].nil?
return @instance_types[name]['cpu'].to_i * 100 ,
@instance_types[name]['memory'].to_i * 1024 * 1024
end
# Get the Azure section of the template. If more than one Azure section
# the LOCATION element is used and matched with the host
def get_deployment_info(host, xml_text)
xml = REXML::Document.new xml_text
az = nil
all_az_elements = xml.root.get_elements("//USER_TEMPLATE/PUBLIC_CLOUD")
# First, let's see if we have an Azure location that matches
# our host name
all_az_elements.each { |element|
cloud_host = element.elements["LOCATION"]
type = element.elements["TYPE"].text
next if !type.downcase.eql? "azure"
if cloud_host and cloud_host.text.upcase.eql? host.upcase
az = element
end
}
if !az
# If we don't find an Azure location, and ONE just
# knows about one Azure location, let's use that
if all_az_elements.size == 1 and
all_az_elements[0].elements["TYPE"].text.downcase.eql? "azure"
az = all_az_elements[0]
else
STDERR.puts(
"Cannot find Azure element in VM template "<<
"or couldn't find any Azure location matching "<<
"one of the templates.")
exit(-1)
end
end
# If LOCATION not explicitly defined, try to get default, if not
# try to use hostname as datacenter
if !az.elements["LOCATION"]
location=REXML::Element.new("LOCATION")
if @defaults["LOCATION"]
location.text=@defaults["LOCATION"]
else
location.text=host
end
az.elements << location
end
az
end
# Retrive the vm information from the Azure instance
def parse_poll(instance)
info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \
"#{POLL_ATTRIBUTE[:usedcpu]}=0 " \
"#{POLL_ATTRIBUTE[:nettx]}=0 " \
"#{POLL_ATTRIBUTE[:netrx]}=0 "
state = ""
if !instance
state = VM_STATE[:deleted]
else
state = case instance.deployment_status
when "Running", "Starting"
VM_STATE[:active]
when "Suspended", "Stopping",
VM_STATE[:paused]
else
VM_STATE[:deleted]
end
end
info << "#{POLL_ATTRIBUTE[:state]}=#{state} "
AZ_POLL_ATTRS.map { |key|
value = instance.send(key)
if !value.nil? && !value.empty?
info << "AZ_#{key.to_s.upcase}=\"#{value.sub("\"","'")}\ "
end
}
info
end
def create_params(id,csn,az_info)
params = {
# Name will always be 'one-<id>_<cloud_service_name>'
:vm_name => "one-#{id}_#{csn}",
:vm_user => az_value(az_info, 'VM_USER'),
:image => az_value(az_info, 'IMAGE'),
:password => az_value(az_info, 'VM_PASSWORD'),
:location => az_value(az_info, 'LOCATION')
}
end
def create_options(id,csn,az_info)
options = {
:storage_account_name => az_value(az_info, 'STORAGE_ACCOUNT'),
:winrm_transport => az_value(az_info, 'WIN_RM'),
:cloud_service_name => csn,
:tcp_endpoints => az_value(az_info, 'TCP_ENDPOINTS'),
# TODO possibly taking the values from user template
# and create temp files
# :private_key_file => 'c:/private_key.key',
# :certificate_file => 'c:/certificate.pem',
:ssh_port => az_value(az_info, 'SSHPORT'),
:vm_size => az_value(az_info, 'INSTANCE_TYPE'),
:affinity_group_name => az_value(az_info, 'AFFINITY_GROUP'),
:virtual_network_name => az_value(az_info, 'VIRTUAL_NETWORK_NAME'),
:subnet_name => az_value(az_info, 'SUBNET'),
:availability_set_name => az_value(az_info, 'AVAILABILITY_SET')
}
end
# Execute an Azure command
# +deploy_id+: String, VM id in Azure
# +az_action+: Symbol, one of the keys of the Azure hash constant (i.e :run)
def az_action(deploy_id, az_action)
i = get_instance(deploy_id)
begin
i.send(AZ[az_action][:cmd])
rescue => e
STDERR.puts e.message
exit(-1)
end
end
# Returns the value of the xml specified by the name or the default
# one if it does not exist
# +xml+: REXML Document, containing Azure information
# +name+: String, xpath expression to retrieve the value
# +block+: Block, block to be applied to the value before returning it
def az_value(xml, name, &block)
value = value_from_xml(xml, name) || @defaults[name]
if block_given? && value
block.call(value)
else
value
end
end
def value_from_xml(xml, name)
if xml
element = xml.elements[name]
element.text.strip if element && element.text
end
end
# Load the default values that will be used to create a new instance, if
# not provided in the template. These values are defined in the AZ_CONF
# file
def load_default_template_values
@defaults = Hash.new
if File.exists?(AZ_DRIVER_DEFAULT)
fd = File.new(AZ_DRIVER_DEFAULT)
xml = REXML::Document.new fd
fd.close()
return if !xml || !xml.root
az = xml.root.elements["AZURE"]
return if !az
AZ.each {|action, hash|
if hash[:args]
hash[:args].each { |key, value|
@defaults[key] = value_from_xml(az, key)
}
end
}
end
end
# Retrive the instance from Azure
def get_instance(id)
begin
name_and_csn = id.match(/([^_]+)_(.+)/)
name = name_and_csn[1]
csn = name_and_csn[2]
instance = @azure_vms.get_virtual_machine(name,csn)
if instance.exists?
return instance
else
raise "Instance #{id} does not exist"
end
rescue => e
STDERR.puts e.message
exit(-1)
end
end
end

29
src/vmm_mad/remotes/az/cancel Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
deploy_id = ARGV[0]
host = ARGV[1]
az_drv = AzureDriver.new(host)
az_drv.cancel(deploy_id)

34
src/vmm_mad/remotes/az/deploy Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env ruby
# ---------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# ---------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
dfile = ARGV[0]
host = ARGV[1]
id = ARGV[2]
az_drv = AzureDriver.new(host)
text=File.read(dfile)
puts az_drv.deploy(id, host, text)
exit 0

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

20
src/vmm_mad/remotes/az/migrate Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

30
src/vmm_mad/remotes/az/poll Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
deploy_id = ARGV[0]
host = ARGV[1]
id = ARGV[2]
az_drv = AzureDriver.new(host)
az_drv.poll(id, deploy_id)

29
src/vmm_mad/remotes/az/reboot Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
deploy_id = ARGV[0]
host = ARGV[1]
az_drv = AzureDriver.new(host)
az_drv.reboot(deploy_id)

20
src/vmm_mad/remotes/az/reset Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

28
src/vmm_mad/remotes/az/restore Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
checkpoint_file = ARGV[0]
host = ARGV[1]
deploy_id = ARGV[2]
az_drv = AzureDriver.new(host)
az_drv.restore(deploy_id)

29
src/vmm_mad/remotes/az/save Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
deploy_id = ARGV[0]
file = ARGV[1]
host = ARGV[2]
az_drv = AzureDriver.new(host)
az_drv.save(deploy_id)

29
src/vmm_mad/remotes/az/shutdown Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2010-2014, C12G Labs S.L #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# -------------------------------------------------------------------------- #
$: << File.dirname(__FILE__)
require 'az_driver'
deploy_id = ARGV[0]
host = ARGV[1]
az_drv = AzureDriver.new(host)
az_drv.shutdown(deploy_id)

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2

View File

@ -0,0 +1,20 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
SCRIPT_NAME=$(basename $0)
echo "Action $SCRIPT_NAME not supported" 1>&2