forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.py
More file actions
57 lines (45 loc) · 2.04 KB
/
edit.py
File metadata and controls
57 lines (45 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Edit hardware details."""
# :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 helpers
@click.command()
@click.argument('identifier')
@click.option('--domain', '-D', help="Domain portion of the FQDN")
@click.option('--userfile', '-F', type=click.Path(exists=True, readable=True, resolve_path=True),
help="Read userdata from file")
@click.option('--tag', '-g', multiple=True,
help="Tags to set or empty string to remove all")
@click.option('--hostname', '-H', help="Host portion of the FQDN")
@click.option('--userdata', '-u', help="User defined metadata string")
@click.option('--public-speed', default=None, type=click.Choice(['0', '10', '100', '1000', '10000', '-1']),
help="Public port speed. -1 is best speed available")
@click.option('--private-speed', default=None, type=click.Choice(['0', '10', '100', '1000', '10000', '-1']),
help="Private port speed. -1 is best speed available")
@environment.pass_env
def cli(env, identifier, domain, userfile, tag, hostname, userdata, public_speed, private_speed):
"""Edit hardware details."""
if userdata and userfile:
raise exceptions.ArgumentError(
'[-u | --userdata] not allowed with [-F | --userfile]')
data = {
'hostname': hostname,
'domain': domain,
}
if userdata:
data['userdata'] = userdata
elif userfile:
with open(userfile, 'r') as userfile_obj:
data['userdata'] = userfile_obj.read()
if tag:
data['tags'] = ','.join(tag)
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if not mgr.edit(hw_id, **data):
raise exceptions.CLIAbort("Failed to update hardware")
if public_speed is not None:
mgr.change_port_speed(hw_id, True, int(public_speed))
if private_speed is not None:
mgr.change_port_speed(hw_id, False, int(private_speed))