-
Notifications
You must be signed in to change notification settings - Fork 69
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
Added support for VM delete #184
Conversation
087e465
to
7252c43
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @VojkoR , I only have one tiny comment, otherwise LGTM 👍
def raw_destroy | ||
raise "VM has no #{ui_lookup(:table => "ext_management_systems")}, unable to destroy VM" unless ext_management_system | ||
with_provider_object(&:undeploy) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking, but could you please remove this empty line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line removed
7252c43
to
8b9b085
Compare
def raw_destroy | ||
raise "VM has no #{ui_lookup(:table => "ext_management_systems")}, unable to destroy VM" unless ext_management_system | ||
with_provider_object(&:undeploy) | ||
ext_management_system.with_provider_connection do |service| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since with_provider_object
calls with_provider_connection
can you do the :undeploy
in this block so you only have to connect once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext_management_system.with_provider_connection do |service| | ||
service.delete_vapp(ems_ref) | ||
end | ||
update_attributes!(:raw_power_state => "DELETED") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is DELETED
a valid power state? How about "off" since it is a valid vcloud_director state and also recognized by the vcloud provider
8b9b085
to
6daddc7
Compare
raise "VM has no #{ui_lookup(:table => "ext_management_systems")}, unable to destroy VM" unless ext_management_system | ||
ext_management_system.with_provider_connection do |service| | ||
begin | ||
response = service.post_undeploy_vapp(ems_ref, :UndeployPowerAction => 'shutdown') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before delete action is called we need to stop VM. In case VM is already stopped action will rise an error. To successfully delete VM we are catching this error and just log the message what happened.
ensure | ||
response = service.delete_vapp(ems_ref) | ||
service.process_task(response.body) | ||
update_attributes!(:raw_power_state => "terminated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think correct power state for deleted VM should be "terminated". Maybe I should set power state to "unknown" instead of "terminated"?
Hi @agrare I changed functionality as requested. I added some extra code, to correctly implement DELETE action. I wrote some comments for the code that was added and why it was added. |
begin | ||
response = service.post_undeploy_vapp(ems_ref, :UndeployPowerAction => 'shutdown') | ||
service.process_task(response.body) | ||
rescue => err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rescue the exact exception that is raised if the VM is already stopped?
rescue => err | ||
$vcloud_log.debug("vm=[#{name}], error: VM not running! Ignoring error: #{err}") | ||
ensure | ||
response = service.delete_vapp(ems_ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't like doing this in the ensure block assuming that you're rescuing a "vm already powered off" exception because it could be something completely different and we'll still try to do this.
I'd rather rescue the exact exception then do this outside the begin/rescue block like:
begin
service.post_undeploy_vapp(ems_ref, :UndeployPowerAction => 'shutdown')
rescue Vcloud::VmAlreadyPoweredOff /* not sure what this exception actually is, just for demonstration */
# this is expected if the vapp is already off
end
service.process_task(response.body)
update_attributes!(:raw_power_state => "terminated")
This commit now adds support for removal of a stopped VM from vApp. Besides removal operation it overrides the `supports :terminate` feature because the VM must be powered off to allow to be deleted from VCD. Signed-off-by: Vojko Rozic <[email protected]> Signed-off-by: Gregor Berginc <[email protected]>
6daddc7
to
0427809
Compare
Checked commit https://github.com/VojkoR/manageiq-providers-vmware/commit/042780967d87c0bc9524a57d71cf174099398791 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 app/models/manageiq/providers/vmware/cloud_manager.rb
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare We have simplified the code to handle removal of VM in a way VCD handles it. I've added two comments in the code to explain the rationale.
I hope this will be ok.
|
||
included do | ||
supports :terminate do | ||
unsupported_reason_add(:terminate, "The VM is powered on") unless current_state == "off" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare we have modified the code to resemble the behaviour of VCD. Now, it is not possible to delete a VM that is running (powered on). To this end we had to redefine the supports_terminate?
by looking at the current_state
of the VM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I like that, we actually have a helper method for this that you can use, https://github.com/ManageIQ/manageiq/blob/master/app/models/vm/operations/power.rb#L22-L24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @agrare. I’ll make another PR to use this.
def raw_destroy | ||
raise "VM has no #{ui_lookup(:table => "ext_management_systems")}, unable to destroy VM" unless ext_management_system | ||
ext_management_system.with_provider_connection do |service| | ||
response = service.delete_vapp(ems_ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking for exceptions we are simply passing to the underlying provider connection. Looking at OpenStack and Amazon, this is exactly how these two are handled. In case an exception occurs it will be propagated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 perfect
This looks good, can you send a followup to use that |
Added support for VM delete (cherry picked from commit 1dfa303) https://bugzilla.redhat.com/show_bug.cgi?id=1552683
Gaprindashvili backport details:
|
…h-based-on-events Do targeted refresh based on Openstack events.
Added support for VM delete
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1550841
/cc @miha-plesko