Git Product home page Git Product logo

mreg-cli's Introduction

MREG CLI Build Status

mreg-cli is a command line interface for the MREG API.

Setup

Options can be set in ~/.config/mreg-cli.conf. A typical config file looks like this:

[mreg]
USER=mreg-user
SERVER=https://mreg.example.com:8000

General usage

Commands in mreg-cli take on the form of a fairly standard command line interface:

host add myhost.example.com 192.168.1.1 [email protected] -hinfo Linux -comment "My host"

Here we are using the host add command to add a new host. The command takes a number of arguments, which are positional. The arguments in this case is a name and an ip address, followed by a contact and some optional arguments. The optional arguments are specified with a flag, followed by the value. The optional arguments can be specified in any order, but the positional arguments must be specified in the order they are defined in the command.

Filtering

mreg-cli support output filtering via the operators | and |!. The | operator is used to filter the output to only show the lines matching the text specified after the operator. Using |! will show the lines not matching the text specified after the operator. The filter text is a standard python regular expression. Some examples:

mreg> host info one.example.com
Name:         one.example.com
Contact:      [email protected]
A_Records     IP                           MAC
              192.168.1.2                  aa:bb:cc:dd:ee:ff
TTL:          (Default)
TXT:          v=spf1 -all
mreg> host info one.example.com | example
Name:         one.example.com
Contact:      [email protected]
mreg> host info one.example.com | me.*com
Contact:      [email protected]
mreg> host info one.example.com |! me.*com
Name:         one.example.com
A_Records     IP                           MAC
              192.168.1.2                  aa:bb:cc:dd:ee:ff
TTL:          (Default)
TXT:          v=spf1 -all

Forcing commands

A number of commands take a -force flag. This flag is typically required when the operation will fail internal validation. However, please note that -force is emphatically not a "I know what I'm doing" flag. It is a "I know what I'm doing and I'm willing to take responsibility for the consequences" flag. If you're not sure what you're doing, don't use -force.

As an example, you may add a host to a network unknown to mreg, or a frozen network. You may want to assiciate a mac address to a host or an IP that already has a mac address associated with it. All of these examples will cause a validation failure, but you may bypass this failure by using -force. This is fine if you for example are certain the new mac address is supposed to replace the old one, but if you mistakenly associate a mac address to the wrong host, you may cause the host to be unreachable on the network. -force exists to alert you that you are doing something that may have unintended consequences, and you should be sure you know what you are doing before using it.

Command set

Host

   host add <name> <ip/net> <contact> [-hinfo <hinfo>] [-comment <comment>]
       Add a new host with the given name, ip or subnet and contact. hinfo and comment
       are optional.

!!!note Force is required when adding a host with an ip in a subnet not controlled by MREG or in a frozen subnet.

   host remove <name|ip>
       Remove host. If <name> is an alias the cname host is removed.
       
   host info <name|ip>
       Print information about host. If <name> is an alias the cname hosts info is shown.
       
   host rename <old-name> <new-name>
       Rename host. If <old-name> is an alias then the alias is renamed.
    
   host set_comment <name> <comment>
       Set comment for host. If <name> is an alias the cname host is updated.
       
   host set_contact <name> <contact>
       Set contact for host. If <name> is an alias the cname host is updated.

A/AAAA

The API doesn't differentiate between ipv4 and ipv6, so A/AAAA are only different on the client side.
Require force if the host already has A/AAAA record(s), or if the ip is in a subnet not controlled by MREG.

   host a_add <name> <ip|subnet>
       Add an A record to host. If <name> is an alias the cname host is used.
       
   host a_change <name> <old-ip> <new-ip-or-subnet>
       Change A record. If <name> is an alias the cname host is used.
       
   host a_remove <name> <ip>
       Remove A record from host. If <name> is an alias the cname host is used.
       
   host a_show <name>
       Show hosts ipaddresses. If <name> is an alias the cname host is used.
       
   host aaaa_add <name> <ipv6>
       Add an AAAA record to host. If <name> is an alias the cname host is used.
       
   host aaaa_change <name> <old-ipv6> <new-ipv6>
       Change AAAA record. If <name> is an alias the cname host is used.
       
   host aaaa_remove <name> <ipv6>
       Remove AAAA record from host. If <name> is an alias the cname host is used.
       
   host aaaa_show <name>
       Show hosts ipaddresses. If <name> is an alias the cname host is used.

