Skip to content

Conversation

acamacho82
Copy link
Contributor

slcli dh cancel makes a simple call to the deleteObject method of dedicated host.
slcli dh cancel-guests cancels all guests into the dedicated hosts
slcli dh list-guests lists guests in the dedicated host, it should be possible to filter, sortby and display more columns in the table

It should cover the request #1041

@acamacho82
Copy link
Contributor Author

It failed due to my latest commit, I will fix it

Copy link
Member

@allmightyspiff allmightyspiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just need a few changes to cancel_guest.

"""
return self.host.deleteObject(id=host_id)

def cancel_guests(self, host_id):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this function, I'd like it to be able to return a structure that has a bit more information about what guests were canceled so the slcli can print out a receipt.

Ideally id, FQDN, and whether the guest was canceled or got an error

return  = [
    {'id': 1234, 'fqdn': 'test01.test.com', 'status': 'canceled' },
    {'id': 1235, 'fqdn': 'test02.test.com', 'status': 'Exception: Running Transaction or something' },
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, it returns a dictionary and it is empty if there isn't any guest in the dedicated host. The slcli prints a table or a message in case the dict is empty.


if guests:
for vs in guests:
result = self.guest.deleteObject(id=vs['id'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to wrap this in a try/catch for SoftLayer.Exceptions. I can see a case where one guest will have a running transaction and won't be able to be canceled. So we don't want this command to fail midway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, is in the method called _delete_guest. I also added a unit-test to verify the exception message is retrieved in case the deleteObject fails

if not (env.skip_confirmations or formatting.no_going_back(host_id)):
raise exceptions.CLIAbort('Aborted')

result = dh_mgr.cancel_guests(host_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After updated the manager function, just add a way to print out a nice table with the results of each guests' cancelation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It prints a table like below

$ slcli --really dh cancel-guests 33333
:..........:...........................:..................................................................:
:    id    :        server name        :                              status                              :
:..........:...........................:..................................................................:
: 1111111  :    foobar.softlayer.com   :                            Cancelled                             :
: 2222222  :    wombat.softlayer.com   : Exception: A billing item is required to process a cancellation. :
:..........:...........................:..................................................................:

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 89.825% when pulling 2987fd9 on acamacho82:1041 into d6821f3 on softlayer:master.

@allmightyspiff allmightyspiff merged commit 12310b8 into softlayer:master Nov 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants