Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Azure VM retirement #5717

Merged
merged 2 commits into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def parse_instance(instance)
:uid_ems => uid,
:ems_ref => uid,
:name => instance.name,
:vendor => "Microsoft",
:vendor => "azure",
:raw_power_state => power_status(instance),
:operating_system => process_os(instance),
:flavor => series,
Expand Down Expand Up @@ -467,7 +467,7 @@ def parse_image(image)
:ems_ref => uid,
:name => uid.split(%r{Microsoft.Compute\/}i)[1].split('.').first,
:location => @ems.provider_region,
:vendor => "microsoft",
:vendor => "azure",
:raw_power_state => "never",
:template => true,
:publicly_available => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,52 @@ object:
on_error:
max_retries:
max_time:
- field:
aetype: method
name: azure_meth1
display_name: Azure
datatype: string
priority: 7
owner:
default_value:
substitute: true
message: azure
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
- field:
aetype: relationship
name: azure_rel1
display_name: Azure
datatype: string
priority: 8
owner:
default_value:
substitute: true
message: azure
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
- field:
aetype: relationship
name: common_rel1
display_name: Common
datatype: string
priority: 7
priority: 9
owner:
default_value:
substitute: true
Expand All @@ -156,7 +196,7 @@ object:
name: common_meth1
display_name: Common
datatype: string
priority: 8
priority: 10
owner:
default_value:
substitute: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
if vm && vm.attributes['power_state'] == 'on'
ems = vm.ext_management_system
if vm.hardware.root_device_type == "ebs"
$evm.log('info', "Stopping Amazon Instance <#{vm.name}> in EMS <#{ems ? ems.name : nil}>")
$evm.log('info', "Stopping Amazon Instance <#{vm.name}> in EMS <#{ems.try(:name)}>")
vm.stop if ems
else
$evm.log('info', "Skipping stopping of non EBS Amazon Instance <#{vm.name}> in EMS <#{ems ? ems.name : nil}>")
$evm.log('info', "Skipping stopping of non EBS Amazon Instance <#{vm.name}> in EMS <#{ems.try(:name)}>")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Description: This method stops the Azure Instance
#

vm = $evm.root['vm']
if vm && vm.power_state == 'on'
ems = vm.ext_management_system
$evm.log('info', "Stopping Azure Instance <#{vm.name}> in EMS <#{ems.try(:name)}>")
vm.stop if ems
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
object_type: method
version: 1.0
object:
attributes:
name: azure_pre_retirement
display_name:
description:
scope: instance
language: ruby
location: inline
inputs: []
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
vm = $evm.root['vm']
unless vm.nil? || vm.attributes['power_state'] == 'off'
ems = vm.ext_management_system
$evm.log('info', "Suspending Openstack Instance <#{vm.name}> in EMS <#{ems ? ems.name : nil}")
$evm.log('info', "Suspending Openstack Instance <#{vm.name}> in EMS <#{ems.try(:name)}")
vm.suspend if ems
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ object:
value: check_pre_retirement
- amazon_meth1:
value: amazon_check_pre_retirement
- azure_meth1:
value: check_pre_retirement
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ object:
value: openstack_pre_retirement
- amazon_meth1:
value: amazon_pre_retirement
- azure_meth1:
value: azure_pre_retirement
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe "azure_pre_retirement Method Validation" do
before do
@user = FactoryGirl.create(:user_with_group)
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_azure, :zone => @zone)
@vm = FactoryGirl.create(:vm_azure,
:name => "AZURE", :raw_power_state => "VM Running",
:ems_id => @ems.id, :registered => true)
@ins = "/Cloud/VM/Retirement/StateMachines/Methods/PreRetirement"
end

it "call suspend for running instances" do
MiqAeEngine.instantiate("#{@ins}?Vm::vm=#{@vm.id}#Azure", @user)
MiqQueue.exists?(:method_name => 'stop', :instance_id => @vm.id, :role => 'ems_operations').should be_true
end

it "does not call suspend for powered off instances" do
@vm.update_attributes(:raw_power_state => 'VM Stopped')
MiqAeEngine.instantiate("#{@ins}?Vm::vm=#{@vm.id}#Azure", @user)
MiqQueue.exists?(:method_name => 'stop', :instance_id => @vm.id, :role => 'ems_operations').should be_false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def assert_specific_vm_powered_on
:ems_ref_obj => nil,
:uid_ems => "462f2af8-e67e-40c6-9fbf-02824d1dd485\\chef-prod"\
"\\microsoft.compute/virtualmachines\\Chef-Prod",
:vendor => "Microsoft",
:vendor => "Azure",
:power_state => "on",
:location => "462f2af8-e67e-40c6-9fbf-02824d1dd485\\chef-prod"\
"\\microsoft.compute/virtualmachines\\Chef-Prod",
Expand Down Expand Up @@ -235,7 +235,7 @@ def assert_specific_vm_powered_off_attributes(v)
:ems_ref_obj => nil,
:uid_ems => "462f2af8-e67e-40c6-9fbf-02824d1dd485\\computevms\\"\
"microsoft.compute/virtualmachines\\MIQ2",
:vendor => "Microsoft",
:vendor => "Azure",
:power_state => "off",
:location => "462f2af8-e67e-40c6-9fbf-02824d1dd485\\computevms\\"\
"microsoft.compute/virtualmachines\\MIQ2",
Expand Down Expand Up @@ -287,7 +287,7 @@ def assert_specific_template
:uid_ems => "https://chefprod5120.blob.core.windows.net/system/"\
"Microsoft.Compute/Images/postgres-cont/"\
"postgres-osDisk.fcf3dcec-fb8d-49f5-9d8c-b15edcff704c.vhd",
:vendor => "Microsoft",
:vendor => "Azure",
:power_state => "never",
:location => "eastus",
:tools_status => nil,
Expand Down