CNAME

   host cname_add <existing-name> <new-alias>
       Add a CNAME record to host. If <existing-name> is an alias the cname host is used as
       target for <new-alias>.
       
   host cname_remove <name> <alias-to-delete>
       Remove CNAME record.
       
   host cname_show <name>
       Show CNAME records for host. If <name> is an alias the cname hosts aliases are shown.

HINFO

   host hinfo_remove <name>
       Remove hinfo for host. If <name> is an alias the cname host is updated.
       
   host hinfo_set <name> <hinfo>
       Set hinfo for host. If <name> is an alias the cname host is updated.
       
   host hinfo_show <name>
       Show hinfo for host. If <name> is an alias the cname hosts hinfo is shown.

LOC

All LOC commands require force.

   host loc_remove <name>
       Remove location from host. If <name> is an alias the cname host is updated.
       
   host loc_set <name> <loc>
       Set location of host. If <name> is an alias the cname host is updated.
       
   host loc_show <name>
       Show location of host. If <name> is an alias the cname hosts LOC is shown.

NAPTR

   host naptr_add <name> <preference> <order> <flagg> <service> <regexp> <replacement>
       Add a NAPTR record to host.
       
   host naptr_remove <name> <replacement>
       Remove NAPTR record.
       
   host naptr_show <name>
       Show all NAPTR records for host.

PTR

   host ptr_change <ipv4|ipv6> <old-name> <new-name>
       Move PTR record from <old-name> to <new-name>.
       
   host ptr_remove <ipv4|ipv6> <name>
       Remove PTR record from host.
       
   host ptr_set <ipv4|ipv6> <name>
       Create a PTR record for host.
       
   host ptr_show <ipv4|ipv6>
       Show PTR record matching given ip (empty input shows all PTR records).

SRV

Require force if a host with target-name doesn't exist.

   host srv_add <service-name> <pri> <weight> <port> <target-name>
       Add SRV record.
       
   host srv_remove <service-name>
       Remove SRV record.
       
   host srv_show <service-name>
       Show SRV records for the service.

SSHFP

   host sshfp_add <name> <algorithm> <hash_type> <fingerprint>
       Add SSHFP record for the host.

   host sshfp_remove <name> <fingerprint>
       Remove SSHFP record with a given fingerprint from the host.
       A missing fingerprint removes all SSHFP records for the host.

   host sshfp_show <name>
       Show SSHFP records for the host.

TTL

   host ttl_remove <name>
       Remove explicit TTL for host. If <name> is an alias the alias host is updated.
       
   host ttl_set <name> <ttl>
       Set ttl for host. Valid values are 300 <= TTL <= 68400 or "default". If <name> is an
       alias the alias host is updated.
       
   host ttl_show <name>
       Show ttl for host. If <name> is an alias the alias hosts TTL is shown.

TXT

   host txt_add <name> <text>
       Add a txt record to host. <text> must be enclosed in double quotes if it contains more
       than one word.
       
   host txt_remove <name> <text>
       Remove TXT record for host matching <text>.
       
   host txt_show <name>
       Show all TXT records for host.

DHCP

   dhcp assoc <name|ip> <mac-addr>
       Associate MAC address with host. If host got multiple A/AAAA records an IP must be
       given instead of name.
       
   dhcp disassoc <name|ip>
       Disassociate MAC address with host/ip. If host got multiple A/AAAA records an IP must be
       given instead of name

subnet

   subnet create <subnet> <description> <vlan> <dns_delegated> <category> <location> <frozen>
       Create a new subnet
       
   subnet import <file>
       Import subnet data from <file>.
       
   subnet info <subnet>
       Display subnet info
       
   subnet list_unused_addresses <subnet>
       Lists all the unused addresses for a subnet
       
   subnet list_used_addresses <subnet>
       Lists all the used addresses for a subnet
       
   subnet remove <subnet>
       Remove subnet
       
   subnet set_category <subnet> <category_tag>
       Set category tag for subnet
       
   subnet set_description <subnet> <description>
       Set description for subnet
       
   subnet set_dns_delegated <subnet>
       Set that DNS-administration is being handled elsewhere.
       
   subnet set_frozen <subnet>
       Freeze a subnet.
       
   subnet set_location <subnet> <location_tag>
       Set location tag for subnet
       
   subnet set_reserved <subnet> <number>
       Set number of reserved hosts.
       
   subnet set_vlan <subnet> <vlan>
       Set VLAN for subnet
       
   subnet unset_dns_delegated <subnet>
       Set that DNS-administration is not being handled elsewhere.
       
   subnet unset_frozen <subnet>
       Unfreeze a subnet.

