Skip to content

Commit 231b7de

Browse files
Merge branch 'master' of github.com:softlayer/softlayer-python into v5.9.0
2 parents d6583f3 + c18a155 commit 231b7de

File tree

11 files changed

+294
-67
lines changed

11 files changed

+294
-67
lines changed

SoftLayer/CLI/ticket/create.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
@click.command()
1313
@click.option('--title', required=True, help="The title of the ticket")
1414
@click.option('--subject-id', type=int, required=True,
15-
help="""The subject id to use for the ticket,
16-
issue 'slcli ticket subjects' to get the list""")
15+
help="""The subject id to use for the ticket, run 'slcli ticket subjects' to get the list""")
1716
@click.option('--body', help="The ticket body")
1817
@click.option('--hardware', 'hardware_identifier',
1918
help="The identifier for hardware to attach")
@@ -24,11 +23,31 @@
2423
Only settable with Advanced and Premium support. See https://www.ibm.com/cloud/support""")
2524
@environment.pass_env
2625
def cli(env, title, subject_id, body, hardware_identifier, virtual_identifier, priority):
27-
"""Create a support ticket."""
28-
ticket_mgr = SoftLayer.TicketManager(env.client)
26+
"""Create a Infrastructure support ticket.
27+
28+
Example::
29+
30+
Will create the ticket with `Some text`.
31+
32+
slcli ticket create --body="Some text" --subject-id 1522 --hardware 12345 --title "My New Ticket"
2933
34+
Will create the ticket with text from STDIN
35+
36+
cat sometfile.txt | slcli ticket create --subject-id 1003 --virtual 111111 --title "Reboot Me"
37+
38+
Will open the default text editor, and once closed, use that text to create the ticket
39+
40+
slcli ticket create --subject-id 1482 --title "Vyatta Questions..."
41+
"""
42+
ticket_mgr = SoftLayer.TicketManager(env.client)
3043
if body is None:
31-
body = click.edit('\n\n' + ticket.TEMPLATE_MSG)
44+
stdin = click.get_text_stream('stdin')
45+
# Means there is text on the STDIN buffer, read it and add to the ticket
46+
if not stdin.isatty():
47+
body = stdin.read()
48+
# This is an interactive terminal, open a text editor
49+
else:
50+
body = click.edit('\n\n' + ticket.TEMPLATE_MSG)
3251
created_ticket = ticket_mgr.create_ticket(
3352
title=title,
3453
body=body,

SoftLayer/CLI/ticket/update.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,35 @@
1111

1212
@click.command()
1313
@click.argument('identifier')
14-
@click.option('--body', help="The entry that will be appended to the ticket")
14+
@click.option('--body', help="Text to add to the ticket. STDIN or the default text editor will be used otherwise.")
1515
@environment.pass_env
1616
def cli(env, identifier, body):
17-
"""Adds an update to an existing ticket."""
17+
"""Adds an update to an existing ticket.
18+
19+
Example::
20+
21+
Will update the ticket with `Some text`.
22+
23+
slcli ticket update 123456 --body="Some text"
24+
25+
Will update the ticket with text from STDIN
26+
27+
cat sometfile.txt | slcli ticket update 123456
28+
29+
Will open the default text editor, and once closed, use that text to update the ticket
30+
31+
slcli ticket update 123456
32+
"""
1833
mgr = SoftLayer.TicketManager(env.client)
1934

2035
ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')
21-
2236
if body is None:
23-
body = click.edit('\n\n' + ticket.TEMPLATE_MSG)
24-
37+
stdin = click.get_text_stream('stdin')
38+
# Means there is text on the STDIN buffer, read it and add to the ticket
39+
if not stdin.isatty():
40+
body = stdin.read()
41+
# This is an interactive terminal, open a text editor
42+
else:
43+
body = click.edit('\n\n' + ticket.TEMPLATE_MSG)
2544
mgr.update_ticket(ticket_id=ticket_id, body=body)
2645
env.fout("Ticket Updated!")

SoftLayer/CLI/virt/detail.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from SoftLayer.CLI import environment
1010
from SoftLayer.CLI import formatting
1111
from SoftLayer.CLI import helpers
12-
from SoftLayer.CLI.virt.storage import get_local_type
12+
from SoftLayer.CLI.virt.storage import get_local_storage_table
1313
from SoftLayer import utils
1414

1515
LOGGER = logging.getLogger(__name__)
@@ -35,11 +35,7 @@ def cli(env, identifier, passwords=False, price=False):
3535
result = utils.NestedDict(result)
3636
local_disks = vsi.get_local_disks(vs_id)
3737

38-
table_local_disks = formatting.Table(['Type', 'Name', 'Capacity'])
39-
for disks in local_disks:
40-
if 'diskImage' in disks:
41-
table_local_disks.add_row([get_local_type(disks), disks['mountType'],
42-
str(disks['diskImage']['capacity']) + " " + str(disks['diskImage']['units'])])
38+
table_local_disks = get_local_storage_table(local_disks)
4339

4440
table.add_row(['id', result['id']])
4541
table.add_row(['guid', result['globalIdentifier']])
@@ -173,7 +169,7 @@ def _get_owner_row(result):
173169
owner = utils.lookup(result, 'billingItem', 'orderItem', 'order', 'userRecord', 'username')
174170
else:
175171
owner = formatting.blank()
176-
return(['owner', owner])
172+
return (['owner', owner])
177173

178174

179175
def _get_vlan_table(result):

SoftLayer/CLI/virt/list.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
@click.option('--hourly', is_flag=True, help='Show only hourly instances')
5353
@click.option('--monthly', is_flag=True, help='Show only monthly instances')
5454
@click.option('--transient', help='Filter by transient instances', type=click.BOOL)
55+
@click.option('--hardware', is_flag=True, default=False, help='Show the all VSI related to hardware')
56+
@click.option('--all-guests', is_flag=True, default=False, help='Show the all VSI and hardware VSIs')
5557
@helpers.multi_option('--tag', help='Filter by tags')
5658
@click.option('--sortby',
5759
help='Column to sort by',
@@ -69,7 +71,7 @@
6971
show_default=True)
7072
@environment.pass_env
7173
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network,
72-
hourly, monthly, tag, columns, limit, transient):
74+
hourly, monthly, tag, columns, limit, transient, hardware, all_guests):
7375
"""List virtual servers."""
7476

