コード例 #1
0
ファイル: hardware.py プロジェクト: cloudant/slapi
def osreload(args):
    """Execute OS reload

    Usage: slapi hardware osreload [options] [<hardware_spec>]

    Options:
        -c, --confirm TOKEN
        -h, --help
    """
    # Parse Arguments
    hardware_spec = parse_hardware_spec(args)

    # Get Hardware
    hardware = list(_get_hardware(hardware_spec, None))
    if not hardware:
        print warning("No objects found matching spec: %s." %
                     (args['<hardware_spec>']))
        return

    # Refuse hardware_specs that match more then one host
    if len(hardware) > 1:
        print error("More then one object matching spec: %s. "
                    "Refusing to continue." % (args['<hardware_spec>']))
        sys.exit(1)

    # Get server object
    server = hardware[0]

    # Get hardware service
    service = get_service('SoftLayer_Hardware_Server', server.id)

    confirmation_token = args['--confirm']

    # Check for confirmation_token option
    if confirmation_token is None:
        # Prompt for confirmation
        print critical("You are about to issue an OS reload on %s." %
                      (server.fqdn), label="WARNING: ")
        print critical("This will destroy all data on the device.",
                       label="WARNING: ")
        if confirm(colored("Are you sure you want to continue?",
                           fg='red', style='bright')):
            token = service.reloadCurrentOperatingSystemConfiguration()
            print "OS reload issued, confirm with token: %s" % (token)
            return

    else:
        # Prompt for confirmation
        print critical("You are about to confirm an OS reload on %s." %
                      (server.fqdn), label="WARNING: ")
        print critical("This will destroy all data on the device.",
                       label="WARNING: ")
        print critical("This is your last chance to abort.", label="WARNING: ")
        if confirm(colored("Are you sure you want to continue?",
                           fg='red', style='bright')):
            service.reloadCurrentOperatingSystemConfiguration(
                token=confirmation_token)
            print "OS Reload Started on %s" % (server.fqdn)
            return
コード例 #2
0
ファイル: billing.py プロジェクト: cloudant/slapi
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
コード例 #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