예제 #1
0
def add_record(args, flags):
    if args[1] == "valid":
        reply = centarra('/dns/zone/%s/record/new' % substitutes.swap("dns zones", args[0]))
        return JsonResponse(reply, "Available records: " + ', '.join(reply['record_types']))
    else:  # id subdomain type content
        send = {"subdomain": args[1], "type": args[2], "content": args[3], 'ttl': flags.get('t', 300),
                "prio": flags.get('p', 0)}
        reply = centarra("/dns/zone/%s/record/new" % substitutes.swap("dns zones", args[0]), **send)
        return JsonResponse(reply, flashed("{subdomain}{dot}{domain} was set as {type} to {content}."
                                   + ("\tTTL = {ttl}" if 't' in flags else "")
                                   + ("\tPriority = {prio}" if 'p' in flags else "").format(
                        dot="." if send['subdomain'] is not "" else "",
                        domain=reply['zone']['name'],
                        **send))
        )
예제 #2
0
def delete(args, flags):
    print("Are you sure you would like to delete your vServer {} (#{})?".format(args[0], substitutes.swap("vps list", args[0])))
    line = raw_input('[N/y]: ')
    if line == "y":
        reply = centarra("/vps/%s/delete" % substitutes.swap("vps list", args[0]))
        return JsonResponse(reply, flashed())
    return "Aborted."
예제 #3
0
def update_dns_zones():
    if not needs_update('dns zones'):
        return
    substitutes.data['dns zones'] = {}
    reply = centarra('/dns/zones')
    for zone in reply['zones']:
        substitutes.sub('dns zones', zone['name'], zone['id'])
예제 #4
0
def update_templates_list(arg):
    if not needs_update("vps templates"):
        return
    substitutes.data['vps templates'] = {}
    reply = centarra('/vps/%s/deploy' % substitutes.swap("vps list", substitutes.swap("vps list", arg)))
    for i in reply['templates']:
        substitutes.sub('vps templates', reply['templates'][i]['name'], i)
예제 #5
0
def update_vps_list():
    if not needs_update('vps list'):
        return
    substitutes.data['vps list'] = {}
    reply = centarra('/vps/list')
    for i in reply['vpslist']:
        substitutes.sub('vps list', i['name'], i['id'])
        substitutes.sub('vps list', i['nickname'], i['id'])
예제 #6
0
def login_preferences(args, flags):
    preferences = {
        'fail': 1 if 'f' in flags else 0,
        'success': 1 if 's' in flags else 0
    }
    reply = centarra('/profile/login-preferences', **preferences)
    return JsonResponse(reply, flashed() + '\n' +
                               ', '.join(["%s log-in events: %s" % (a, bool(preferences[a])) for a in preferences]))
예제 #7
0
def update_signup():
    if not needs_update("vps regions") and not needs_update("vps plans"):
        return
    substitutes.data['vps regions'] = {}
    reply = centarra('/vps/signup')
    for i in reply['regions']:
        substitutes.sub('vps regions', i['name'], i['id'])
    for i in reply['resource_plans']:
        substitutes.sub('vps plans', i['name'], i['id'])
예제 #8
0
def signup(args, flags):
    update_signup()
    reply = centarra('/vps/signup', plan=substitutes.swap("vps plans", args[1]), region=substitutes.swap("vps regions", args[0]))
    if not reply:
        return JsonResponse(reply, "The selected region did not have enough stock left to satisfy your request. Try using region '0' for a random location.")
    if not reply.get('service', False):
        return JsonResponse(reply, "Your new VPS has been created; please pay invoice {invoice} (${total:.2f}) to continue.".format(**reply['invoice']))
    substitutes.sub('vps list', reply['service']['name'], reply['service']['id'])
    return JsonResponse(reply, "Your new vps is now named {name} (#{id}) on node {node}. Deploy it with `vps deploy'!"
                                                .format(**reply['service']))
예제 #9
0
파일: vps.py 프로젝트: kaniini/Centarra-cli
def info(args, flags):
    reply = centarra('/vps/%s' % args[0])
    service = reply['service']
    service['w'] = ' not' if not service['monitoring'] else ''
    rpl = "\r\nServer {id} - {name} (\"{nickname}\")" + \
        "\r\n\t{name} is on node {node} with {cpu_sla} CPU SLA status." + \
        "\r\n\t{name} has {memory}mb memory, {swap}mb swap, and {disk}gb disk space." + \
        "\r\n\t{name} is{w} being monitored, and has MAC address {mac}" + \
        "\r\n\t{name} is allowed {ipv6_limit} IPv6 addresses and {ipv4_limit} IPv4 addresses." + \
          (''.join(["\r\n\tIt has IPv{x} address {ip} (id {id})".format(x=i['ipnet']['version'], **i) for i in service['ips']]) if 'i' in flags else '')
    return JsonResponse(reply, rpl.format(**service))
