aeolus-incubator/tim — pull request #113 by mtaylor (2013-03-13 19:06:36+00:00)
Title: Fsm delete

This Patch adds in ability to delete factory provider images (for non imported images). It does not actually remove the image from the database. It simply sets the fsm_delete_state to COMPLETE.

If an end user wants to actually delete the provider image from the database. They can add a state machine listener:

```
def after_fsm_create_complete(pi, transition)
pi.force_destroy
end
```

As is apparent from the above code. ActiveRecord destroy (on ProviderImage only) has been alias to :force_destroy. The new destroy method requires 1 parameter (XML credentials definition).

In order to test this code use the imagefactory branch from my repo:
https://github.com/mtaylor/imagefactory/tree/pi_delete_with_root

There are a few monkey patches in this code. This is because ActiveResource (and also the delete method of Net::HTTP) does not allow a content body in a DELETE request.

I was very careful not to change any default behaviour. I only add new methods, and do a check to see whether or not to call those new methods.

You can test that bit of code independently by:

```
p = Tim::Imagefactory::ProviderImage.find()
p.destroy_with_body
```

There are spec tests included in the patch. But if you want to see delete working (fopr mock provider), you can execute the following code (be sure to use the factory in the url I provided):

```
template_xml = ""

template = Tim::Template.create(:xml => template_xml)

base_image = Tim::BaseImage.new(:name => "BaseImage")
base_image.template = template
base_image.save

image_version = Tim::ImageVersion.new
image_version.base_image = base_image
image_version.save

target_image = Tim::TargetImage.new(:target => "MockSphere")
target_image.image_version = image_version
target_image.save

provider_image = Tim::ProviderImage.new(:provider => "MockSphere", :credentials => "foo=bar")
provider_image.target_image = target_image
provider_image.save

provider_image.destroy("foo")
```