Exemplo n.º 1
0
def cli(env, is_open):
    """List tickets."""
    ticket_mgr = SoftLayer.TicketManager(env.client)

    tickets = ticket_mgr.list_tickets(open_status=is_open,
                                      closed_status=not is_open)

    table = formatting.Table(['id', 'assigned_user', 'title',
                              'last_edited', 'status'])

    for ticket in tickets:
        user = formatting.blank()
        if ticket.get('assignedUser'):
            user = "******" % (ticket['assignedUser']['firstName'],
                              ticket['assignedUser']['lastName'])

        table.add_row([
            ticket['id'],
            user,
            click.wrap_text(ticket['title']),
            ticket['lastEditDate'],
            ticket['status']['name'],
        ])

    env.fout(table)
Exemplo n.º 2
0
def cli(env, identifier, count):
    """Get details for a ticket."""

    mgr = SoftLayer.TicketManager(env.client)

    ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')
    env.fout(ticket.get_ticket_results(mgr, ticket_id, update_count=count))
Exemplo n.º 3
0
def cli(env, identifier, body):
    """Adds an update to an existing ticket.

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

        slcli ticket update 123456 --body="Some text"

Will update the ticket with text from STDIN::

        cat sometfile.txt | slcli ticket update 123456

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

        slcli ticket update 123456
    """
    mgr = SoftLayer.TicketManager(env.client)

    ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')
    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)
    mgr.update_ticket(ticket_id=ticket_id, body=body)
    env.fout("Ticket Updated!")
Exemplo n.º 4
0
    def execute(self, args):
        ticket_mgr = SoftLayer.TicketManager(self.client)

        tickets = ticket_mgr.list_tickets(open_status=not args.get('--closed'),
                                          closed_status=args.get('--closed'))

        table = formatting.Table([
            'id', 'assigned user', 'title', 'creation date', 'last edit date'
        ])

        for ticket in tickets:
            if ticket['assignedUser']:
                table.add_row([
                    ticket['id'],
                    "%s %s" % (ticket['assignedUser']['firstName'],
                               ticket['assignedUser']['lastName']),
                    wrap_string(ticket['title']), ticket['createDate'],
                    ticket['lastEditDate']
                ])
            else:
                table.add_row([
                    ticket['id'], 'N/A',
                    wrap_string(ticket['title']), ticket['createDate'],
                    ticket['lastEditDate']
                ])

        return table
Exemplo n.º 5
0
    def execute(self, args):
        ticket_mgr = SoftLayer.TicketManager(self.client)

        table = formatting.Table(['id', 'subject'])
        for subject in ticket_mgr.list_subjects():
            table.add_row([subject['id'], subject['name']])
        return table
Exemplo n.º 6
0
def cli(env, title, subject_id, body, hardware_identifier, virtual_identifier,
        priority):
    """Create a support ticket."""
    ticket_mgr = SoftLayer.TicketManager(env.client)

    if body is None:
        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']))
Exemplo n.º 7
0
def cli(env):
    """List Subject IDs for ticket creation."""
    ticket_mgr = SoftLayer.TicketManager(env.client)

    table = formatting.Table(['id', 'subject'])
    for subject in ticket_mgr.list_subjects():
        table.add_row([subject['id'], subject['name']])

    env.fout(table)
Exemplo n.º 8
0
    def execute(self, args):
        mgr = SoftLayer.TicketManager(self.client)

        ticket_id = helpers.resolve_id(mgr.resolve_ids,
                                       args.get('<identifier>'), 'ticket')

        count = args.get('--count')
        if count is None:
            count = 10
        return get_ticket_results(mgr, ticket_id, update_count=int(count))
Exemplo n.º 9
0
    def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate=False):
        """Cancels the specified dedicated server.

        Example::

            # Cancels hardware id 1234
            result = mgr.cancel_hardware(hardware_id=1234)

        :param int hardware_id: The ID of the hardware to be cancelled.
        :param string reason: The reason code for the cancellation. This should come from
                              :func:`get_cancellation_reasons`.
        :param string comment: An optional comment to include with the cancellation.
        :param bool immediate: If set to True, will automatically update the cancelation ticket to request
                               the resource be reclaimed asap. This request still has to be reviewed by a human
        :returns: True on success or an exception
        """

        # Get cancel reason
        reasons = self.get_cancellation_reasons()
        cancel_reason = reasons.get(reason, reasons['unneeded'])
        ticket_mgr = SoftLayer.TicketManager(self.client)
        mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id], activeTransaction]'
        hw_billing = self.get_hardware(hardware_id, mask=mask)

        if 'activeTransaction' in hw_billing:
            raise SoftLayer.SoftLayerError("Unable to cancel hardware with running transaction")

        if 'billingItem' not in hw_billing:
            if utils.lookup(hw_billing, 'openCancellationTicket', 'id'):
                raise SoftLayer.SoftLayerError("Ticket #%s already exists for this server" %
                                               hw_billing['openCancellationTicket']['id'])
            raise SoftLayer.SoftLayerError("Cannot locate billing for the server. "
                                           "The server may already be cancelled.")

        billing_id = hw_billing['billingItem']['id']

        if immediate and not hw_billing['hourlyBillingFlag']:
            LOGGER.warning("Immediate cancellation of monthly servers is not guaranteed."
                           "Please check the cancellation ticket for updates.")

            result = self.client.call('Billing_Item', 'cancelItem',
                                      False, False, cancel_reason, comment, id=billing_id)
            hw_billing = self.get_hardware(hardware_id, mask=mask)
            ticket_number = hw_billing['openCancellationTicket']['id']
            cancel_message = "Please reclaim this server ASAP, it is no longer needed. Thankyou."
            ticket_mgr.update_ticket(ticket_number, cancel_message)
            LOGGER.info("Cancelation ticket #%s has been updated requesting immediate reclaim", ticket_number)
        else:
            result = self.client.call('Billing_Item', 'cancelItem',
                                      immediate, False, cancel_reason, comment, id=billing_id)
            hw_billing = self.get_hardware(hardware_id, mask=mask)
            ticket_number = hw_billing['openCancellationTicket']['id']
            LOGGER.info("Cancelation ticket #%s has been created", ticket_number)

        return result