zone

   zone create <zone-name> (<nameservers>)
       Create new zone.
       
   zone delete <zone-name>
       Delete a zone
       
   zone set_ns <zone-name> (<nameservers>)
       Update nameservers for an existing zone.
       
   zone set_soa <zone-name> (<primary_ns> <email> <serialno> <refresh> <retry> <expire> <ttl>)
       Updated the SOA of a zone.

other

The CLI also provides these miscellaneous functions:

List available commands without a argument, or display detailed help for a command or for a specific option of a command.

help
help <cmd>
<cmd> help <option>

shell <cmd>: Run a bash command.

source <file-name> [--exit]: Read commands from a file. If --exit is supplied then it'll stop executing on error.

mreg-cli's People

Contributors

fredrikhl avatar magnuhho avatar mbakke avatar mhmorgan avatar nicolactic avatar nlhiorth avatar oyvindhagberg avatar oyvindkolbu avatar paalbra avatar pederhan avatar safeaim avatar terjekv avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mreg-cli's Issues

Lage en generisk "yes/no" input, med defaultverdi

F.eks ved subnet create 11.0.0.0, så må man eksplisitt skrive "y" eller "n" for om det skal være fryst. La heller "n" være standard og la brukeren kunne bare trykke på enter for å unngå å måtte velge.

Helt sikkert andre tilfeller av en generisk yes_no_input kan brukes.

host ptr_set ignores reserved addresses

mreg> host ptr_set 10.0.0.2 foo
OK: host ptr_set: Added PTR record 10.0.0.2 to foo.example.org
mreg> subnet info 10.0.0.0
Subnet:                  10.0.0.0/26
Netmask:                 255.255.255.192
[..]
IP-range:                10.0.0.0 - 10.0.0.63
Reserved host addresses: 3
                         10.0.0.0 (net)
                         10.0.0.1
                         10.0.0.2
                         10.0.0.3
                         10.0.0.63 (broadcast)
Used addresses:          2
Unused addresses:        57 (excluding reserved adr.)

Fiks sletting av subnet

Ved sletting av subnet så prøver man å få ut info ved å gå til "subnets/1.2.3.4/24", det fungerer ikke uten å bruke "urllib.parse.quote", ellers blir "1.2.3.4/24" tolket som en sti og ikke som et argument.

Eksempel fra Odberg:

mreg> subnet remove 193.157.109.0/24
WARNING: subnet remove: Must force (y)
mreg> subnet remove 193.157.109.0/24 y
ERROR: subnet remove: DELETE "http://127.0.0.1:8000/subnets/193.157.109.0/24": 500: Internal Server Error

Bla opp / kommandobuffer bør gå til forrige kommando

Når man kjører en kommando, kan den spørre deg om flere parametre, som du da må skrive inn på hver sin linje.
Hvis man trykker pil opp for å gå tilbake, bør man slippe å bla gjennom disse parameterverdiene, men i stedet gå rett til forrige kommando.

Oppdatere hjelpeteksten for cname_add

Fra Anders per epost:

Forresten veldig fint om den interaktive hjelpeteksten :

mreg> host cname_add
Enter name> www.vg.no.
Enter alias> tulleavis.uio.no.
WARNING: host cname_add: host not found: www.vg.no.uio.no

Kan endres fra "Enter name" til "Enter existing name", og fra "Enter
alias" til "Enter new alias".

Støtte at et argument kan være en liste

Typisk i dag bruker man:
>> host info (ns1 ns2)
for å gjøre host info ns1 og host info ns2. Dette støtter ikke mreg-cli.
Tilsvarende kan man gjøre:
>> host add (foo bar) 10.0.0.0/
for å legge til to hoster samtidig. Følgelig må man skjønne når noe er en liste og når det er i eksempelet over henholdvis andre og tredje argument.

Sletting av en zone feiler

Nå klarer vi ikke å slette selv nyopprettede soner:

