|
| 1 | +"""Edit dedicated host details.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +import SoftLayer |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import exceptions |
| 9 | +from SoftLayer.CLI import helpers |
| 10 | + |
| 11 | + |
| 12 | +@click.command() |
| 13 | +@click.argument('identifier') |
| 14 | +@click.option('--domain', '-D', help="Domain portion of the FQDN") |
| 15 | +@click.option('--userfile', '-F', |
| 16 | + help="Read userdata from file", |
| 17 | + type=click.Path(exists=True, readable=True, resolve_path=True)) |
| 18 | +@click.option('--tag', '-g', |
| 19 | + multiple=True, |
| 20 | + help="Tags to set or empty string to remove all") |
| 21 | +@click.option('--hostname', '-H', help="Host portion of the FQDN") |
| 22 | +@click.option('--userdata', '-u', help="User defined metadata string") |
| 23 | +@click.option('--public-speed', |
| 24 | + help="Public port speed.", |
| 25 | + default=None, |
| 26 | + type=click.Choice(['0', '10', '100', '1000', '10000'])) |
| 27 | +@click.option('--private-speed', |
| 28 | + help="Private port speed.", |
| 29 | + default=None, |
| 30 | + type=click.Choice(['0', '10', '100', '1000', '10000'])) |
| 31 | +@environment.pass_env |
| 32 | +def cli(env, identifier, domain, userfile, tag, hostname, userdata, |
| 33 | + public_speed, private_speed): |
| 34 | + """Edit dedicated host details.""" |
| 35 | + |
| 36 | + if userdata and userfile: |
| 37 | + raise exceptions.ArgumentError( |
| 38 | + '[-u | --userdata] not allowed with [-F | --userfile]') |
| 39 | + |
| 40 | + data = { |
| 41 | + 'hostname': hostname, |
| 42 | + 'domain': domain, |
| 43 | + } |
| 44 | + if userdata: |
| 45 | + data['userdata'] = userdata |
| 46 | + elif userfile: |
| 47 | + with open(userfile, 'r') as userfile_obj: |
| 48 | + data['userdata'] = userfile_obj.read() |
| 49 | + if tag: |
| 50 | + data['tags'] = ','.join(tag) |
| 51 | + |
| 52 | + mgr = SoftLayer.DedicatedHostManager(env.client) |
| 53 | + |
| 54 | + if not mgr.edit(identifier, **data): |
| 55 | + raise exceptions.CLIAbort("Failed to update dedicated host") |
| 56 | + |
| 57 | + if public_speed is not None: |
| 58 | + mgr.change_port_speed(identifier, True, int(public_speed)) |
| 59 | + |
| 60 | + if private_speed is not None: |
| 61 | + mgr.change_port_speed(identifier, False, int(private_speed)) |
0 commit comments