Exemplo n.º 10
0
def cli(env, identifier, count):
    """Get details for a ticket."""

    is_json = False
    if (env.format == 'json'):
        is_json = True
    mgr = SoftLayer.TicketManager(env.client)

    ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')
    env.fout(
        ticket.get_ticket_results(mgr, ticket_id, is_json, update_count=count))
Exemplo n.º 11
0
def cli(env, title, subject_id, body):
    """Create a support ticket."""
    mgr = SoftLayer.TicketManager(env.client)

    if body is None:
        body = click.edit('\n\n' + ticket.TEMPLATE_MSG)

    created_ticket = mgr.create_ticket(title=title,
                                       body=body,
                                       subject=subject_id)
    return ticket.get_ticket_results(mgr, created_ticket['id'])
Exemplo n.º 12
0
def cli(env, identifier, body):
    """Adds an update to an existing ticket."""
    mgr = SoftLayer.TicketManager(env.client)

    ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')

    if body is None:
        body = click.edit('\n\n' + ticket.TEMPLATE_MSG)

    mgr.update_ticket(ticket_id=ticket_id, body=body)
    env.fout("Ticket Updated!")
Exemplo n.º 13
0
    def execute(self, args):
        mgr = SoftLayer.TicketManager(self.client)
        if args.get('--title') is "":
            return 'Please provide a valid title'
        body = args.get('--body')
        if body is None:
            body = open_editor(beg_msg=TEMPLATE_MSG)

        created_ticket = mgr.create_ticket(title=args.get('--title'),
                                           body=body,
                                           subject=args.get('--subject'))
        return get_ticket_results(mgr, created_ticket['id'])
Exemplo n.º 14
0
    def execute(self, args):
        mgr = SoftLayer.TicketManager(self.client)

        ticket_id = helpers.resolve_id(mgr.resolve_ids,
                                       args.get('<identifier>'), 'ticket')

        body = args.get('--body')
        if body is None:
            body = open_editor(beg_msg=TEMPLATE_MSG)

        mgr.update_ticket(ticket_id=ticket_id, body=body)
        return "Ticket Updated!"
Exemplo n.º 15
0
def cli(env, identifier, hardware_identifier, virtual_identifier):
    """Detach devices from a ticket."""
    ticket_mgr = SoftLayer.TicketManager(env.client)

    if hardware_identifier and virtual_identifier:
        raise exceptions.ArgumentError("Cannot detach hardware and a virtual server at the same time")

    if hardware_identifier:
        hardware_mgr = SoftLayer.HardwareManager(env.client)
        hardware_id = helpers.resolve_id(hardware_mgr.resolve_ids, hardware_identifier, 'hardware')
        ticket_mgr.detach_hardware(identifier, hardware_id)
    elif virtual_identifier:
        vs_mgr = SoftLayer.VSManager(env.client)
        vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS')
        ticket_mgr.detach_virtual_server(identifier, vs_id)
    else:
        raise exceptions.ArgumentError("Must have a hardware or virtual server identifier to detach")
Exemplo n.º 16
0
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']))
Exemplo n.º 17
0
def cli(env, identifier, path, name):
    """Adds an attachment to an existing ticket."""
    mgr = SoftLayer.TicketManager(env.client)

    ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')

    if path is None:
        raise exceptions.ArgumentError("Missing argument --path")

    if not os.path.exists(path):
        raise exceptions.ArgumentError("%s not exist" % path)

    if name is None:
        name = os.path.basename(path)

    attached_file = mgr.upload_attachment(ticket_id=ticket_id,
                                          file_path=path,
                                          file_name=name)
    env.fout("File attached: \n%s" % attached_file)
Exemplo n.º 18
0
def cli(env, is_open):
    """List tickets."""
    ticket_mgr = SoftLayer.TicketManager(env.client)

    tickets = ticket_mgr.list_tickets(open_status=not is_open,
                                      closed_status=is_open)

    table = formatting.Table(
        ['id', 'assigned user', 'title', 'creation date', 'last edit date'])

    for ticket in tickets:
        user = '******'
        if ticket.get('assignedUser'):
            user = "******" % (ticket['assignedUser']['firstName'],
                              ticket['assignedUser']['lastName']),

        table.add_row([
            ticket['id'], user,
            click.wrap_text(ticket['title']), ticket['createDate'],
            ticket['lastEditDate']
        ])

    return table
Exemplo n.º 19
0
 def set_up(self):
     self.ticket = SoftLayer.TicketManager(self.client)
Exemplo n.º 20
0
 def set_up(self):
     self.client = testing.FixtureClient()
     self.ticket = SoftLayer.TicketManager(self.client)