7577
vsi = SoftLayer.VSManager(env.client)
@@ -88,27 +90,29 @@ def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network,
8890

8991
table = formatting.Table(columns.columns)
9092
table.sortby = sortby
91-
for guest in guests:
92-
table.add_row([value or formatting.blank()
93-
for value in columns.row(guest)])
93+
if not hardware or all_guests:
94+
for guest in guests:
95+
table.add_row([value or formatting.blank()
96+
for value in columns.row(guest)])
9497

95-
env.fout(table)
98+
env.fout(table)
9699

97-
hardware_guests = vsi.get_hardware_guests()
98-
for hardware in hardware_guests:
99-
if hardware['virtualHost']['guests']:
100-
title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hardware['id'])
101-
table_hardware_guest = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status',
102-
'powerState'], title=title)
103-
table_hardware_guest.sortby = 'hostname'
104-
for guest in hardware['virtualHost']['guests']:
105-
table_hardware_guest.add_row([
106-
guest['id'],
107-
guest['hostname'],
108-
'%i %s' % (guest['maxCpu'], guest['maxCpuUnits']),
109-
guest['maxMemory'],
110-
utils.clean_time(guest['createDate']),
111-
guest['status']['keyName'],
112-
guest['powerState']['keyName']
113-
])
114-
env.fout(table_hardware_guest)
100+
if hardware or all_guests:
101+
hardware_guests = vsi.get_hardware_guests()
102+
for hd_guest in hardware_guests:
103+
if hd_guest['virtualHost']['guests']:
104+
title = "Hardware(id = {hardwareId}) guests associated".format(hardwareId=hd_guest['id'])
105+
table_hardware_guest = formatting.Table(['id', 'hostname', 'CPU', 'Memory', 'Start Date', 'Status',
106+
'powerState'], title=title)
107+
table_hardware_guest.sortby = 'hostname'
108+
for guest in hd_guest['virtualHost']['guests']:
109+
table_hardware_guest.add_row([
110+
guest['id'],
111+
guest['hostname'],
112+
'%i %s' % (guest['maxCpu'], guest['maxCpuUnits']),
113+
guest['maxMemory'],
114+
utils.clean_time(guest['createDate']),
115+
guest['status']['keyName'],
116+
guest['powerState']['keyName']
117+
])
118+
env.fout(table_hardware_guest)

