|
5 | 5 |
|
6 | 6 | import SoftLayer |
7 | 7 | from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import exceptions |
8 | 9 | from SoftLayer.CLI import helpers |
9 | 10 | # pylint: disable=redefined-builtin |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @click.command() |
13 | | -@click.argument('zone') |
14 | 14 | @click.argument('record') |
15 | | -@click.argument('type') |
| 15 | +@click.argument('record_type') |
16 | 16 | @click.argument('data') |
| 17 | +@click.option('--zone', |
| 18 | + help="Zone name or identifier that the resource record will be associated with.\n" |
| 19 | + "Required for all record types except PTR") |
17 | 20 | @click.option('--ttl', |
18 | | - type=click.INT, |
19 | | - default=7200, |
| 21 | + default=900, |
20 | 22 | show_default=True, |
21 | 23 | help='TTL value in seconds, such as 86400') |
| 24 | +@click.option('--priority', |
| 25 | + default=10, |
| 26 | + show_default=True, |
| 27 | + help='The priority of the target host. (MX or SRV type only)') |
| 28 | +@click.option('--protocol', |
| 29 | + type=click.Choice(['tcp', 'udp', 'tls']), |
| 30 | + default='tcp', |
| 31 | + show_default=True, |
| 32 | + help='The protocol of the service, usually either TCP or UDP. (SRV type only)') |
| 33 | +@click.option('--port', |
| 34 | + type=click.INT, |
| 35 | + help='The TCP/UDP/TLS port on which the service is to be found. (SRV type only)') |
| 36 | +@click.option('--service', |
| 37 | + help='The symbolic name of the desired service. (SRV type only)') |
| 38 | +@click.option('--weight', |
| 39 | + default=5, |
| 40 | + show_default=True, |
| 41 | + help='Relative weight for records with same priority. (SRV type only)') |
22 | 42 | @environment.pass_env |
23 | | -def cli(env, zone, record, type, data, ttl): |
24 | | - """Add resource record.""" |
| 43 | +def cli(env, record, record_type, data, zone, ttl, priority, protocol, port, service, weight): |
| 44 | + """Add resource record. |
| 45 | +
|
| 46 | + Each resource record contains a RECORD and DATA property, defining a resource's name and it's target data. |
| 47 | + Domains contain multiple types of resource records so it can take one of the following values: A, AAAA, CNAME, |
| 48 | + MX, SPF, SRV, and PTR. |
| 49 | +
|
| 50 | + About reverse records (PTR), the RECORD value must to be the public Ip Address of device you would like to manage |
| 51 | + reverse DNS. |
| 52 | +
|
| 53 | + slcli dns record-add 10.10.8.21 PTR myhost.com --ttl=900 |
| 54 | +
|
| 55 | + Examples: |
| 56 | +
|
| 57 | + slcli dns record-add myhost.com A 192.168.1.10 --zone=foobar.com --ttl=900 |
| 58 | +
|
| 59 | + slcli dns record-add myhost.com AAAA 2001:DB8::1 --zone=foobar.com |
| 60 | +
|
| 61 | + slcli dns record-add 192.168.1.2 MX 192.168.1.10 --zone=foobar.com --priority=11 --ttl=1800 |
| 62 | +
|
| 63 | + slcli dns record-add myhost.com TXT "txt-verification=rXOxyZounZs87oacJSKvbUSIQ" --zone=2223334 |
| 64 | +
|
| 65 | + slcli dns record-add myhost.com SPF "v=spf1 include:_spf.google.com ~all" --zone=2223334 |
| 66 | +
|
| 67 | + slcli dns record-add myhost.com SRV 192.168.1.10 --zone=2223334 --service=foobar --port=80 --protocol=TCP |
| 68 | +
|
| 69 | + """ |
25 | 70 |
|
26 | 71 | manager = SoftLayer.DNSManager(env.client) |
27 | | - zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone') |
28 | | - manager.create_record(zone_id, record, type, data, ttl=ttl) |
| 72 | + record_type = record_type.upper() |
| 73 | + |
| 74 | + if zone and record_type != 'PTR': |
| 75 | + zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone') |
| 76 | + |
| 77 | + if record_type == 'MX': |
| 78 | + manager.create_record_mx(zone_id, record, data, ttl=ttl, priority=priority) |
| 79 | + elif record_type == 'SRV': |
| 80 | + manager.create_record_srv(zone_id, record, data, protocol, port, service, |
| 81 | + ttl=ttl, priority=priority, weight=weight) |
| 82 | + else: |
| 83 | + manager.create_record(zone_id, record, record_type, data, ttl=ttl) |
| 84 | + |
| 85 | + elif record_type == 'PTR': |
| 86 | + manager.create_record_ptr(record, data, ttl=ttl) |
| 87 | + else: |
| 88 | + raise exceptions.CLIAbort("%s isn't a valid record type or zone is missing" % record_type) |
| 89 | + |
| 90 | + click.secho("%s record added successfully" % record_type, fg='green') |
0 commit comments