コード例 #1
0
def purchase_choice_vpn(config):
    provider = plebnet_settings.get_instance().vpn_host()

    provider_instance = get_vpn_providers()[provider](child_account())

    # no need to generate new child config

    wallet = TriblerWallet(
        plebnet_settings.get_instance().wallets_testnet_created())
    c = cloudomate_providers['vpn'][provider]

    configurations = c.get_options()
    # option is assumbed to be the first vpn provider option
    option = configurations[0]

    transaction_hash = provider_instance.purchase(wallet, option)

    if not transaction_hash:
        logger.warning("Failed to purchase vpn")
        return plebnet_settings.FAILURE
    if False:
        logger.warning("Insufficient funds to purchase server")
        return plebnet_settings.UNKNOWN

    config.get('bought').append(
        (provider, transaction_hash, config.get('child_index')))
    config.get('transactions').append(transaction_hash)
    config.save()

    return plebnet_settings.SUCCESS
コード例 #2
0
def purchase_choice_vpn(config):
    provider = plebnet_settings.get_instance().vpn_host()

    provider_instance = get_vpn_providers()[provider](child_account())

    # no need to generate new child config

    wallet = TriblerWallet(plebnet_settings.get_instance().wallets_testnet_created())
    c = cloudomate_providers['vpn'][provider]

    configurations = c.get_options()
    # option is assumbed to be the first vpn provider option
    option = configurations[0]

    try:
        transaction_hash = provider_instance.purchase(wallet, option)
    except:
        title = "Failed to purchase vpn: %s" % sys.exc_info()[0]
        body = traceback.format_exc()
        logger.error(title)
        logger.error(body)
        git_issuer.handle_error(title, body)
        git_issuer.handle_error("Failed to purchase server", sys.exc_info()[0], ['crash'])
        return plebnet_settings.FAILURE

    if not transaction_hash:
        logger.warning("VPN probably purchased, but transaction hash not returned")

    config.get('bought').append((provider, option, transaction_hash, config.get('child_index')))
    config.get('transactions').append(transaction_hash)
    config.save()

    return plebnet_settings.SUCCESS
コード例 #3
0
def purchase_choice(config):
    """
    Purchase the cheapest provider in chosen_providers. If buying is successful this provider is
    moved to bought. In any case the provider is removed from choices.
    :param config: config
    :return: plebnet_settings errorcode
    """

    (provider, option, _) = config.get('chosen_provider')
    provider_instance = cloudomate_providers['vps'][provider](child_account())

    wallet = TriblerWallet(
        plebnet_settings.get_instance().wallets_testnet_created())

    vps_option = get_vps_option(provider, option)
    try:
        transaction_hash = provider_instance.purchase(wallet, vps_option)
    except:
        title = "Failed to purchase server: %s" % sys.exc_info()[0]
        body = traceback.format_exc()
        logger.error(title)
        logger.error(body)
        git_issuer.handle_error(title, body)
        git_issuer.handle_error("Failed to purchase server",
                                sys.exc_info()[0], ['crash'])
        return plebnet_settings.FAILURE

    # Cloudomate should throw an exception when purchase fails. The transaction hash is not in fact required,
    # and even when cloudomate fails to return it, the purchase itself could have been successful.
    if not transaction_hash:
        logger.warning(
            "Server probably purchased, but transaction hash not returned")

    config.get('bought').append(
        (provider, option, transaction_hash, config.get('child_index')))
    config.get('transactions').append(transaction_hash)
    config.set('chosen_provider', None)
    config.save()

    return plebnet_settings.SUCCESS
コード例 #4
0
def purchase_choice(config):
    """
    Purchase the cheapest provider in chosen_providers. If buying is successful this provider is
    moved to bought. In any case the provider is removed from choices.
    :param config: config
    :return: plebnet_settings errorcode
    """

    (provider, option, _) = config.get('chosen_provider')
    provider_instance = cloudomate_providers['vps'][provider](child_account())

    wallet = TriblerWallet(
        plebnet_settings.get_instance().wallets_testnet_created())
    c = cloudomate_providers['vps'][provider]

    configurations = c.get_options()
    option = configurations[option]

    try:
        transaction_hash = provider_instance.purchase(wallet, option)
    except:
        title = "Failed to purchase server: %s" % sys.exc_info()[0]
        body = traceback.format_exc()
        logger.error(title)
        logger.error(body)
        git_issuer.handle_error(title, body)
        git_issuer.handle_error("Failed to purchase server",
                                sys.exc_info()[0], ['crash'])
        return plebnet_settings.FAILURE

    if not transaction_hash:
        return plebnet_settings.FAILURE
    config.get('bought').append(
        (provider, transaction_hash, config.get('child_index')))
    config.get('transactions').append(transaction_hash)
    config.set('chosen_provider', None)
    config.save()

    return plebnet_settings.SUCCESS
コード例 #5
0
def purchase_choice(config):
    """
    Purchase the cheapest provider in chosen_providers. If buying is successful this provider is moved to bought. In any
    case the provider is removed from choices.
    :param config: config
    :return: success
    """

    (provider, option, _) = config.get('chosen_provider')

    provider_instance = cloudomate_providers['vps'][provider](child_account())
    PlebNetConfig().increment_child_index()
    fake_generator.generate_child_account()

    wallet = TriblerWallet(
        plebnet_settings.get_instance().wallets_testnet_created())
    c = cloudomate_providers['vps'][provider]

    configurations = c.get_options()
    option = configurations[option]

    transaction_hash, _ = provider_instance.purchase(wallet, option)

    if not transaction_hash:
        logger.warning("Failed to purchase server")
        return plebnet_settings.FAILURE
    # TODO: how to spot the difference?
    if False:
        logger.warning("Insufficient funds to purchase server")
        return plebnet_settings.UNKNOWN

    config.get('bought').append(
        (provider, transaction_hash, config.get('child_index') - 1))
    config.get('transactions').append(transaction_hash)
    config.set('chosen_provider', None)
    config.save()

    return plebnet_settings.SUCCESS