Ejemplo n.º 1
0
def available(args, flags):
    reply = centarra('/vps/signup')
    for i in reply['regions']:
        sub(i['name'], i['id'])
    for i in reply['resource_plans']:
        sub(i['name'], i['id'])
    if args[0] == "regions":
        return JsonResponse(reply['regions'], '\r\n'.join(["(%s): %s" % (i['id'], i['name']) for i in reply['regions']]))
    else:
        rpl = []
        for i in reply['resource_plans']:
            rpl.append(("({id}) '{name}' - ${price_usd}" + (" ({price_btc} BTC)" if 'b' in flags else "") + "."
                       + ("\tIPv4 limit {ipv4_limit}, IPv6 limit {ipv6_limit}" if "l" in flags else "")
                       + ("\tSwap {swap}mb" if 'S' in flags else "")
                       + ("\tMemory {memory}mb" if 'M' in flags else "")
                       + ("\tDisk {disk}gb" if 'D' in flags else "")
            ).format(**i))
        return JsonResponse(reply, '\r\n'.join(rpl))
Ejemplo n.º 2
0
def list(args, flags):
    reply = centarra('/vps/list')
    for i in reply['vpslist']:
        sub(i['name'], i['id'])
        sub(i['nickname'], i['id'])
    rpl = []
    for i in reply['vpslist']:
        st = '\t{id}: {name} ("{nickname}") on {node}\t\t' + \
             ("IPv6 limit {ipv6_limit}, IPv4 limit {ipv4_limit}\t" if 'l' in flags else '') + \
             ("{cpu_sla} CPU SLA\t" if 's' in flags else '') + \
             ((("IPs: " + ", ".join([j['ip'] for j in i['ips']])) + "\t") if 'i' in flags else '') + \
             ("MAC address {mac}\t" if 'm' in flags else '') + \
             ("Owned by {user}\t" if 'u' in flags else '') + \
             ("Monitoring {monitoring} enabled\t".format(monitoring="is" if i['monitoring'] else "is not") if 'w' in flags else '') + \
             ("{memory}mb memory\t" if 'M' in flags else '') + \
             ("{swap}mb swap\t" if 'S' in flags else '') + \
             ("{disk}gb disk\t" if "D" in flags else '')
        rpl.append(st.format(**i))

    rpl = '\r\n'.join(rpl)
    return JsonResponse(reply, "Your current vServers: \r\n%s" % rpl)
Ejemplo n.º 3
0
def signup(args, flags):
    reply = centarra('/vps/signup', plan=args[0], region=args[1])
    sub(reply['name'], reply['id'], False)
    return JsonResponse(reply, "Your new vps is now named {name} (#{id}) on node {node}. Deploy it with `vps deploy'!"
                                                .format(**reply['service']))
Ejemplo n.º 4
0
def templates(args, flags):
    reply = centarra('/vps/%s/deploy' % args[0])
    for i in reply['templates']:
        sub(reply['templates'][i]['name'], i)
    return JsonResponse(reply, "Templates:\r\n" + '\r\n'.join(["\t%s = %s" % (i, reply['templates'][i]['name']) for i in reply['templates']]))