File: create.py

package info (click to toggle)
python-softlayer 6.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,508 kB
  • sloc: python: 57,195; makefile: 133; xml: 97; sh: 59
file content (66 lines) | stat: -rw-r--r-- 2,824 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
"""Create a support ticket."""
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import helpers
from SoftLayer.CLI import ticket


@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.option('--title', required=True, help="The title of the ticket")
@click.option('--subject-id', type=int, required=True,
              help="""The subject id to use for the ticket, run 'slcli ticket subjects' to get the list""")
@click.option('--body', help="The ticket body")
@click.option('--hardware', 'hardware_identifier',
              help="The identifier for hardware to attach")
@click.option('--virtual', 'virtual_identifier',
              help="The identifier for a virtual server to attach")
@click.option('--priority', 'priority', type=click.Choice(['1', '2', '3', '4']), default=None,
              help="""Ticket priority, from 1 (Critical) to 4 (Minimal Impact).
              Only settable with Advanced and Premium support. See https://www.ibm.com/cloud/support""")
@environment.pass_env
def cli(env, title, subject_id, body, hardware_identifier, virtual_identifier, priority):
    """Create a Infrastructure support ticket.

    Will create the ticket with `Some text`.::

        slcli ticket create --body="Some text" --subject-id 1522 --hardware 12345 --title "My New Ticket"

    Will create the ticket with text from STDIN::

        cat sometfile.txt | slcli ticket create --subject-id 1003 --virtual 111111 --title "Reboot Me"

    Will open the default text editor, and once closed, use that text to create the ticket::

        slcli ticket create --subject-id 1482 --title "Vyatta Questions..."

    """
    ticket_mgr = SoftLayer.TicketManager(env.client)
    if body is None:
        stdin = click.get_text_stream('stdin')
        # Means there is text on the STDIN buffer, read it and add to the ticket
        if not stdin.isatty():
            body = stdin.read()
        # This is an interactive terminal, open a text editor
        else:
            body = click.edit('\n\n' + ticket.TEMPLATE_MSG)
    created_ticket = ticket_mgr.create_ticket(
        title=title,
        body=body,
        subject=subject_id,
        priority=priority)

    if hardware_identifier:
        hardware_mgr = SoftLayer.HardwareManager(env.client)
        hardware_id = helpers.resolve_id(hardware_mgr.resolve_ids, hardware_identifier, 'hardware')
        ticket_mgr.attach_hardware(created_ticket['id'], hardware_id)

    if virtual_identifier:
        vs_mgr = SoftLayer.VSManager(env.client)
        vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS')
        ticket_mgr.attach_virtual_server(created_ticket['id'], vs_id)

    env.fout(ticket.get_ticket_results(ticket_mgr, False, created_ticket['id']))