SoftLayer/CLI/virt/storage.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ def cli(env, identifier):
4848
nas['allowedVirtualGuests'][0]['datacenter']['longName'],
4949
nas.get('notes', None)])
5050

51-
table_local_disks = formatting.Table(['Type', 'Name', 'Capacity'], title="Other storage details")
52-
for disks in local_disks:
53-
if 'diskImage' in disks:
54-
table_local_disks.add_row([get_local_type(disks), disks['mountType'],
55-
str(disks['diskImage']['capacity']) + " " + str(disks['diskImage']['units'])])
51+
table_local_disks = get_local_storage_table(local_disks)
52+
table_local_disks.title = "Other storage details"
5653

5754
env.fout(table_credentials)
5855
env.fout(table_iscsi)
@@ -64,10 +61,28 @@ def cli(env, identifier):
6461
def get_local_type(disks):
6562
"""Returns the virtual server local disk type.
6663
67-
:param disks: virtual serve local disks.
64+
:param disks: virtual server local disks.
6865
"""
6966
disk_type = 'System'
7067
if 'SWAP' in disks.get('diskImage', {}).get('description', []):
7168
disk_type = 'Swap'
7269

7370
return disk_type
71+
72+
73+
def get_local_storage_table(local_disks):
74+
"""Returns a formatting local disk table
75+
76+
:param local_disks: virtual server local disks.
77+
"""
78+
table_local_disks = formatting.Table(['Type', 'Name', 'Drive', 'Capacity'])
79+
for disk in local_disks:
80+
if 'diskImage' in disk:
81+
table_local_disks.add_row([
82+
get_local_type(disk),
83+
disk['mountType'],
84+
disk['device'],
85+
"{capacity} {unit}".format(capacity=disk['diskImage']['capacity'],
86+
unit=disk['diskImage']['units'])
87+
])
88+
return table_local_disks

SoftLayer/CLI/virt/upgrade.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020
help="CPU core will be on a dedicated host server.")
2121
@click.option('--memory', type=virt.MEM_TYPE, help="Memory in megabytes")
2222
@click.option('--network', type=click.INT, help="Network port speed in Mbps")
23+
@click.option('--add-disk', type=click.INT, multiple=True, required=False, help="add Hard disk in GB")
24+
@click.option('--resize-disk', nargs=2, multiple=True, type=(int, int),
25+
help="Update disk number to size in GB. --resize-disk 250 2 ")
2326
@click.option('--flavor', type=click.STRING,
2427
help="Flavor keyName\nDo not use --memory, --cpu or --private, if you are using flavors")
2528
@environment.pass_env
26-
def cli(env, identifier, cpu, private, memory, network, flavor):
29+
def cli(env, identifier, cpu, private, memory, network, flavor, add_disk, resize_disk):
2730
"""Upgrade a virtual server."""
2831

2932
vsi = SoftLayer.VSManager(env.client)
3033

