Ejemplo n.º 1
0
def quotes(args):
    """Show quotes

    Usage: slapi billing quotes [options] [<quote_spec>]

    Options:
        -F, --format FORMAT
        -h, --help
    """
    # Parse quote_spec
    quote_spec = parse_quote_spec(args['<quote_spec>'])
    # TODO: Build Object Mask
    object_mask = None

    for quote in get_quotes(quote_spec, object_mask):
        print quote.format()
Ejemplo n.º 2
0
def quotes(args):
    """Show quotes

    Usage: slapi billing quotes [options] [<quote_spec>]

    Options:
        -F, --format FORMAT
        -h, --help
    """
    # Parse quote_spec
    quote_spec = parse_quote_spec(args['<quote_spec>'])
    # TODO: Build Object Mask
    object_mask = None

    for quote in get_quotes(quote_spec, object_mask):
        print quote.format()
Ejemplo n.º 3
0
def orderquote(args):
    """Place an order from an existing quote

    Usage: slapi billing orderquote [options] <quote_spec> <hostname> <domain>

    Options:
        --network-public-vlan VLAN_SPEC
        --network-private-vlan VLAN_SPEC
        -h, --help
    """
    # Parse Quote Spec
    quote_spec = parse_quote_spec(args['<quote_spec>'])
    # TODO: Build Object Mask
    object_mask = None

    # Get Quotes
    quotelist = list(get_quotes(quote_spec, object_mask))
    if len(quotelist) < 1:
        print warning("No quotes found matching spec: %s." % (
            args['<quote_spec>']))
        sys.exit(1)
    if len(quotelist) > 1:
        print error("More then one quote matching spec: %s. "
                    "Refusing to continue." % args['<quote_spec>'])
        sys.exit(1)

    # Get Quote
    quote = quotelist[0]
    log.debug("found quote: %d, name: %s, key: %s", quote.id,
              quote.name,
              quote.key)

    # Get Orders Containers
    order_containers = list(_get_quote_product_orders(quote.id, None))
    if len(order_containers) < 0:
        print error("Quote %d contains no product orders." % (quote.id))
        sys.exit(1)
    if len(order_containers) > 1:
        print error("Quote %d contains more then one product orders."
                    "Refusing to continue." % (quote.id))
        sys.exit(1)
    order_container = order_containers[0]

    # Get VLAN information
    if args['--network-public-vlan']:
        public_vlan = _find_vlan('public', args['--network-public-vlan'])
    else:
        public_vlan = None
    if args['--network-private-vlan']:
        private_vlan = _find_vlan('private', args['--network-private-vlan'])
    else:
        private_vlan = None

    # Check public vlan location
    if public_vlan and \
            public_vlan.primary_router.datacenter.id != order_container.location.id:
        print error("Public VLAN %d does not appear to be in %s." % (
            public_vlan.vlan, order_container.location.name))
        sys.exit(1)

    # Check private vlan location
    if private_vlan and \
            private_vlan.primary_router.datacenter.id != order_container.location.id:
        print error("Private VLAN %d does not appear to be in %s." % (
            public_vlan.vlan, order_container.location.name))
        sys.exit(1)

    # Set order type
    order_container._data['complexType'] = \
        'SoftLayer_Container_Product_Order_Hardware_Server'

    # Get order hardware
    hardware = order_container._data['hardware'][0]

    # Update order information
    hardware['hostname'] = args['<hostname>']
    hardware['domain'] = args['<domain>']

    # Configure VLANs
    if public_vlan:
        hardware['primaryNetworkComponent']['networkVlanId'] = \
            public_vlan.id
    if private_vlan:
        hardware['primaryBackendNetworkComponent']['networkVlanId'] = \
            private_vlan.id

    # Verify order
    _verify_order(quote.id, order_container)

    # Print Order Information

    print colored("Quote:", fg='green', style='bright')
    print quote.format()

    server_name = ".".join([args['<hostname>'], args['<domain>']])
    print colored("Public VLAN:", fg='green', style='bright')
    if public_vlan:
        print public_vlan.format()
    else:
        print "Default"
    print colored("Private VLAN:", fg='green', style='bright')
    if private_vlan:
        print private_vlan.format()
    else:
        print "Default"

    print colored("Order:", fg='green', style='bright')
    print order_container.format()

    print critical("You are about to order a server: %s." % (server_name),
                   label="WARNING: ")
    print critical("Monthly Cost: %s %s, Setup Cost: %s %s" % (
        order_container.currency_type,
        order_container.post_tax_recurring_charge,
        order_container.currency_type,
        order_container.post_tax_setup_charge), label="WARNING: ")
    if confirm(colored("Are you sure you want to continue?",
                       fg='red',
                       style='bright')):
        # Place Order
        _place_order(quote.id, order_container)
        print colored("Order Placed", fg='green', style='bright')
        return