예제 #10
0
def list(args, flags):  # I'd rather not spit every ticket reply out at them at once in this command...
    reply = centarra("/support/tickets")
    rpl = []
    for ticket in reply['tickets']:
        form = {
            "open": "OPEN" if ticket['is_open'] else "CLOSED",
            "o_t": pretty_date(ticket['opened_at']),
            "closed": "\tclosed %s" % pretty_date(ticket['closed_at']) if not ticket['is_open'] else "\t\t"
                }
        rpl.append("#{ticket} by {user}\t{open}\t\tOpened {o_t}{closed}\tSubject: \"{subject}\"".format(**(dict(form.items() + ticket.items()))))
    return JsonResponse(reply, "\r\n".join(rpl))
예제 #11
0
def view(args, flags):
    reply = centarra("/support/ticket/%s" % args[0])
    ticket = reply['ticket']
    form = {
            "open": "OPEN" if ticket['is_open'] else "CLOSED",
            "o_t": pretty_date(ticket['opened_at']),
            "closed": "\tclosed %s" % pretty_date(ticket['closed_at']) if not ticket['is_open'] else "\t\t"
    }
    rpl = ("#{ticket} by {user}\t{open}\t\tOpened {o_t}{closed}\tSubject: \"{subject}\"\r\n".format(**(dict(form.items() + ticket.items()))))
    for i in ticket['replies']:
        rpl += ("\r\nReply {ago}, by {user}:\r\n" + ("-" * 10) + "\r\n{message}\r\n" + ("-" * 10)).format(ago=pretty_date(i['replied_at']), **i)
    return JsonResponse(reply, rpl)
예제 #12
0
def zones(args, flags):
    reply = centarra('/dns/zones')
    resp = []
    for zone in reply['zones']:
        substitutes.sub('dns zones', zone['name'], zone['id'])
        a = "Zone #{id} - {name}, owned by {user}, with {x} records assigned.".format(x=len(zone['records']), **zone)
        if 'l' in flags:
            a += "\r\n\tID\t\tType\t\tPriority\tTTL\t\tContent"
            for record in zone['records']:
                a += "\r\n\t({id}):\t\t{type}\t\t{prio}\t\t{ttl}\t\t\"{content}\"".format(**record)
        resp.append(a)
    return JsonResponse(reply, "\r\n".join(resp))
예제 #13
0
def ip_manage(args, flags):
    oper = args.pop(1)
    if oper == "add":
        vps_id, net_id, ip = tuple(args)
        vps_id = substitutes.swap("vps list", vps_id)
        reply = centarra("/vps/{}/admin/ip/add".format(vps_id), ipbox="{}!{}".format(net_id, ip))
        return JsonResponse(reply, flashed("IP address {0} was successfully added to your vServer.".format(ip)))
    elif oper == "rdns":
        vps_id, ip_id, rdns = tuple(args)
        vps_id = substitutes.swap("vps list", vps_id)
        reply = centarra("/vps/{}/admin/ip/{}/rdns-modify".format(vps_id, ip_id), rdns=rdns)
        return JsonResponse(reply, flashed("IP rDNS was successfully set on your IP address."))
    elif oper == "delete":
        vps_id, ip_id = tuple(args)
        vps_id = substitutes.swap("vps list", vps_id)
        return JsonResponse(centarra("/vps/{}/admin/ip/{}/delete".format(vps_id, ip_id)), "Your IP address has been successfully deleted.")
    elif oper == "list":
        vps_id = substitutes.swap("vps list", args[0])
        reply = centarra("/vps/{}/admin".format(vps_id))
        rpl = []
        for ip in reply['service']['ips']:
            rpl.append("#{}: IPv{} address {} | Broadcast {} | Netmask {} | Gateway {} | Network {}".format(
                ip["id"],
                ip['ipnet']['version'],
                ip['ip'],
                ip['ipnet']['broadcast'],
                ip['ipnet']['netmask'],
                ip['ipnet']['gateway'],
                ip['ipnet']['network']))
        return JsonResponse(reply, "\n".join(rpl))
    elif oper == "available":
        vps_id = substitutes.swap("vps list", args[0])
        reply = centarra("/{}/admin/available-addresses.json".format(vps_id))
        ret = []
        for irange in reply:
            ret.append("IP Range #{}:".format(irange))
            for ip in reply[irange]:
                ret.append("\t{}".format(ip))
    return "Unknown IP operation '{}'.".format(oper)