mreg> zone create usit.no [email protected] ns1.uio.no
OK: zone create: created zone usit.no
mreg> zone delete usit.no
WARNING: zone delete: Zone has registered subzones, must force

Problemet er at den sjekker om det finnes noen soner som slutter på det samme som sonen oppgitt. Den får alltids treff på seg selv, om da syter den over treff på undersoner.

Angreknapp

Kunne angre og gjenopprette en removed host, f.eks.

The cname handling is completly bogus

cname_add does the opposite of what is should. It creates a new host with the alias name and adds the name of the host as the cname name.

mreg=# SELECT * FROM host;
 id |        name           |      contact      | ttl | loc | comment | hinfo | zone
----+-----------------------+-------------------+-----+-----+---------+-------+------
  1 | ns1.example.org       | [email protected]   |     |     |         |       |    2
  2 | foo.example.com       | [email protected]   |     |     |         |       |    3
  3 | ns.blåbær.example.org | [email protected]   |     |     |         |       |    2
  4 | ns.example.org        | [email protected]   |     |     |         |       |    3
  5 | ns.example.net        | [email protected]   |     |     |         |       |
(5 rows)

mreg=# SELECT * FROM cname;
 id |   cname         | ttl  | host
----+-----------------+---+------
  1 | ns1.example.org |    |    3
  2 | ns1.example.org |    |    4
  3 | ns1.example.org |    |    5

Krev force for a_add utenfor subnet mreg styrer

Fra Odberg:

dersom man oppgir en adresse som er på et subnett som ikke er
kontrollert av mreg, så skal det kreve force :

mreg> host a_add kantarell 129.241.10.10 y
OK: host a_add: added ip 129.241.10.10 to kantarell.uio.no

Den over burde ha krevd force, på samme måte som :

mreg> host add kantarell2 129.241.10.10 [email protected]
WARNING: host add: 129.241.10.10 isn't in a subnet controlled by MREG, must force

Lag kommandoer for å liste og lage hinfopresets

Nå må man vite om og lage hinfopresets via API-et, det holder ikke.
Trenger å lage:
host hinfopreset_list -- som lister alle hinfopresets
host hinfopreset_create -- opprette ny
host hinfopreset_delete -- fjerne

Refaktorere opprettelse av urler

Må lage en felles metode for å lage urler. Nå er det ca 100 tilfeller av følgende kode:

url = "http://{}:{}/subnets/".format
    conf["server_ip"],
    conf["server_port"],
)
history.record_get(url)
nets = get(url).json()

Dette både hardkoder bruk av HTTP og er virkelig unødvendig jobb gang man skal kalle på APIet.

Ikke kræsj ved "subnet info stortipv6subnet"

Nå gjør mreg-cli en hosts = list(subnet.hosts()) og det fungerer fint i ipv4-verden, men drar seg virkelig til i ipv6-verdenen. En standard /64-prefix har 18446744073709551616 adresser. Så blir en stor liste for å hente ut de første reserverte adressene...

Kan ikke opprette to hoster som peker på samme IP-adresse

mreg> host add foo 129.240.0.10 [email protected]
OK: host add: created host foo.uio.no
mreg> host add foo2 129.240.0.10 [email protected]
ERROR: host add: POST "http://127.0.0.1:8000/hosts/": 409: Conflict
{
  "ERROR": "IP address already exists"
}

Dagens oppførsel:

jbofh> host add foobar10 193.157.234.70 other other other
name                           ip
foobar10                       193.157.234.70
bofh> host add foobar11 193.157.234.70 other other other n
Error: IP already in use or reserved, must force (y)
jbofh> host add foobar11 193.157.234.70 other other other y
name                           ip
foobar11                       193.157.234.70
jbofh> host info 193.157.234.70
A-records              IP                   MAC
  foobar10.uio.no.     193.157.234.70       <not set>
  foobar11.uio.no.     193.157.234.70       <not set>
Rev-map override:
  193.157.234.70       foobar10.uio.no.
jbofh> host remove foobar11.uio.no.
OK, DNS-owner foobar11.uio.no. completely removed
jbofh> host info 193.157.234.70
A-records              IP                   MAC
  foobar10.uio.no.     193.157.234.70       <not set>
Rev-map override:
  193.157.234.70       using default PTR from A-record

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.