My services / owner


#1

Hello,

We have been testing service catalog items and built many services. (under EvmGroup-super_administrator group)
I would need to be able to retire just services built by a specific user. Pls. is there any way how can I display and retire services regarding a service owner?

Thanks,
Karel


#2

@gmccullough can you review this question from @Karel and forward to a SME if necessary.


#3

Hi Karel,

You can use reporting and create a custom report to include services with a specific owner, but it doesn’t help you with selective retirement.

One approach is to create a custom button to list, then optionally retire services based on a user.

To create a service custom button with dialog input:

  1. Create a simple service dialog to prompt for the owner name.

  2. Create a service retire custom button, using the visibility option to limit the visibility by role.(so only certain roles can retire the services)


  3. Create a service retire custom button group and include the custom button in the group.

  4. Create a /System/Request/retire_services instance and method.
    The retire_services instance would call a retire_services method.
    Here’s my /System/Request/retire_services test method which only lists the services for a given user. Uncommenting out the “s.retire_now” line would retire the services.
    ``

    $evm.log(‘info’, ‘Listing Root Object Attributes:’)

    $evm.root.attributes.sort.each { |k, v| $evm.log(‘info’, ‘\t#{k}: # {v}’) }
    owner_name = $evm.root[‘dialog_service_owner’]

    owner = $evm.vmdb(:user).find_by_name(owner_name)
    if owner.nil?
    $evm.log(“info”, “Requested owner not found: #{owner_name}”)
    exit MIQ_ABORT
    end

    $evm.log(“info”, “Services Owned by: #{owner.inspect}”)

    services = $evm.vmdb(:service).where(:id => owner.id)
    $evm.log(“info”, “Services: Owned by: #{owner_name}”)
    services.sort.each do |s|
    if s.retired?
    $evm.log(“info”, “Service already retired: #{s.name}”)
    next
    end
    $evm.log(“info”, “Initiating Retirement for Service: #{s.name}”)
    ####s.retire_now
    end
    ``

Please let me know if you have any questions.

Regards,
Tina


#4

Many thanks for help.
It works well.

Karel


#5

Hi Karel,

I’m glad it solved your problem.

I noticed a typo in my test method this morning:
this line:
services = $evm.vmdb(:service).where(:id => owner.id)
should be replaced with this:
services = $evm.vmdb(:service).where(:evm_owner_id => owner.id)

Regards,
Tina


#6

yes, I have found the typo.
I have added next parameter service description to be able to limit the retirement just for an owner and specific services. So my final method looks this way.

$evm.log(‘info’, ‘Listing Root Object Attributes:’)

$evm.root.attributes.sort.each { |k, v| $evm.log(‘info’, ‘\t#{k}: # {v}’) }
owner_name = $evm.root[‘dialog_service_owner’]
$evm.log(“info”, “Entered owner name: #{owner_name}”)

service_description = $evm.root[‘dialog_service_description’]
$evm.log(“info”, “Entered service description: #{service_description}”)

owner = $evm.vmdb(:user).find_by_name(owner_name)
if owner.nil?
$evm.log(“info”, “Requested owner not found: #{owner_name}”)
exit MIQ_ABORT
end

$evm.log(“info”, “Services Owned by: #{owner.inspect}”)
$evm.log(“info”, “OwnerID: #{owner.id}”)

services = $evm.vmdb(:service).where([“evm_owner_id = ? AND description = ?”, owner.id, service_description])

$evm.log(“info”, “Services: Owned by: #{owner_name}”)
services.each do |s|
if s.retired?
$evm.log(“info”, “Service already retired: #{s.name}”)
next
end
$evm.log(“info”, “Initiating Retirement for Service: #{s.name}”)
s.retire_now
end


#7

Hi Karel,

Thanks, I’m glad you found the typo.

Your method looks great!

Regards,
Tina