예제 #14
0
def zone(args, flags):
    reply = centarra('/dns/zone/%s' % substitutes.swap("dns zones", args[0]))
    zone = reply['zone']
    substitutes.sub('dns zones', zone['name'], zone['id'])
    a = "Zone #{id} - {name}, owned by {user}, with {x} records assigned".format(x=len(zone['records']), **zone)
    a += "\r\n\tID\t\tType\t\t" \
         + ("Priority\t" if 'p' in flags else "") \
         + ("TTL\t\t" if 't' in flags else "") \
         + "Content"
    for record in zone['records']:
        a += ("\r\n\t({id}):\t\t{type}\t\t"
              + ("{prio}\t\t" if 'p' in flags else "")
              + ("{ttl}\t\t" if 't' in flags else "")
              + "\"{content}\"").format(**record)
    return JsonResponse(reply, a)
예제 #15
0
파일: vps.py 프로젝트: kaniini/Centarra-cli
def deploy(args, flags):
    send = {}
    if 's' in flags:
        send['startvps'] = "on"
    if 'v' in flags:
        if flags['v'] in intent:
            send['intent'] = flags['v']
        else:
            print("Warning: virtualization type is unknown - ignoring value %s" % flags['v'])
    reply = centarra('/vps/%s/deploy' % args[0], imagename=args[1], rootpass=args[2], **send)

    return JsonResponse(reply, "Your vServer #{vps} is being deployed with the image name {image}, root password {pw}".format(
        vps=args[0], image=args[1], pw=''.join(['*' for a in args[2]]))
                               + ('\r\n' if 'intent' in send or 's' in flags else "")
                               + (("Using virtualization type %s" % send['intent']) if 'intent' in send else '')
                               + ("; " if 'intent' in send and 's' in flags else "")
                               + ("Starting VPS after install completes" if 's' in flags else ""))  # TODO what did I just write. also fix ' and " differences everywhere.
예제 #16
0
def profile_contact(args, flags):
    args = {
        'new_email': args[0],
        'organization': args[1],
        'contact_name': args[2],
        'address1': args[3],
        'address2': args[4],
        'city': args[5],
        'state': args[6],
        'country': args[7],
        'phone': args[8],
        'zip': args[9]
    }
    reply = centarra('/profile/email', **args)
    rsp = ""
    for i in args:
        rsp += "%s=%s, " % (i, args[i])
    return JsonResponse(reply, flashed() + "\n" + rsp[:-2])