31-
if not any([cpu, memory, network, flavor]):
32-
raise exceptions.ArgumentError("Must provide [--cpu], [--memory], [--network], or [--flavor] to upgrade")
34+
if not any([cpu, memory, network, flavor, resize_disk, add_disk]):
35+
raise exceptions.ArgumentError("Must provide [--cpu],"
36+
" [--memory], [--network], [--flavor], [--resize-disk], or [--add] to upgrade")
3337

3438
if private and not cpu:
3539
raise exceptions.ArgumentError("Must specify [--cpu] when using [--private]")
@@ -38,8 +42,19 @@ def cli(env, identifier, cpu, private, memory, network, flavor):
3842
if not (env.skip_confirmations or formatting.confirm("This action will incur charges on your account. Continue?")):
3943
raise exceptions.CLIAbort('Aborted')
4044

45+
disk_json = list()
4146
if memory:
4247
memory = int(memory / 1024)
43-
44-
if not vsi.upgrade(vs_id, cpus=cpu, memory=memory, nic_speed=network, public=not private, preset=flavor):
48+
if resize_disk:
49+
for guest_disk in resize_disk:
50+
disks = {'capacity': guest_disk[0], 'number': guest_disk[1]}
51+
disk_json.append(disks)
52+
53+
elif add_disk:
54+
for guest_disk in add_disk:
55+
disks = {'capacity': guest_disk, 'number': -1}
56+
disk_json.append(disks)
57+
58+
if not vsi.upgrade(vs_id, cpus=cpu, memory=memory, nic_speed=network, public=not private, preset=flavor,
59+
disk=disk_json):
4560
raise exceptions.CLIAbort('VS Upgrade Failed')

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88
'id': 6327,
99
'nextInvoiceTotalRecurringAmount': 1.54,
1010
'children': [
11-
{'nextInvoiceTotalRecurringAmount': 1},
12-
{'nextInvoiceTotalRecurringAmount': 1},
13-
{'nextInvoiceTotalRecurringAmount': 1},
14-
{'nextInvoiceTotalRecurringAmount': 1},
15-
{'nextInvoiceTotalRecurringAmount': 1},
11+
{'categoryCode': 'port_speed',
12+
'nextInvoiceTotalRecurringAmount': 1},
13+
{'categoryCode': 'guest_core',
14+
'nextInvoiceTotalRecurringAmount': 1},
15+
{'categoryCode': 'ram',
16+
'nextInvoiceTotalRecurringAmount': 1},
17+
{'categoryCode': 'guest_core',
18+
'nextInvoiceTotalRecurringAmount': 1},
19+
{'categoryCode': 'guest_disk1',
20+
'nextInvoiceTotalRecurringAmount': 1},
1621
],
1722
'package': {
1823
"id": 835,
@@ -622,7 +627,35 @@
622627
'capacity': '2',
623628
'description': 'RAM',
624629
}
625-
},
630+
}, {
631+
"id": 2255,
632+
"categories": [
633+
{
634+
"categoryCode": "guest_disk1",
635+
"id": 82,
636+
"name": "Second Disk"
637+
},
638+
{
639+
"categoryCode": "guest_disk2",
640+
"id": 92,
641+
"name": "Third Disk"
642+
},
643+
{
644+
"categoryCode": "guest_disk3",
645+
"id": 93,
646+
"name": "Fourth Disk"
647+
},
648+
{
649+
"categoryCode": "guest_disk4",
650+
"id": 116,
651+
"name": "Fifth Disk"
652+
}
653+
],
654+
"item": {
655+
"capacity": "10",
656+
"description": "10 GB (SAN)"
657+
}
658+
}
626659
]
627660

628661
DEDICATED_GET_UPGRADE_ITEM_PRICES = [
@@ -641,7 +674,6 @@
641674

642675
getMetricTrackingObjectId = 1000
643676

644-
645677
getBandwidthAllotmentDetail = {
646678
'allocationId': 25465663,
647679
'bandwidthAllotmentId': 138442,

0 commit comments

Comments
 (0)