Ejemplo n.º 4
0
def orderquote(args):
    """Place an order from an existing quote

    Usage: slapi billing orderquote [options] <quote_spec> <hostname> <domain>

    Options:
        --network-public-vlan VLAN_SPEC
        --network-private-vlan VLAN_SPEC
        -h, --help
    """
    # Parse Quote Spec
    quote_spec = parse_quote_spec(args['<quote_spec>'])
    # TODO: Build Object Mask
    object_mask = None

    # Get Quotes
    quotelist = list(get_quotes(quote_spec, object_mask))
    if len(quotelist) < 1:
        print warning("No quotes found matching spec: %s." %
                      (args['<quote_spec>']))
        sys.exit(1)
    if len(quotelist) > 1:
        print error("More then one quote matching spec: %s. "
                    "Refusing to continue." % args['<quote_spec>'])
        sys.exit(1)

    # Get Quote
    quote = quotelist[0]
    log.debug("found quote: %d, name: %s, key: %s", quote.id, quote.name,
              quote.key)

    # Get Orders Containers
    order_containers = list(_get_quote_product_orders(quote.id, None))
    if len(order_containers) < 0:
        print error("Quote %d contains no product orders." % (quote.id))
        sys.exit(1)
    if len(order_containers) > 1:
        print error("Quote %d contains more then one product orders."
                    "Refusing to continue." % (quote.id))
        sys.exit(1)
    order_container = order_containers[0]

    # Get VLAN information
    if args['--network-public-vlan']:
        public_vlan = _find_vlan('public', args['--network-public-vlan'])
    else:
        public_vlan = None
    if args['--network-private-vlan']:
        private_vlan = _find_vlan('private', args['--network-private-vlan'])
    else:
        private_vlan = None

    # Check public vlan location
    if public_vlan and \
            public_vlan.primary_router.datacenter.id != order_container.location.id:
        print error("Public VLAN %d does not appear to be in %s." %
                    (public_vlan.vlan, order_container.location.name))
        sys.exit(1)

    # Check private vlan location
    if private_vlan and \
            private_vlan.primary_router.datacenter.id != order_container.location.id:
        print error("Private VLAN %d does not appear to be in %s." %
                    (public_vlan.vlan, order_container.location.name))
        sys.exit(1)

    # Set order type
    order_container._data['complexType'] = \
        'SoftLayer_Container_Product_Order_Hardware_Server'

    # Get order hardware
    hardware = order_container._data['hardware'][0]

    # Update order information
    hardware['hostname'] = args['<hostname>']
    hardware['domain'] = args['<domain>']

    # Configure VLANs
    if public_vlan:
        hardware['primaryNetworkComponent']['networkVlanId'] = \
            public_vlan.id
    if private_vlan:
        hardware['primaryBackendNetworkComponent']['networkVlanId'] = \
            private_vlan.id

    # Verify order
    _verify_order(quote.id, order_container)

    # Print Order Information

    print colored("Quote:", fg='green', style='bright')
    print quote.format()

    server_name = ".".join([args['<hostname>'], args['<domain>']])
    print colored("Public VLAN:", fg='green', style='bright')
    if public_vlan:
        print public_vlan.format()
    else:
        print "Default"
    print colored("Private VLAN:", fg='green', style='bright')
    if private_vlan:
        print private_vlan.format()
    else:
        print "Default"

    print colored("Order:", fg='green', style='bright')
    print order_container.format()

    print critical("You are about to order a server: %s." % (server_name),
                   label="WARNING: ")
    print critical(
        "Monthly Cost: %s %s, Setup Cost: %s %s" %
        (order_container.currency_type,
         order_container.post_tax_recurring_charge,
         order_container.currency_type, order_container.post_tax_setup_charge),
        label="WARNING: ")
    if confirm(
            colored("Are you sure you want to continue?",
                    fg='red',
                    style='bright')):
        # Place Order
        _place_order(quote.id, order_container)
        print colored("Order Placed", fg='green', style='bright')
        return