Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Domain check function #194

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
14 changes: 13 additions & 1 deletion gandi/cli/commands/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click

from gandi.cli.core.cli import cli
from gandi.cli.core.utils import output_contact_info, output_domain
from gandi.cli.core.utils import output_contact_info, output_domain, output_domain_check
from gandi.cli.core.params import pass_gandi


Expand Down Expand Up @@ -37,6 +37,18 @@ def info(gandi, resource):
return result


@cli.command()
@click.argument('resource', metavar='DOMAIN')
@pass_gandi
def check(gandi, resource):
"""Check domain availability and price."""

result_check = gandi.domain.check(resource)
output_domain_check(gandi, result_check, justify=12)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove the justify parameter from the call as it's the same as the method default one.


return result_check


@cli.command()
@click.option('--domain', default=None, help='Name of the domain.')
@click.option('--duration', default=1, prompt=True,
Expand Down
23 changes: 23 additions & 0 deletions gandi/cli/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,29 @@ def output_hostedcert(gandi, hcert, output_keys, justify=12):
output_sub_line(gandi, 'type', vhost['type'], 10)


def output_domain_check(gandi, domain, justify=12):
""" Helper to output a domain information."""

if (domain['available'] == 'available'):
output_line(gandi, 'Domain', domain['extension'], justify)
for domains_avail in domain['prices']:
r_phase = str(domains_avail['action']['param']['tld_phase'])
for domain_prices in domains_avail['unit_price']:
output_line (gandi, 'Phase', r_phase, justify)
output_line (gandi, 'Min Duration', str(domain_prices['min_duration']), justify)
output_line (gandi, 'Max Duration', str(domain_prices['min_duration']), justify)
output_line (gandi, 'Price', str(domain_prices['price']), justify)
output_line (gandi, 'Currency', str(domain_prices['currency']), justify)
output_line (gandi, 'Price Type', str(domain_prices['price_type']), justify)
for phases in domain['phases']:
tldphase = "Start: " + str(phases['date_start']) + " "
tldphase += "Start Gandi: " + str(phases['date_start_gandi']) + " ";
tldphase += "End: " + str(phases['date_end']);
output_line(gandi, str(phases['phase']), tldphase, justify)
else:
output_line (gandi, 'Status', str(domain['available']), justify)


def output_domain(gandi, domain, output_keys, justify=12):
""" Helper to output a domain information."""
if 'nameservers' in domain:
Expand Down
14 changes: 14 additions & 0 deletions gandi/cli/modules/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Domain(GandiModule):

""" Module to handle CLI commands.

$ gandi domain check
$ gandi domain create
$ gandi domain info
$ gandi domain list
Expand All @@ -26,6 +27,19 @@ def info(cls, fqdn):
"""Display information about a domain."""
return cls.call('domain.info', fqdn)

@classmethod
def check(cls, fqdn):
"""Check domain availability and price."""
fqdn = fqdn.lower()

result = cls.call('domain.price', [fqdn])

while result[0]['available'] == 'pending':
time.sleep(1)
result = cls.call('domain.price', [fqdn])

return result[0]

@classmethod
def create(cls, fqdn, duration, owner, admin, tech, bill, nameserver,
background):
Expand Down
3 changes: 3 additions & 0 deletions gandicli.man.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Namespaces:
* disk rollback Rollback a disk from a snapshot.
* disk update Update a disk.
* docker Manage docker instances.
* domain check Check domain availability and price.
* domain create Buy a domain.
* domain renew Renew a domain.
* domain info Display information about a domain.
Expand Down Expand Up @@ -228,6 +229,8 @@ Details:

* ``gandi domain create domain.tld`` helps register a domain. Options are ``--domain domain.tld`` for the domain you want to get (/!\ this option is deprecated and will be removed upon next release), ``--duration INTEGER RANGE`` for the registration period, ``--owner TEXT``, ``--admin TEXT``, ``--tech TEXT``, ``--bill TEXT`` for the four contacts to pass to the creation process, ``--nameserver TEXT`` for adding custom nameservers. All these modification can be done as background process using the option ``--background`` (or ``--bg``).

* ``gandi domain check omain.tld`` Check information about the specific domain availability and price.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in the command: should be domain.tld.
And it would be more explicit to say Retrieve information.. than Check information...


* ``gandi domain renew domain.tld`` will renew a domain. Available option is ``--duration INTEGER RANGE`` for the registration period. All these modification can be done as background process using the option ``--background`` (or ``--bg``).

* ``gandi domain info domain.tld`` show information about the specific domain ``domain.tld`` : owner, admin, billing and technical contacts, fully qualified domain name, nameservers, associated zone, associated tags and more.
Expand Down