-
Notifications
You must be signed in to change notification settings - Fork 194
Dedicate command #896
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
Dedicate command #896
Conversation
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.
Overall looks good. My biggest concern is some of the hard coding around the dedicated host size stuff.
help="Host portion of the FQDN", | ||
required=True, | ||
prompt=True) | ||
@click.option('--router', '-r', |
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.
- unless its wildly complicated, I would prefer to pass in the router hostname, fcr02a.dal13 or something
- Is specifying a VLAN not an option for dedicated hosts?
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.
- Specifying a VLAN is not an option for dedicated hosts
default='hourly', | ||
show_default=True, | ||
help="Billing rate") | ||
@click.option('--test', |
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'd prefer --verify, or --dry-run instead of test.
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.
Currently virtual servers and hardware use --test. Would you still like it changed?
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.
Yeah --test
isn't too descriptive. I'd personally prefer --verify
. Might want to make the help a little more descriptive to say it only verifies the dedicated host order without placing it.
'hourly': args.get('billing') == 'hourly', | ||
} | ||
|
||
do_create = not (args['test']) |
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 you are already testing this on line 55, just change line 84 to else:
if args.get('test'): | ||
result = mgr.verify_order(**order) | ||
|
||
table = formatting.Table(['Item', 'cost']) |
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 it would be good to include this pricing information in the order output as well.
"""host order options for a given dedicated host.""" | ||
|
||
mgr = SoftLayer.DedicatedHostManager(env.client) | ||
options = mgr.get_create_options() |
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.
If its not too hard I'd also like to output the available routers (and vlans if possible) per DC here.
SoftLayer/managers/dedicated_host.py
Outdated
|
||
def _get_item(self, package): | ||
"""Returns the item for ordering a dedicated host.""" | ||
description = '56 Cores X 242 RAM X 1.2 TB' |
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 can see this being problematic if we ever have more dedicated host sizes. I'd also prefer we check keynames not descriptions.
_get_item(self, package, itemKey='DEDICATED_HSOT')
or something like that.
for location in locations: | ||
if location['locationId'] is not None: | ||
loc_id = location['locationId'] | ||
host = { |
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 can see this being problematic if more dedicated host sizes are added. This should be calculated from the package or supplied by the CLI I think.
Unless its possible to not supply this data at all and just get a list of routers without specifying a template
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've taken a first pass at this, mostly focusing on the create CLI and the manager. I'll take a deeper look at this later.
type=click.Path(writable=True, resolve_path=True), | ||
help="Exports options to a template file") | ||
@environment.pass_env | ||
def cli(env, **args): |
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 know virt/create:cli does **args, but I find that really confusing since they're more conventionally **kwargs.
Though in my opinion, even though you do have a lot of options, I think it would be easier to read and see what options are all possibly going to be coming in on the cli by explicitly outlining all of the command line args that are coming in here.
'hostname': args['hostname'], | ||
'domain': args['domain'], | ||
'flavor': args['flavor'], | ||
'router': args['router'], |
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 router is optional, this may not be defined in the args. I think the @click.option
decorator will make it a kwarg for you, so you don't need to worry about a key error here, but it will be set to None if it isn't set on the command line. Is that what this is supposed to be set to if no router is specified?
If not, I'd put the things you know will be set in the order (i.e. the mandatory items) in this initial dict creation, and then add things in later if needed, like:
if args['router']:
order['router'] = args['router']
'domain': args['domain'], | ||
'flavor': args['flavor'], | ||
'router': args['router'], | ||
'location': args.get('datacenter'), |
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.
this needs to be set doesn't it? It's required by the CLI, so it should just be args['datacenter']
.get()
will return None if it isn't set, which you probably don't want to pass in the order
default='hourly', | ||
show_default=True, | ||
help="Billing rate") | ||
@click.option('--test', |
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.
Yeah --test
isn't too descriptive. I'd personally prefer --verify
. Might want to make the help a little more descriptive to say it only verifies the dedicated host order without placing it.
if len(result['prices']) != 1: | ||
raise exceptions.ArgumentError("More than 1 price was found or no " | ||
"prices found") | ||
price = result['prices'] |
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.
set price = result['prices'][0]
here, because price[0]
looks weird down below (and you're doing it twice so that helps clean up the below a little more)
SoftLayer/CLI/hardware/create.py
Outdated
return | ||
|
||
if do_create: | ||
|
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 don't think you wanted to be changing this file
'sort': 0 | ||
}] | ||
|
||
verifyOrderDH = { |
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.
Not sure what the normal process is around adding fixtures, but this seems a little long. Do we want this reduced down so it only has the fields that you need? This question is more for @allmightyspiff
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 don't really have a strong opinion on this at the moment.
SoftLayer/managers/dedicated_host.py
Outdated
|
||
kwargs['filter'] = _filter.to_dict() | ||
func = getattr(self.account, call) | ||
return func(**kwargs) |
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 making this roundabout way of calling getDedicatedHosts, I'd just use self.account.getDedicatedHosts(**kwargs)
SoftLayer/managers/dedicated_host.py
Outdated
|
||
raise SoftLayer.SoftLayerError("Could not find available routers") | ||
|
||
def _get_default_router(self, routers, router_name): |
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 for readability, since router_name isn't required, default it to None in the args here. Even though you always supply it above (and it's None because it's optional in _generate_create_dict()), I'd still be explicit with router_name=None
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.
Few more comments added from going through it a little closer.
" ex. 56_CORES_X_242_RAM_X_1_4_TB", | ||
show_default=True) | ||
@environment.pass_env | ||
def cli(env, **args): |
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.
Same for **kwargs
here as in create. Though I would really just lean towards having datacenter and flavor as explicit kwargs for the function
else: | ||
if args['flavor'] is None or args['datacenter'] is None: | ||
raise exceptions.ArgumentError('Both a flavor and datacenter need ' | ||
'to be passed as arguments\n' |
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 do a '\n'
in an exception string, just let it all flow on one line. If you want a separator for the example, maybe just put the example in parentheses
table.add_row(['router hostname', result['backendRouter']['hostname']]) | ||
if utils.lookup(result, 'billingItem') != {}: | ||
table.add_row(['owner', formatting.FormattedItem( | ||
utils.lookup(result, 'billingItem', 'orderItem', |
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.
wouldn't this lookup just return {} if billingItem wasn't set, so the if above isn't needed? Because either way if something in that lookup isn't set, you'll end up with formatting.blank()
anyways
SoftLayer/managers/dedicated_host.py
Outdated
'createDate,' | ||
'modifyDate,' | ||
'backendRouter[id, hostname, domain],' | ||
'billingItem[id, nextInvoiceTotalRecurringAmount, ' |
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'd think about reorganizing this to make it a little more readable, because it's not obvious the nesting structure of this mask (i.e. children and orderItem are under billingItem, but the brackets are hard to follow)
Maybe look at how masking is done where a docstring is used, where different indentation can be used to make nesting easier to read. The only problem with the docstring method is printing it out in the debugger can get a little difficult to read.
I made the requested changes. |
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.
Ok looks good. I'll do some personal testing with this tomorrow and if everything works as expected I'll be ready to merge into master, and released some point next week.
'sort': 0 | ||
}] | ||
|
||
verifyOrderDH = { |
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 don't really have a strong opinion on this at the moment.
$ ./slcli dedicatedhost create -H dedicatedHostTest -D cgallo.com -d mex01 -f 56_CORES_X_242_RAM_X_1_4_TB --verify
Total hourly cost 0.00
-- ! Prices reflected here are retail and do not take account level discounts and are not guaranteed.
./slcli dedicatedhost create -H dedicatedHostTest -D cgallo.com -d mex01 -f 56_CORES_X_242_RAM_X_1_4_TB
This action will incur charges on your account. Continue? [y/N]: y
Total hourly cost 0.00
-- ! Prices reflected here are retail and do not take account level discounts and are not guaranteed.
id 21462711
created 2017-12-15T10:54:15-06:00
./slcli dedicatedhost list
50701 ajcb-test 56 1200 242 mex01 1
10201 dedicated2 56 1200 242 dal10 NULL
64801 dedicatedHostTest 56 1200 242 mex01 NULL
10405 fmirDH 56 1200 242 dal09 1
|
No description provided.