예제 #17
0
파일: vps.py 프로젝트: kaniini/Centarra-cli
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))
예제 #18
0
def available(args, flags):
    reply = centarra('/vps/signup')
    for i in reply['regions']:
        substitutes.sub('vps regions', i['name'], i['id'])
    for i in reply['resource_plans']:
        substitutes.sub('vps plans', i['name'], i['id'])
    rpl = []
    if not args or args[0] == "regions":
        rpl.append("Available Regions: \n")
        rpl += ["(%s): %s" % (i['id'], i['name']) for i in reply['regions']]
    if not args or args[0] == "plans":
        rpl.append("Available Plans: \n")
        for i in reply['resource_plans']:
            rpl.append(("({id}) '{name}' - ${price_usd:.2f}" + (" ({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, '\n'.join(rpl))
예제 #19
0
def stock(args, flags):
    reply = centarra("/vps/stock.json")
    if 'p' in flags:
        plan = False
        res = {}
        for region in reply:
            if not plan:
                for plan_amt in reply[region]:
                    if flags['p'] in plan_amt:
                        plan = plan_amt
                        res[region] = reply[region][plan_amt]
                        break
            else:
                res[region] = reply[region][plan]
        return JsonResponse(reply, ("%s: \n" % plan) + "\n".join(["\t%s: %s" % (i, res[i]) for i in res]))
    res = []
    for region in reply:
        res.append("\n" + region)
        for plan in reply[region]:
            res.append("{}: {}".format(plan, reply[region][plan]))
    return JsonResponse(reply, "\n".join(res))
예제 #20
0
def list(args, flags):
    reply = centarra('/vps/list')
    for i in reply['vpslist']:
        substitutes.sub('vps list', i['name'], i['id'])
        substitutes.sub('vps list', 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 = '\n'.join(rpl)
    return JsonResponse(reply, "Your current vServers: \n%s" % rpl)
예제 #21
0
def deploy(args, flags):
    update_vps_list()
    update_templates_list(args[0])
    send = {}
    if 'p' in flags:
        send['rootpass'] = flags['p']
    else:
        import getpass
        send['rootpass'] = getpass.getpass('Enter root password: '******'s' in flags:
        send['startvps'] = "on"
    if 'v' in flags:
        if flags['v'] in intent:
            send['intent'] = flags['v']
        else:
            print("Warning: virtualization type is unknown - ignoring value %s" % flags['v'])
    reply = centarra('/vps/%s/deploy' % substitutes.swap("vps list", substitutes.swap("vps list", args[0])), imagename=args[1], **send)

    return JsonResponse(reply, flashed() + "\nYour vServer #{vps} is being deployed with the image name {image}, root password {pw}".format(
        vps=substitutes.swap("vps list", args[0]), image=args[1], pw=''.join(['*' for a in send['rootpass']]))
                               + ('\n' if 'intent' in send or 's' in flags else "")
                               + (("Using virtualization type %s" % send['intent']) if 'intent' in send else '')
                               + ("; " if 'intent' in send and 's' in flags else "")
                               + ("Starting VPS after install completes" if 's' in flags else ""))  # TODO that's awful logic control. also fix ' and " differences... everywhere.
예제 #22
0
def delete_record(args, flags):
    update_dns_zones()
    reply = centarra("/dns/zone/%s/record/%s/delete" % (substitutes.swap("dns zones", args[0]), args[1]))
    return JsonResponse(reply, "Your record %s in domain %s has been deleted." % (args[1], substitutes.swap("dns zones", args[0])))
예제 #23
0
def password(args, flags):
    reply = centarra('/profile/password', newpass=args[0])
    return JsonResponse(reply, flashed())
예제 #24
0
def delete(args, flags):
    update_dns_zones()
    reply = centarra("/dns/zone/%s/delete" % substitutes.swap("dns zones", args[0]))
    return JsonResponse(reply, "Your zone %s (#%s) has been successfully deleted." % (args[0], substitutes.swap("dns zones", args[0])))
예제 #25
0
def new_api_key(args, flags):
    reply = centarra('/profile/new-apikey')
    return JsonResponse(reply, flashed())
예제 #26
0
def webhook_uri(args, flags):
    reply = centarra('/profile/webhook-uri', webhook_uri=args[0])
    return JsonResponse(reply, flashed())
예제 #27
0
def record(args, flags):
    update_dns_zones()
    reply = centarra("/dns/zone/{}/record/{}".format(substitutes.swap("dns zones", args[0]), args[1]))
    return JsonResponse(reply, "Record #{id}\n\tTTL {ttl}\n\tPrio {prio}\n\tType {type}\n\t{name} = '{content}'".format(**reply['record']))
예제 #28
0
def edit_record(args, flags):
    update_dns_zones()
    reply = centarra("/dns/zone/%s/record/%s" % (substitutes.swap("dns zones", args[0]), args[1]), subdomain=args[2], content=args[3])
    return JsonResponse(reply, "Record {id} was successfully updated - {sub}{dot}{name} set to {content}"
    .format(dot="." if args[2] is not "" else "", sub=args[2], content=args[3], id=args[1], **(reply['zone'])))
예제 #29
0
def new(args, flags):
    reply = centarra('/dns/zone/new', domain_name=args[0])
    if reply == {}:
        return reply, flashed()
    response = "Domain {id} was created. See `dns zone {id}' for more information.".format(**reply['zone'])
    return JsonResponse(reply, response)
예제 #30
0
def axfr_import(args, flags):
    update_dns_zones()
    reply = centarra("/dns/zone/%s/axfr-import" % substitutes.swap("dns zones", args[0]), nameserver=args[1])
    return JsonResponse(reply, "Your axfr-import process is running for domain %s on nameserver %s" % (args[0], args[1]))