I’m trying to implement a “service upgrade” lifecycle action on active services. Let’s suppose we have a service ordered from service template
template_v1 . We offer an new
template_v2 with extended capabilities (for example optional monitoring service).
I want to allow upgrading the active services to v2. I create a button “Upgrade to v2” with an
upgrade_to_v2 method. This method carefully creates/configures (additional) resources of the service to match
template_v2. I also want to reflect the change in the catalog item relationship (parent catalog item) of the service. The following code seems to do the trick:
service = $evm.root['service'] template_id = $evm.vmdb(:service_template).find_by_name("template_v2").id service[:service_template_id] = template_id service.instance_variable_get(:@object).save!
This seems to correctly update the catalog item relationship. Does that look right to you? Any objections?
Another approach I thought of would be to create a new service and add the resources of the old one to the new, based on this example:
template = $evm.vmdb(:service_template).find_by_name("template_v2") new_service = $evm.vmdb('service').create(:name => "service v2", :service_template => template) # ... adding child services, VMs, generic objects to new_service, copying options # ... deleting old service
This looks to be harder but probably safer than the first approach. One drawback is that we have a new service object losing the history of the old one.