-
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
Merged
Merged
Dedicate command #896
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9661c63
VIRT-4404 : adding list functionality to dedicated host
1a48944
VIRT-4404 : Adding dedicated host functionality
aa944c7
VIRT-4404 : Adding dedicated host functionality
91376d7
VIRT-4404 : Adding Functionality for dedicated host
3a39d82
VIRT-4404 : Adding Functionality for dedicated host
11b6e9a
VIRT-4404 : fixed merge conflicts
a133971
VIRT-4404 : Adding details functionality
913e721
Virt-4404 : Made suggested code changes and added dedicated host func…
a09d814
Merge branch 'master' into dedicateCommand
2abc785
Added Dedicated host functionality
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"""Dedicated Host.""" | ||
# :license: MIT, see LICENSE for more details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
"""Order/create a dedicated Host.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import exceptions | ||
from SoftLayer.CLI import formatting | ||
from SoftLayer.CLI import template | ||
|
||
|
||
@click.command( | ||
epilog="See 'slcli dedicatedhost create-options' for valid options.") | ||
@click.option('--hostname', '-H', | ||
help="Host portion of the FQDN", | ||
required=True, | ||
prompt=True) | ||
@click.option('--router', '-r', | ||
help="Router hostname ex. fcr02a.dal13", | ||
show_default=True) | ||
@click.option('--domain', '-D', | ||
help="Domain portion of the FQDN", | ||
required=True, | ||
prompt=True) | ||
@click.option('--datacenter', '-d', help="Datacenter shortname", | ||
required=True, | ||
prompt=True) | ||
@click.option('--flavor', '-f', help="Dedicated Virtual Host flavor", | ||
required=True, | ||
prompt=True) | ||
@click.option('--billing', | ||
type=click.Choice(['hourly', 'monthly']), | ||
default='hourly', | ||
show_default=True, | ||
help="Billing rate") | ||
@click.option('--verify', | ||
is_flag=True, | ||
help="Verify dedicatedhost without creating it.") | ||
@click.option('--template', '-t', | ||
is_eager=True, | ||
callback=template.TemplateCallback(list_args=['key']), | ||
help="A template file that defaults the command-line options", | ||
type=click.Path(exists=True, readable=True, resolve_path=True)) | ||
@click.option('--export', | ||
type=click.Path(writable=True, resolve_path=True), | ||
help="Exports options to a template file") | ||
@environment.pass_env | ||
def cli(env, **kwargs): | ||
"""Order/create a dedicated host.""" | ||
mgr = SoftLayer.DedicatedHostManager(env.client) | ||
|
||
order = { | ||
'hostname': kwargs['hostname'], | ||
'domain': kwargs['domain'], | ||
'flavor': kwargs['flavor'], | ||
'location': kwargs['datacenter'], | ||
'hourly': kwargs.get('billing') == 'hourly', | ||
} | ||
|
||
if kwargs['router']: | ||
order['router'] = kwargs['router'] | ||
|
||
do_create = not (kwargs['export'] or kwargs['verify']) | ||
|
||
output = None | ||
|
||
result = mgr.verify_order(**order) | ||
table = formatting.Table(['Item', 'cost']) | ||
table.align['Item'] = 'r' | ||
table.align['cost'] = 'r' | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. set |
||
if order['hourly']: | ||
total = float(price[0].get('hourlyRecurringFee', 0.0)) | ||
else: | ||
total = float(price[0].get('recurringFee', 0.0)) | ||
|
||
if order['hourly']: | ||
table.add_row(['Total hourly cost', "%.2f" % total]) | ||
else: | ||
table.add_row(['Total monthly cost', "%.2f" % total]) | ||
|
||
output = [] | ||
output.append(table) | ||
output.append(formatting.FormattedItem( | ||
'', | ||
' -- ! Prices reflected here are retail and do not ' | ||
'take account level discounts and are not guaranteed.')) | ||
|
||
if kwargs['export']: | ||
export_file = kwargs.pop('export') | ||
template.export_to_template(export_file, kwargs, | ||
exclude=['wait', 'verify']) | ||
env.fout('Successfully exported options to a template file.') | ||
|
||
if do_create: | ||
if not env.skip_confirmations and not formatting.confirm( | ||
"This action will incur charges on your account. " | ||
"Continue?"): | ||
raise exceptions.CLIAbort('Aborting dedicated host order.') | ||
|
||
result = mgr.place_order(**order) | ||
|
||
table = formatting.KeyValueTable(['name', 'value']) | ||
table.align['name'] = 'r' | ||
table.align['value'] = 'l' | ||
table.add_row(['id', result['orderId']]) | ||
table.add_row(['created', result['orderDate']]) | ||
output.append(table) | ||
|
||
env.fout(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Options for ordering a dedicated host""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import click | ||
import SoftLayer | ||
|
||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import exceptions | ||
from SoftLayer.CLI import formatting | ||
|
||
|
||
@click.command() | ||
@click.option('--datacenter', '-d', | ||
help="Router hostname (requires --flavor) " | ||
"ex. ams01", | ||
show_default=True) | ||
@click.option('--flavor', '-f', | ||
help="Dedicated Virtual Host flavor (requires --datacenter)" | ||
" ex. 56_CORES_X_242_RAM_X_1_4_TB", | ||
show_default=True) | ||
@environment.pass_env | ||
def cli(env, **kwargs): | ||
"""host order options for a given dedicated host. | ||
|
||
To get a list of available backend routers see example: | ||
slcli dh create-options --datacenter dal05 --flavor 56_CORES_X_242_RAM_X_1_4_TB | ||
""" | ||
|
||
mgr = SoftLayer.DedicatedHostManager(env.client) | ||
tables = [] | ||
|
||
if not kwargs['flavor'] and not kwargs['datacenter']: | ||
options = mgr.get_create_options() | ||
|
||
# Datacenters | ||
dc_table = formatting.Table(['datacenter', 'value']) | ||
dc_table.sortby = 'value' | ||
for location in options['locations']: | ||
dc_table.add_row([location['name'], location['key']]) | ||
tables.append(dc_table) | ||
|
||
dh_table = formatting.Table(['Dedicated Virtual Host Flavor(s)', 'value']) | ||
dh_table.sortby = 'value' | ||
for item in options['dedicated_host']: | ||
dh_table.add_row([item['name'], item['key']]) | ||
tables.append(dh_table) | ||
else: | ||
if kwargs['flavor'] is None or kwargs['datacenter'] is None: | ||
raise exceptions.ArgumentError('Both a flavor and datacenter need ' | ||
'to be passed as arguments ' | ||
'ex. slcli dh create-options -d ' | ||
'ams01 -f ' | ||
'56_CORES_X_242_RAM_X_1_4_TB') | ||
router_opt = mgr.get_router_options(kwargs['datacenter'], kwargs['flavor']) | ||
br_table = formatting.Table( | ||
['Available Backend Routers']) | ||
for router in router_opt: | ||
br_table.add_row([router['hostname']]) | ||
tables.append(br_table) | ||
|
||
env.fout(formatting.listing(tables, separator='\n')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Get details for a dedicated host.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import logging | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
from SoftLayer import utils | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@click.command() | ||
@click.argument('identifier') | ||
@click.option('--price', is_flag=True, help='Show associated prices') | ||
@click.option('--guests', is_flag=True, help='Show guests on dedicated host') | ||
@environment.pass_env | ||
def cli(env, identifier, price=False, guests=False): | ||
"""Get details for a virtual server.""" | ||
dhost = SoftLayer.DedicatedHostManager(env.client) | ||
|
||
table = formatting.KeyValueTable(['name', 'value']) | ||
table.align['name'] = 'r' | ||
table.align['value'] = 'l' | ||
|
||
result = dhost.get_host(identifier) | ||
result = utils.NestedDict(result) | ||
|
||
table.add_row(['id', result['id']]) | ||
table.add_row(['name', result['name']]) | ||
table.add_row(['cpu count', result['cpuCount']]) | ||
table.add_row(['memory capacity', result['memoryCapacity']]) | ||
table.add_row(['disk capacity', result['diskCapacity']]) | ||
table.add_row(['create date', result['createDate']]) | ||
table.add_row(['modify date', result['modifyDate']]) | ||
table.add_row(['router id', result['backendRouter']['id']]) | ||
table.add_row(['router hostname', result['backendRouter']['hostname']]) | ||
table.add_row(['owner', formatting.FormattedItem( | ||
utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username') or formatting.blank(),)]) | ||
|
||
if price: | ||
total_price = utils.lookup(result, | ||
'billingItem', | ||
'nextInvoiceTotalRecurringAmount') or 0 | ||
total_price += sum(p['nextInvoiceTotalRecurringAmount'] | ||
for p | ||
in utils.lookup(result, | ||
'billingItem', | ||
'children') or []) | ||
table.add_row(['price_rate', total_price]) | ||
|
||
table.add_row(['guest count', result['guestCount']]) | ||
if guests: | ||
guest_table = formatting.Table(['id', 'hostname', 'domain', 'uuid']) | ||
for guest in result['guests']: | ||
guest_table.add_row([ | ||
guest['id'], guest['hostname'], guest['domain'], guest['uuid']]) | ||
table.add_row(['guests', guest_table]) | ||
|
||
table.add_row(['datacenter', result['datacenter']['name']]) | ||
|
||
env.fout(table) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""List dedicated servers.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import columns as column_helper | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
from SoftLayer.CLI import helpers | ||
|
||
COLUMNS = [ | ||
column_helper.Column('datacenter', ('datacenter', 'name')), | ||
column_helper.Column( | ||
'created_by', | ||
('billingItem', 'orderItem', 'order', 'userRecord', 'username')), | ||
column_helper.Column( | ||
'tags', | ||
lambda server: formatting.tags(server.get('tagReferences')), | ||
mask="tagReferences.tag.name"), | ||
] | ||
|
||
DEFAULT_COLUMNS = [ | ||
'id', | ||
'name', | ||
'cpuCount', | ||
'diskCapacity', | ||
'memoryCapacity', | ||
'datacenter', | ||
'guestCount', | ||
] | ||
|
||
|
||
@click.command() | ||
@click.option('--cpu', '-c', help='Number of CPU cores', type=click.INT) | ||
@helpers.multi_option('--tag', help='Filter by tags') | ||
@click.option('--sortby', help='Column to sort by', | ||
default='name', | ||
show_default=True) | ||
@click.option('--columns', | ||
callback=column_helper.get_formatter(COLUMNS), | ||
help='Columns to display. [options: %s]' | ||
% ', '.join(column.name for column in COLUMNS), | ||
default=','.join(DEFAULT_COLUMNS), | ||
show_default=True) | ||
@click.option('--datacenter', '-d', help='Datacenter shortname') | ||
@click.option('--name', '-H', help='Host portion of the FQDN') | ||
@click.option('--memory', '-m', help='Memory capacity in mebibytes', | ||
type=click.INT) | ||
@click.option('--disk', '-D', help='Disk capacity') | ||
@environment.pass_env | ||
def cli(env, sortby, cpu, columns, datacenter, name, memory, disk, tag): | ||
"""List dedicated host.""" | ||
mgr = SoftLayer.DedicatedHostManager(env.client) | ||
hosts = mgr.list_instances(cpus=cpu, | ||
datacenter=datacenter, | ||
hostname=name, | ||
memory=memory, | ||
disk=disk, | ||
tags=tag, | ||
mask=columns.mask()) | ||
|
||
table = formatting.Table(columns.columns) | ||
table.sortby = sortby | ||
|
||
for host in hosts: | ||
table.add_row([value or formatting.blank() | ||
for value in columns.row(host)]) | ||
|
||
env.fout(table) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.