id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
11,100
Gandi/gandi.cli
gandi/cli/modules/cert.py
Certificate.package_list
def package_list(cls, options=None): """ List possible certificate packages.""" options = options or {} try: return cls.safe_call('cert.package.list', options) except UsageError as err: if err.code == 150020: return [] raise
python
def package_list(cls, options=None): """ List possible certificate packages.""" options = options or {} try: return cls.safe_call('cert.package.list', options) except UsageError as err: if err.code == 150020: return [] raise
[ "def", "package_list", "(", "cls", ",", "options", "=", "None", ")", ":", "options", "=", "options", "or", "{", "}", "try", ":", "return", "cls", ".", "safe_call", "(", "'cert.package.list'", ",", "options", ")", "except", "UsageError", "as", "err", ":", "if", "err", ".", "code", "==", "150020", ":", "return", "[", "]", "raise" ]
List possible certificate packages.
[ "List", "possible", "certificate", "packages", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/cert.py#L169-L177
11,101
Gandi/gandi.cli
gandi/cli/modules/cert.py
Certificate.advice_dcv_method
def advice_dcv_method(cls, csr, package, altnames, dcv_method, cert_id=None): """ Display dcv_method information. """ params = {'csr': csr, 'package': package, 'dcv_method': dcv_method} if cert_id: params['cert_id'] = cert_id result = cls.call('cert.get_dcv_params', params) if dcv_method == 'dns': cls.echo('You have to add these records in your domain zone :') cls.echo('\n'.join(result['message']))
python
def advice_dcv_method(cls, csr, package, altnames, dcv_method, cert_id=None): """ Display dcv_method information. """ params = {'csr': csr, 'package': package, 'dcv_method': dcv_method} if cert_id: params['cert_id'] = cert_id result = cls.call('cert.get_dcv_params', params) if dcv_method == 'dns': cls.echo('You have to add these records in your domain zone :') cls.echo('\n'.join(result['message']))
[ "def", "advice_dcv_method", "(", "cls", ",", "csr", ",", "package", ",", "altnames", ",", "dcv_method", ",", "cert_id", "=", "None", ")", ":", "params", "=", "{", "'csr'", ":", "csr", ",", "'package'", ":", "package", ",", "'dcv_method'", ":", "dcv_method", "}", "if", "cert_id", ":", "params", "[", "'cert_id'", "]", "=", "cert_id", "result", "=", "cls", ".", "call", "(", "'cert.get_dcv_params'", ",", "params", ")", "if", "dcv_method", "==", "'dns'", ":", "cls", ".", "echo", "(", "'You have to add these records in your domain zone :'", ")", "cls", ".", "echo", "(", "'\\n'", ".", "join", "(", "result", "[", "'message'", "]", ")", ")" ]
Display dcv_method information.
[ "Display", "dcv_method", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/cert.py#L236-L245
11,102
Gandi/gandi.cli
gandi/cli/modules/cert.py
Certificate.create_csr
def create_csr(cls, common_name, private_key=None, params=None): """ Create CSR. """ params = params or [] params = [(key, val) for key, val in params if val] subj = '/' + '/'.join(['='.join(value) for value in params]) cmd, private_key = cls.gen_pk(common_name, private_key) if private_key.endswith('.crt') or private_key.endswith('.key'): csr_file = re.sub(r'\.(crt|key)$', '.csr', private_key) else: csr_file = private_key + '.csr' cmd = cmd % {'csr': csr_file, 'key': private_key, 'subj': subj} result = cls.execute(cmd) if not result: cls.echo('CSR creation failed') cls.echo(cmd) return return csr_file
python
def create_csr(cls, common_name, private_key=None, params=None): """ Create CSR. """ params = params or [] params = [(key, val) for key, val in params if val] subj = '/' + '/'.join(['='.join(value) for value in params]) cmd, private_key = cls.gen_pk(common_name, private_key) if private_key.endswith('.crt') or private_key.endswith('.key'): csr_file = re.sub(r'\.(crt|key)$', '.csr', private_key) else: csr_file = private_key + '.csr' cmd = cmd % {'csr': csr_file, 'key': private_key, 'subj': subj} result = cls.execute(cmd) if not result: cls.echo('CSR creation failed') cls.echo(cmd) return return csr_file
[ "def", "create_csr", "(", "cls", ",", "common_name", ",", "private_key", "=", "None", ",", "params", "=", "None", ")", ":", "params", "=", "params", "or", "[", "]", "params", "=", "[", "(", "key", ",", "val", ")", "for", "key", ",", "val", "in", "params", "if", "val", "]", "subj", "=", "'/'", "+", "'/'", ".", "join", "(", "[", "'='", ".", "join", "(", "value", ")", "for", "value", "in", "params", "]", ")", "cmd", ",", "private_key", "=", "cls", ".", "gen_pk", "(", "common_name", ",", "private_key", ")", "if", "private_key", ".", "endswith", "(", "'.crt'", ")", "or", "private_key", ".", "endswith", "(", "'.key'", ")", ":", "csr_file", "=", "re", ".", "sub", "(", "r'\\.(crt|key)$'", ",", "'.csr'", ",", "private_key", ")", "else", ":", "csr_file", "=", "private_key", "+", "'.csr'", "cmd", "=", "cmd", "%", "{", "'csr'", ":", "csr_file", ",", "'key'", ":", "private_key", ",", "'subj'", ":", "subj", "}", "result", "=", "cls", ".", "execute", "(", "cmd", ")", "if", "not", "result", ":", "cls", ".", "echo", "(", "'CSR creation failed'", ")", "cls", ".", "echo", "(", "cmd", ")", "return", "return", "csr_file" ]
Create CSR.
[ "Create", "CSR", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/cert.py#L337-L358
11,103
Gandi/gandi.cli
gandi/cli/modules/cert.py
Certificate.get_common_name
def get_common_name(cls, csr): """ Read information from CSR. """ from tempfile import NamedTemporaryFile fhandle = NamedTemporaryFile() fhandle.write(csr.encode('latin1')) fhandle.flush() output = cls.exec_output('openssl req -noout -subject -in %s' % fhandle.name) if not output: return common_name = output.split('=')[-1].strip() fhandle.close() return common_name
python
def get_common_name(cls, csr): """ Read information from CSR. """ from tempfile import NamedTemporaryFile fhandle = NamedTemporaryFile() fhandle.write(csr.encode('latin1')) fhandle.flush() output = cls.exec_output('openssl req -noout -subject -in %s' % fhandle.name) if not output: return common_name = output.split('=')[-1].strip() fhandle.close() return common_name
[ "def", "get_common_name", "(", "cls", ",", "csr", ")", ":", "from", "tempfile", "import", "NamedTemporaryFile", "fhandle", "=", "NamedTemporaryFile", "(", ")", "fhandle", ".", "write", "(", "csr", ".", "encode", "(", "'latin1'", ")", ")", "fhandle", ".", "flush", "(", ")", "output", "=", "cls", ".", "exec_output", "(", "'openssl req -noout -subject -in %s'", "%", "fhandle", ".", "name", ")", "if", "not", "output", ":", "return", "common_name", "=", "output", ".", "split", "(", "'='", ")", "[", "-", "1", "]", ".", "strip", "(", ")", "fhandle", ".", "close", "(", ")", "return", "common_name" ]
Read information from CSR.
[ "Read", "information", "from", "CSR", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/cert.py#L361-L374
11,104
Gandi/gandi.cli
gandi/cli/modules/cert.py
Certificate.process_csr
def process_csr(cls, common_name, csr=None, private_key=None, country=None, state=None, city=None, organisation=None, branch=None): """ Create a PK and a CSR if needed.""" if csr: if branch or organisation or city or state or country: cls.echo('Following options are only used to generate' ' the CSR.') else: params = (('CN', common_name), ('OU', branch), ('O', organisation), ('L', city), ('ST', state), ('C', country)) params = [(key, val) for key, val in params if val] csr = cls.create_csr(common_name, private_key, params) if csr and os.path.exists(csr): with open(csr) as fcsr: csr = fcsr.read() return csr
python
def process_csr(cls, common_name, csr=None, private_key=None, country=None, state=None, city=None, organisation=None, branch=None): """ Create a PK and a CSR if needed.""" if csr: if branch or organisation or city or state or country: cls.echo('Following options are only used to generate' ' the CSR.') else: params = (('CN', common_name), ('OU', branch), ('O', organisation), ('L', city), ('ST', state), ('C', country)) params = [(key, val) for key, val in params if val] csr = cls.create_csr(common_name, private_key, params) if csr and os.path.exists(csr): with open(csr) as fcsr: csr = fcsr.read() return csr
[ "def", "process_csr", "(", "cls", ",", "common_name", ",", "csr", "=", "None", ",", "private_key", "=", "None", ",", "country", "=", "None", ",", "state", "=", "None", ",", "city", "=", "None", ",", "organisation", "=", "None", ",", "branch", "=", "None", ")", ":", "if", "csr", ":", "if", "branch", "or", "organisation", "or", "city", "or", "state", "or", "country", ":", "cls", ".", "echo", "(", "'Following options are only used to generate'", "' the CSR.'", ")", "else", ":", "params", "=", "(", "(", "'CN'", ",", "common_name", ")", ",", "(", "'OU'", ",", "branch", ")", ",", "(", "'O'", ",", "organisation", ")", ",", "(", "'L'", ",", "city", ")", ",", "(", "'ST'", ",", "state", ")", ",", "(", "'C'", ",", "country", ")", ")", "params", "=", "[", "(", "key", ",", "val", ")", "for", "key", ",", "val", "in", "params", "if", "val", "]", "csr", "=", "cls", ".", "create_csr", "(", "common_name", ",", "private_key", ",", "params", ")", "if", "csr", "and", "os", ".", "path", ".", "exists", "(", "csr", ")", ":", "with", "open", "(", "csr", ")", "as", "fcsr", ":", "csr", "=", "fcsr", ".", "read", "(", ")", "return", "csr" ]
Create a PK and a CSR if needed.
[ "Create", "a", "PK", "and", "a", "CSR", "if", "needed", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/cert.py#L377-L399
11,105
Gandi/gandi.cli
gandi/cli/modules/cert.py
Certificate.pretty_format_cert
def pretty_format_cert(cls, cert): """ Pretty display of a certificate.""" crt = cert.get('cert') if crt: crt = ('-----BEGIN CERTIFICATE-----\n' + '\n'.join([crt[index * 64:(index + 1) * 64] for index in range(int(len(crt) / 64) + 1)]).rstrip('\n') + # noqa '\n-----END CERTIFICATE-----') return crt
python
def pretty_format_cert(cls, cert): """ Pretty display of a certificate.""" crt = cert.get('cert') if crt: crt = ('-----BEGIN CERTIFICATE-----\n' + '\n'.join([crt[index * 64:(index + 1) * 64] for index in range(int(len(crt) / 64) + 1)]).rstrip('\n') + # noqa '\n-----END CERTIFICATE-----') return crt
[ "def", "pretty_format_cert", "(", "cls", ",", "cert", ")", ":", "crt", "=", "cert", ".", "get", "(", "'cert'", ")", "if", "crt", ":", "crt", "=", "(", "'-----BEGIN CERTIFICATE-----\\n'", "+", "'\\n'", ".", "join", "(", "[", "crt", "[", "index", "*", "64", ":", "(", "index", "+", "1", ")", "*", "64", "]", "for", "index", "in", "range", "(", "int", "(", "len", "(", "crt", ")", "/", "64", ")", "+", "1", ")", "]", ")", ".", "rstrip", "(", "'\\n'", ")", "+", "# noqa", "'\\n-----END CERTIFICATE-----'", ")", "return", "crt" ]
Pretty display of a certificate.
[ "Pretty", "display", "of", "a", "certificate", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/cert.py#L402-L410
11,106
Gandi/gandi.cli
gandi/cli/commands/webacc.py
info
def info(gandi, resource, format): """ Display information about a webaccelerator """ result = gandi.webacc.info(resource) if format: output_json(gandi, format, result) return result output_base = { 'name': result['name'], 'algorithm': result['lb']['algorithm'], 'datacenter': result['datacenter']['name'], 'state': result['state'], 'ssl': 'Disable' if result['ssl_enable'] is False else 'Enabled' } output_keys = ['name', 'state', 'datacenter', 'ssl', 'algorithm'] output_generic(gandi, output_base, output_keys, justify=14) gandi.echo('Vhosts :') for vhost in result['vhosts']: output_vhosts = ['vhost', 'ssl'] vhost['vhost'] = vhost['name'] vhost['ssl'] = 'None' if vhost['cert_id'] is None else 'Exists' output_sub_generic(gandi, vhost, output_vhosts, justify=14) gandi.echo('') gandi.echo('Backends :') for server in result['servers']: try: ip = gandi.ip.info(server['ip']) iface = gandi.iface.info(ip['iface_id']) server['name'] = gandi.iaas.info(iface['vm_id'])['hostname'] output_servers = ['name', 'ip', 'port', 'state'] except Exception: warningmsg = ('\tBackend with ip address %s no longer exists.' '\n\tYou should remove it.' % server['ip']) gandi.echo(warningmsg) output_servers = ['ip', 'port', 'state'] output_sub_generic(gandi, server, output_servers, justify=14) gandi.echo('') gandi.echo('Probe :') output_probe = ['state', 'host', 'interval', 'method', 'response', 'threshold', 'timeout', 'url', 'window'] result['probe']['state'] = ('Disable' if result['probe']['enable'] is False else 'Enabled') output_sub_generic(gandi, result['probe'], output_probe, justify=14) return result
python
def info(gandi, resource, format): """ Display information about a webaccelerator """ result = gandi.webacc.info(resource) if format: output_json(gandi, format, result) return result output_base = { 'name': result['name'], 'algorithm': result['lb']['algorithm'], 'datacenter': result['datacenter']['name'], 'state': result['state'], 'ssl': 'Disable' if result['ssl_enable'] is False else 'Enabled' } output_keys = ['name', 'state', 'datacenter', 'ssl', 'algorithm'] output_generic(gandi, output_base, output_keys, justify=14) gandi.echo('Vhosts :') for vhost in result['vhosts']: output_vhosts = ['vhost', 'ssl'] vhost['vhost'] = vhost['name'] vhost['ssl'] = 'None' if vhost['cert_id'] is None else 'Exists' output_sub_generic(gandi, vhost, output_vhosts, justify=14) gandi.echo('') gandi.echo('Backends :') for server in result['servers']: try: ip = gandi.ip.info(server['ip']) iface = gandi.iface.info(ip['iface_id']) server['name'] = gandi.iaas.info(iface['vm_id'])['hostname'] output_servers = ['name', 'ip', 'port', 'state'] except Exception: warningmsg = ('\tBackend with ip address %s no longer exists.' '\n\tYou should remove it.' % server['ip']) gandi.echo(warningmsg) output_servers = ['ip', 'port', 'state'] output_sub_generic(gandi, server, output_servers, justify=14) gandi.echo('') gandi.echo('Probe :') output_probe = ['state', 'host', 'interval', 'method', 'response', 'threshold', 'timeout', 'url', 'window'] result['probe']['state'] = ('Disable' if result['probe']['enable'] is False else 'Enabled') output_sub_generic(gandi, result['probe'], output_probe, justify=14) return result
[ "def", "info", "(", "gandi", ",", "resource", ",", "format", ")", ":", "result", "=", "gandi", ".", "webacc", ".", "info", "(", "resource", ")", "if", "format", ":", "output_json", "(", "gandi", ",", "format", ",", "result", ")", "return", "result", "output_base", "=", "{", "'name'", ":", "result", "[", "'name'", "]", ",", "'algorithm'", ":", "result", "[", "'lb'", "]", "[", "'algorithm'", "]", ",", "'datacenter'", ":", "result", "[", "'datacenter'", "]", "[", "'name'", "]", ",", "'state'", ":", "result", "[", "'state'", "]", ",", "'ssl'", ":", "'Disable'", "if", "result", "[", "'ssl_enable'", "]", "is", "False", "else", "'Enabled'", "}", "output_keys", "=", "[", "'name'", ",", "'state'", ",", "'datacenter'", ",", "'ssl'", ",", "'algorithm'", "]", "output_generic", "(", "gandi", ",", "output_base", ",", "output_keys", ",", "justify", "=", "14", ")", "gandi", ".", "echo", "(", "'Vhosts :'", ")", "for", "vhost", "in", "result", "[", "'vhosts'", "]", ":", "output_vhosts", "=", "[", "'vhost'", ",", "'ssl'", "]", "vhost", "[", "'vhost'", "]", "=", "vhost", "[", "'name'", "]", "vhost", "[", "'ssl'", "]", "=", "'None'", "if", "vhost", "[", "'cert_id'", "]", "is", "None", "else", "'Exists'", "output_sub_generic", "(", "gandi", ",", "vhost", ",", "output_vhosts", ",", "justify", "=", "14", ")", "gandi", ".", "echo", "(", "''", ")", "gandi", ".", "echo", "(", "'Backends :'", ")", "for", "server", "in", "result", "[", "'servers'", "]", ":", "try", ":", "ip", "=", "gandi", ".", "ip", ".", "info", "(", "server", "[", "'ip'", "]", ")", "iface", "=", "gandi", ".", "iface", ".", "info", "(", "ip", "[", "'iface_id'", "]", ")", "server", "[", "'name'", "]", "=", "gandi", ".", "iaas", ".", "info", "(", "iface", "[", "'vm_id'", "]", ")", "[", "'hostname'", "]", "output_servers", "=", "[", "'name'", ",", "'ip'", ",", "'port'", ",", "'state'", "]", "except", "Exception", ":", "warningmsg", "=", "(", "'\\tBackend with ip address %s no longer exists.'", "'\\n\\tYou should remove it.'", "%", "server", "[", "'ip'", "]", ")", "gandi", ".", "echo", "(", "warningmsg", ")", "output_servers", "=", "[", "'ip'", ",", "'port'", ",", "'state'", "]", "output_sub_generic", "(", "gandi", ",", "server", ",", "output_servers", ",", "justify", "=", "14", ")", "gandi", ".", "echo", "(", "''", ")", "gandi", ".", "echo", "(", "'Probe :'", ")", "output_probe", "=", "[", "'state'", ",", "'host'", ",", "'interval'", ",", "'method'", ",", "'response'", ",", "'threshold'", ",", "'timeout'", ",", "'url'", ",", "'window'", "]", "result", "[", "'probe'", "]", "[", "'state'", "]", "=", "(", "'Disable'", "if", "result", "[", "'probe'", "]", "[", "'enable'", "]", "is", "False", "else", "'Enabled'", ")", "output_sub_generic", "(", "gandi", ",", "result", "[", "'probe'", "]", ",", "output_probe", ",", "justify", "=", "14", ")", "return", "result" ]
Display information about a webaccelerator
[ "Display", "information", "about", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/webacc.py#L80-L127
11,107
Gandi/gandi.cli
gandi/cli/commands/webacc.py
delete
def delete(gandi, webacc, vhost, backend, port): """ Delete a webaccelerator, a vhost or a backend """ result = [] if webacc: result = gandi.webacc.delete(webacc) if backend: backends = backend for backend in backends: if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_remove(backend) if vhost: vhosts = vhost for vhost in vhosts: result = gandi.webacc.vhost_remove(vhost) return result
python
def delete(gandi, webacc, vhost, backend, port): """ Delete a webaccelerator, a vhost or a backend """ result = [] if webacc: result = gandi.webacc.delete(webacc) if backend: backends = backend for backend in backends: if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_remove(backend) if vhost: vhosts = vhost for vhost in vhosts: result = gandi.webacc.vhost_remove(vhost) return result
[ "def", "delete", "(", "gandi", ",", "webacc", ",", "vhost", ",", "backend", ",", "port", ")", ":", "result", "=", "[", "]", "if", "webacc", ":", "result", "=", "gandi", ".", "webacc", ".", "delete", "(", "webacc", ")", "if", "backend", ":", "backends", "=", "backend", "for", "backend", "in", "backends", ":", "if", "'port'", "not", "in", "backend", ":", "if", "not", "port", ":", "backend", "[", "'port'", "]", "=", "click", ".", "prompt", "(", "'Please set a port for '", "'backends. If you want to '", "' different port for '", "'each backend, use `-b '", "'ip:port`'", ",", "type", "=", "int", ")", "else", ":", "backend", "[", "'port'", "]", "=", "port", "result", "=", "gandi", ".", "webacc", ".", "backend_remove", "(", "backend", ")", "if", "vhost", ":", "vhosts", "=", "vhost", "for", "vhost", "in", "vhosts", ":", "result", "=", "gandi", ".", "webacc", ".", "vhost_remove", "(", "vhost", ")", "return", "result" ]
Delete a webaccelerator, a vhost or a backend
[ "Delete", "a", "webaccelerator", "a", "vhost", "or", "a", "backend" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/webacc.py#L215-L240
11,108
Gandi/gandi.cli
gandi/cli/commands/webacc.py
add
def add(gandi, resource, vhost, zone_alter, backend, port, ssl, private_key, poll_cert): """ Add a backend or a vhost on a webaccelerator """ result = [] if backend: backends = backend for backend in backends: # Check if a port is set for each backend, else set a default port if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_add(resource, backend) if vhost: if not gandi.hostedcert.activate_ssl(vhost, ssl, private_key, poll_cert): return vhosts = vhost for vhost in vhosts: params = {'vhost': vhost} if zone_alter: params['zone_alter'] = zone_alter result = gandi.webacc.vhost_add(resource, params) return result
python
def add(gandi, resource, vhost, zone_alter, backend, port, ssl, private_key, poll_cert): """ Add a backend or a vhost on a webaccelerator """ result = [] if backend: backends = backend for backend in backends: # Check if a port is set for each backend, else set a default port if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_add(resource, backend) if vhost: if not gandi.hostedcert.activate_ssl(vhost, ssl, private_key, poll_cert): return vhosts = vhost for vhost in vhosts: params = {'vhost': vhost} if zone_alter: params['zone_alter'] = zone_alter result = gandi.webacc.vhost_add(resource, params) return result
[ "def", "add", "(", "gandi", ",", "resource", ",", "vhost", ",", "zone_alter", ",", "backend", ",", "port", ",", "ssl", ",", "private_key", ",", "poll_cert", ")", ":", "result", "=", "[", "]", "if", "backend", ":", "backends", "=", "backend", "for", "backend", "in", "backends", ":", "# Check if a port is set for each backend, else set a default port", "if", "'port'", "not", "in", "backend", ":", "if", "not", "port", ":", "backend", "[", "'port'", "]", "=", "click", ".", "prompt", "(", "'Please set a port for '", "'backends. If you want to '", "' different port for '", "'each backend, use `-b '", "'ip:port`'", ",", "type", "=", "int", ")", "else", ":", "backend", "[", "'port'", "]", "=", "port", "result", "=", "gandi", ".", "webacc", ".", "backend_add", "(", "resource", ",", "backend", ")", "if", "vhost", ":", "if", "not", "gandi", ".", "hostedcert", ".", "activate_ssl", "(", "vhost", ",", "ssl", ",", "private_key", ",", "poll_cert", ")", ":", "return", "vhosts", "=", "vhost", "for", "vhost", "in", "vhosts", ":", "params", "=", "{", "'vhost'", ":", "vhost", "}", "if", "zone_alter", ":", "params", "[", "'zone_alter'", "]", "=", "zone_alter", "result", "=", "gandi", ".", "webacc", ".", "vhost_add", "(", "resource", ",", "params", ")", "return", "result" ]
Add a backend or a vhost on a webaccelerator
[ "Add", "a", "backend", "or", "a", "vhost", "on", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/webacc.py#L260-L289
11,109
Gandi/gandi.cli
gandi/cli/commands/webacc.py
enable
def enable(gandi, resource, backend, port, probe): """ Enable a backend or a probe on a webaccelerator """ result = [] if backend: backends = backend for backend in backends: if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_enable(backend) if probe: if not resource: gandi.echo('You need to indicate the Webaccelerator name') return result = gandi.webacc.probe_enable(resource) return result
python
def enable(gandi, resource, backend, port, probe): """ Enable a backend or a probe on a webaccelerator """ result = [] if backend: backends = backend for backend in backends: if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_enable(backend) if probe: if not resource: gandi.echo('You need to indicate the Webaccelerator name') return result = gandi.webacc.probe_enable(resource) return result
[ "def", "enable", "(", "gandi", ",", "resource", ",", "backend", ",", "port", ",", "probe", ")", ":", "result", "=", "[", "]", "if", "backend", ":", "backends", "=", "backend", "for", "backend", "in", "backends", ":", "if", "'port'", "not", "in", "backend", ":", "if", "not", "port", ":", "backend", "[", "'port'", "]", "=", "click", ".", "prompt", "(", "'Please set a port for '", "'backends. If you want to '", "' different port for '", "'each backend, use `-b '", "'ip:port`'", ",", "type", "=", "int", ")", "else", ":", "backend", "[", "'port'", "]", "=", "port", "result", "=", "gandi", ".", "webacc", ".", "backend_enable", "(", "backend", ")", "if", "probe", ":", "if", "not", "resource", ":", "gandi", ".", "echo", "(", "'You need to indicate the Webaccelerator name'", ")", "return", "result", "=", "gandi", ".", "webacc", ".", "probe_enable", "(", "resource", ")", "return", "result" ]
Enable a backend or a probe on a webaccelerator
[ "Enable", "a", "backend", "or", "a", "probe", "on", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/webacc.py#L301-L324
11,110
Gandi/gandi.cli
gandi/cli/commands/webacc.py
disable
def disable(gandi, resource, backend, port, probe): """ Disable a backend or a probe on a webaccelerator """ result = [] if backend: backends = backend for backend in backends: if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_disable(backend) if probe: if not resource: gandi.echo('You need to indicate the Webaccelerator name') return result = gandi.webacc.probe_disable(resource) return result
python
def disable(gandi, resource, backend, port, probe): """ Disable a backend or a probe on a webaccelerator """ result = [] if backend: backends = backend for backend in backends: if 'port' not in backend: if not port: backend['port'] = click.prompt('Please set a port for ' 'backends. If you want to ' ' different port for ' 'each backend, use `-b ' 'ip:port`', type=int) else: backend['port'] = port result = gandi.webacc.backend_disable(backend) if probe: if not resource: gandi.echo('You need to indicate the Webaccelerator name') return result = gandi.webacc.probe_disable(resource) return result
[ "def", "disable", "(", "gandi", ",", "resource", ",", "backend", ",", "port", ",", "probe", ")", ":", "result", "=", "[", "]", "if", "backend", ":", "backends", "=", "backend", "for", "backend", "in", "backends", ":", "if", "'port'", "not", "in", "backend", ":", "if", "not", "port", ":", "backend", "[", "'port'", "]", "=", "click", ".", "prompt", "(", "'Please set a port for '", "'backends. If you want to '", "' different port for '", "'each backend, use `-b '", "'ip:port`'", ",", "type", "=", "int", ")", "else", ":", "backend", "[", "'port'", "]", "=", "port", "result", "=", "gandi", ".", "webacc", ".", "backend_disable", "(", "backend", ")", "if", "probe", ":", "if", "not", "resource", ":", "gandi", ".", "echo", "(", "'You need to indicate the Webaccelerator name'", ")", "return", "result", "=", "gandi", ".", "webacc", ".", "probe_disable", "(", "resource", ")", "return", "result" ]
Disable a backend or a probe on a webaccelerator
[ "Disable", "a", "backend", "or", "a", "probe", "on", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/webacc.py#L336-L359
11,111
Gandi/gandi.cli
gandi/cli/commands/webacc.py
probe
def probe(gandi, resource, enable, disable, test, host, interval, http_method, http_response, threshold, timeout, url, window): """ Manage a probe for a webaccelerator """ result = gandi.webacc.probe(resource, enable, disable, test, host, interval, http_method, http_response, threshold, timeout, url, window) output_keys = ['status', 'timeout'] output_generic(gandi, result, output_keys, justify=14) return result
python
def probe(gandi, resource, enable, disable, test, host, interval, http_method, http_response, threshold, timeout, url, window): """ Manage a probe for a webaccelerator """ result = gandi.webacc.probe(resource, enable, disable, test, host, interval, http_method, http_response, threshold, timeout, url, window) output_keys = ['status', 'timeout'] output_generic(gandi, result, output_keys, justify=14) return result
[ "def", "probe", "(", "gandi", ",", "resource", ",", "enable", ",", "disable", ",", "test", ",", "host", ",", "interval", ",", "http_method", ",", "http_response", ",", "threshold", ",", "timeout", ",", "url", ",", "window", ")", ":", "result", "=", "gandi", ".", "webacc", ".", "probe", "(", "resource", ",", "enable", ",", "disable", ",", "test", ",", "host", ",", "interval", ",", "http_method", ",", "http_response", ",", "threshold", ",", "timeout", ",", "url", ",", "window", ")", "output_keys", "=", "[", "'status'", ",", "'timeout'", "]", "output_generic", "(", "gandi", ",", "result", ",", "output_keys", ",", "justify", "=", "14", ")", "return", "result" ]
Manage a probe for a webaccelerator
[ "Manage", "a", "probe", "for", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/webacc.py#L385-L393
11,112
Gandi/gandi.cli
gandi/cli/commands/dns.py
domain_list
def domain_list(gandi): """List domains manageable by REST API.""" domains = gandi.dns.list() for domain in domains: gandi.echo(domain['fqdn']) return domains
python
def domain_list(gandi): """List domains manageable by REST API.""" domains = gandi.dns.list() for domain in domains: gandi.echo(domain['fqdn']) return domains
[ "def", "domain_list", "(", "gandi", ")", ":", "domains", "=", "gandi", ".", "dns", ".", "list", "(", ")", "for", "domain", "in", "domains", ":", "gandi", ".", "echo", "(", "domain", "[", "'fqdn'", "]", ")", "return", "domains" ]
List domains manageable by REST API.
[ "List", "domains", "manageable", "by", "REST", "API", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L19-L25
11,113
Gandi/gandi.cli
gandi/cli/commands/dns.py
list
def list(gandi, fqdn, name, sort, type, rrset_type, text): """Display records for a domain.""" domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return output_keys = ['name', 'ttl', 'type', 'values'] result = gandi.dns.records(fqdn, sort_by=sort, text=text) if text: gandi.echo(result) return result for num, rec in enumerate(result): if type and rec['rrset_type'] != type: continue if rrset_type and rec['rrset_type'] != rrset_type: continue if name and rec['rrset_name'] != name: continue if num: gandi.separator_line() output_dns_records(gandi, rec, output_keys) return result
python
def list(gandi, fqdn, name, sort, type, rrset_type, text): """Display records for a domain.""" domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return output_keys = ['name', 'ttl', 'type', 'values'] result = gandi.dns.records(fqdn, sort_by=sort, text=text) if text: gandi.echo(result) return result for num, rec in enumerate(result): if type and rec['rrset_type'] != type: continue if rrset_type and rec['rrset_type'] != rrset_type: continue if name and rec['rrset_name'] != name: continue if num: gandi.separator_line() output_dns_records(gandi, rec, output_keys) return result
[ "def", "list", "(", "gandi", ",", "fqdn", ",", "name", ",", "sort", ",", "type", ",", "rrset_type", ",", "text", ")", ":", "domains", "=", "gandi", ".", "dns", ".", "list", "(", ")", "domains", "=", "[", "domain", "[", "'fqdn'", "]", "for", "domain", "in", "domains", "]", "if", "fqdn", "not", "in", "domains", ":", "gandi", ".", "echo", "(", "'Sorry domain %s does not exist'", "%", "fqdn", ")", "gandi", ".", "echo", "(", "'Please use one of the following: %s'", "%", "', '", ".", "join", "(", "domains", ")", ")", "return", "output_keys", "=", "[", "'name'", ",", "'ttl'", ",", "'type'", ",", "'values'", "]", "result", "=", "gandi", ".", "dns", ".", "records", "(", "fqdn", ",", "sort_by", "=", "sort", ",", "text", "=", "text", ")", "if", "text", ":", "gandi", ".", "echo", "(", "result", ")", "return", "result", "for", "num", ",", "rec", "in", "enumerate", "(", "result", ")", ":", "if", "type", "and", "rec", "[", "'rrset_type'", "]", "!=", "type", ":", "continue", "if", "rrset_type", "and", "rec", "[", "'rrset_type'", "]", "!=", "rrset_type", ":", "continue", "if", "name", "and", "rec", "[", "'rrset_name'", "]", "!=", "name", ":", "continue", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_dns_records", "(", "gandi", ",", "rec", ",", "output_keys", ")", "return", "result" ]
Display records for a domain.
[ "Display", "records", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L40-L67
11,114
Gandi/gandi.cli
gandi/cli/commands/dns.py
create
def create(gandi, fqdn, name, type, value, ttl): """Create new record entry for a domain. multiple value parameters can be provided. """ domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return result = gandi.dns.add_record(fqdn, name, type, value, ttl) gandi.echo(result['message'])
python
def create(gandi, fqdn, name, type, value, ttl): """Create new record entry for a domain. multiple value parameters can be provided. """ domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return result = gandi.dns.add_record(fqdn, name, type, value, ttl) gandi.echo(result['message'])
[ "def", "create", "(", "gandi", ",", "fqdn", ",", "name", ",", "type", ",", "value", ",", "ttl", ")", ":", "domains", "=", "gandi", ".", "dns", ".", "list", "(", ")", "domains", "=", "[", "domain", "[", "'fqdn'", "]", "for", "domain", "in", "domains", "]", "if", "fqdn", "not", "in", "domains", ":", "gandi", ".", "echo", "(", "'Sorry domain %s does not exist'", "%", "fqdn", ")", "gandi", ".", "echo", "(", "'Please use one of the following: %s'", "%", "', '", ".", "join", "(", "domains", ")", ")", "return", "result", "=", "gandi", ".", "dns", ".", "add_record", "(", "fqdn", ",", "name", ",", "type", ",", "value", ",", "ttl", ")", "gandi", ".", "echo", "(", "result", "[", "'message'", "]", ")" ]
Create new record entry for a domain. multiple value parameters can be provided.
[ "Create", "new", "record", "entry", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L78-L91
11,115
Gandi/gandi.cli
gandi/cli/commands/dns.py
update
def update(gandi, fqdn, name, type, value, ttl, file): """Update record entry for a domain. --file option will ignore other parameters and overwrite current zone content with provided file content. """ domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return content = '' if file: content = file.read() elif not sys.stdin.isatty(): content = click.get_text_stream('stdin').read() content = content.strip() if not content and not name and not type and not value: click.echo('Cannot find parameters for zone content to update.') return if name and type and not value: click.echo('You must provide one or more value parameter.') return result = gandi.dns.update_record(fqdn, name, type, value, ttl, content) gandi.echo(result['message'])
python
def update(gandi, fqdn, name, type, value, ttl, file): """Update record entry for a domain. --file option will ignore other parameters and overwrite current zone content with provided file content. """ domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return content = '' if file: content = file.read() elif not sys.stdin.isatty(): content = click.get_text_stream('stdin').read() content = content.strip() if not content and not name and not type and not value: click.echo('Cannot find parameters for zone content to update.') return if name and type and not value: click.echo('You must provide one or more value parameter.') return result = gandi.dns.update_record(fqdn, name, type, value, ttl, content) gandi.echo(result['message'])
[ "def", "update", "(", "gandi", ",", "fqdn", ",", "name", ",", "type", ",", "value", ",", "ttl", ",", "file", ")", ":", "domains", "=", "gandi", ".", "dns", ".", "list", "(", ")", "domains", "=", "[", "domain", "[", "'fqdn'", "]", "for", "domain", "in", "domains", "]", "if", "fqdn", "not", "in", "domains", ":", "gandi", ".", "echo", "(", "'Sorry domain %s does not exist'", "%", "fqdn", ")", "gandi", ".", "echo", "(", "'Please use one of the following: %s'", "%", "', '", ".", "join", "(", "domains", ")", ")", "return", "content", "=", "''", "if", "file", ":", "content", "=", "file", ".", "read", "(", ")", "elif", "not", "sys", ".", "stdin", ".", "isatty", "(", ")", ":", "content", "=", "click", ".", "get_text_stream", "(", "'stdin'", ")", ".", "read", "(", ")", "content", "=", "content", ".", "strip", "(", ")", "if", "not", "content", "and", "not", "name", "and", "not", "type", "and", "not", "value", ":", "click", ".", "echo", "(", "'Cannot find parameters for zone content to update.'", ")", "return", "if", "name", "and", "type", "and", "not", "value", ":", "click", ".", "echo", "(", "'You must provide one or more value parameter.'", ")", "return", "result", "=", "gandi", ".", "dns", ".", "update_record", "(", "fqdn", ",", "name", ",", "type", ",", "value", ",", "ttl", ",", "content", ")", "gandi", ".", "echo", "(", "result", "[", "'message'", "]", ")" ]
Update record entry for a domain. --file option will ignore other parameters and overwrite current zone content with provided file content.
[ "Update", "record", "entry", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L106-L135
11,116
Gandi/gandi.cli
gandi/cli/commands/dns.py
delete
def delete(gandi, fqdn, name, type, force): """Delete record entry for a domain.""" domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return if not force: if not name and not type: prompt = ("Are you sure to delete all records for domain %s ?" % fqdn) elif name and not type: prompt = ("Are you sure to delete all '%s' name records for " "domain %s ?" % (name, fqdn)) else: prompt = ("Are you sure to delete all '%s' records of type %s " "for domain %s ?" % (name, type, fqdn)) proceed = click.confirm(prompt) if not proceed: return result = gandi.dns.del_record(fqdn, name, type) gandi.echo('Delete successful.') return result
python
def delete(gandi, fqdn, name, type, force): """Delete record entry for a domain.""" domains = gandi.dns.list() domains = [domain['fqdn'] for domain in domains] if fqdn not in domains: gandi.echo('Sorry domain %s does not exist' % fqdn) gandi.echo('Please use one of the following: %s' % ', '.join(domains)) return if not force: if not name and not type: prompt = ("Are you sure to delete all records for domain %s ?" % fqdn) elif name and not type: prompt = ("Are you sure to delete all '%s' name records for " "domain %s ?" % (name, fqdn)) else: prompt = ("Are you sure to delete all '%s' records of type %s " "for domain %s ?" % (name, type, fqdn)) proceed = click.confirm(prompt) if not proceed: return result = gandi.dns.del_record(fqdn, name, type) gandi.echo('Delete successful.') return result
[ "def", "delete", "(", "gandi", ",", "fqdn", ",", "name", ",", "type", ",", "force", ")", ":", "domains", "=", "gandi", ".", "dns", ".", "list", "(", ")", "domains", "=", "[", "domain", "[", "'fqdn'", "]", "for", "domain", "in", "domains", "]", "if", "fqdn", "not", "in", "domains", ":", "gandi", ".", "echo", "(", "'Sorry domain %s does not exist'", "%", "fqdn", ")", "gandi", ".", "echo", "(", "'Please use one of the following: %s'", "%", "', '", ".", "join", "(", "domains", ")", ")", "return", "if", "not", "force", ":", "if", "not", "name", "and", "not", "type", ":", "prompt", "=", "(", "\"Are you sure to delete all records for domain %s ?\"", "%", "fqdn", ")", "elif", "name", "and", "not", "type", ":", "prompt", "=", "(", "\"Are you sure to delete all '%s' name records for \"", "\"domain %s ?\"", "%", "(", "name", ",", "fqdn", ")", ")", "else", ":", "prompt", "=", "(", "\"Are you sure to delete all '%s' records of type %s \"", "\"for domain %s ?\"", "%", "(", "name", ",", "type", ",", "fqdn", ")", ")", "proceed", "=", "click", ".", "confirm", "(", "prompt", ")", "if", "not", "proceed", ":", "return", "result", "=", "gandi", ".", "dns", ".", "del_record", "(", "fqdn", ",", "name", ",", "type", ")", "gandi", ".", "echo", "(", "'Delete successful.'", ")", "return", "result" ]
Delete record entry for a domain.
[ "Delete", "record", "entry", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L146-L173
11,117
Gandi/gandi.cli
gandi/cli/commands/dns.py
keys_list
def keys_list(gandi, fqdn): """List domain keys.""" keys = gandi.dns.keys(fqdn) output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'flags', 'status'] for num, key in enumerate(keys): if num: gandi.separator_line() output_generic(gandi, key, output_keys, justify=15) return keys
python
def keys_list(gandi, fqdn): """List domain keys.""" keys = gandi.dns.keys(fqdn) output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'flags', 'status'] for num, key in enumerate(keys): if num: gandi.separator_line() output_generic(gandi, key, output_keys, justify=15) return keys
[ "def", "keys_list", "(", "gandi", ",", "fqdn", ")", ":", "keys", "=", "gandi", ".", "dns", ".", "keys", "(", "fqdn", ")", "output_keys", "=", "[", "'uuid'", ",", "'algorithm'", ",", "'algorithm_name'", ",", "'ds'", ",", "'flags'", ",", "'status'", "]", "for", "num", ",", "key", "in", "enumerate", "(", "keys", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_generic", "(", "gandi", ",", "key", ",", "output_keys", ",", "justify", "=", "15", ")", "return", "keys" ]
List domain keys.
[ "List", "domain", "keys", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L185-L194
11,118
Gandi/gandi.cli
gandi/cli/commands/dns.py
keys_info
def keys_info(gandi, fqdn, key): """Display information about a domain key.""" key_info = gandi.dns.keys_info(fqdn, key) output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'fingerprint', 'public_key', 'flags', 'tag', 'status'] output_generic(gandi, key_info, output_keys, justify=15) return key_info
python
def keys_info(gandi, fqdn, key): """Display information about a domain key.""" key_info = gandi.dns.keys_info(fqdn, key) output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'fingerprint', 'public_key', 'flags', 'tag', 'status'] output_generic(gandi, key_info, output_keys, justify=15) return key_info
[ "def", "keys_info", "(", "gandi", ",", "fqdn", ",", "key", ")", ":", "key_info", "=", "gandi", ".", "dns", ".", "keys_info", "(", "fqdn", ",", "key", ")", "output_keys", "=", "[", "'uuid'", ",", "'algorithm'", ",", "'algorithm_name'", ",", "'ds'", ",", "'fingerprint'", ",", "'public_key'", ",", "'flags'", ",", "'tag'", ",", "'status'", "]", "output_generic", "(", "gandi", ",", "key_info", ",", "output_keys", ",", "justify", "=", "15", ")", "return", "key_info" ]
Display information about a domain key.
[ "Display", "information", "about", "a", "domain", "key", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L201-L207
11,119
Gandi/gandi.cli
gandi/cli/commands/dns.py
keys_create
def keys_create(gandi, fqdn, flag): """Create key for a domain.""" key_info = gandi.dns.keys_create(fqdn, int(flag)) output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'fingerprint', 'public_key', 'flags', 'tag', 'status'] output_generic(gandi, key_info, output_keys, justify=15) return key_info
python
def keys_create(gandi, fqdn, flag): """Create key for a domain.""" key_info = gandi.dns.keys_create(fqdn, int(flag)) output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'fingerprint', 'public_key', 'flags', 'tag', 'status'] output_generic(gandi, key_info, output_keys, justify=15) return key_info
[ "def", "keys_create", "(", "gandi", ",", "fqdn", ",", "flag", ")", ":", "key_info", "=", "gandi", ".", "dns", ".", "keys_create", "(", "fqdn", ",", "int", "(", "flag", ")", ")", "output_keys", "=", "[", "'uuid'", ",", "'algorithm'", ",", "'algorithm_name'", ",", "'ds'", ",", "'fingerprint'", ",", "'public_key'", ",", "'flags'", ",", "'tag'", ",", "'status'", "]", "output_generic", "(", "gandi", ",", "key_info", ",", "output_keys", ",", "justify", "=", "15", ")", "return", "key_info" ]
Create key for a domain.
[ "Create", "key", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/dns.py#L214-L221
11,120
Gandi/gandi.cli
gandi/cli/modules/docker.py
Docker.handle
def handle(cls, vm, args): """ Setup forwarding connection to given VM and pipe docker cmds over SSH. """ docker = Iaas.info(vm) if not docker: raise Exception('docker vm %s not found' % vm) if docker['state'] != 'running': Iaas.start(vm) # XXX remote_addr = docker['ifaces'][0]['ips'][0]['ip'] port = unixpipe.setup(remote_addr, 'root', '/var/run/docker.sock') os.environ['DOCKER_HOST'] = 'tcp://localhost:%d' % port cls.echo('using DOCKER_HOST=%s' % os.environ['DOCKER_HOST']) subprocess.call(['docker'] + list(args))
python
def handle(cls, vm, args): """ Setup forwarding connection to given VM and pipe docker cmds over SSH. """ docker = Iaas.info(vm) if not docker: raise Exception('docker vm %s not found' % vm) if docker['state'] != 'running': Iaas.start(vm) # XXX remote_addr = docker['ifaces'][0]['ips'][0]['ip'] port = unixpipe.setup(remote_addr, 'root', '/var/run/docker.sock') os.environ['DOCKER_HOST'] = 'tcp://localhost:%d' % port cls.echo('using DOCKER_HOST=%s' % os.environ['DOCKER_HOST']) subprocess.call(['docker'] + list(args))
[ "def", "handle", "(", "cls", ",", "vm", ",", "args", ")", ":", "docker", "=", "Iaas", ".", "info", "(", "vm", ")", "if", "not", "docker", ":", "raise", "Exception", "(", "'docker vm %s not found'", "%", "vm", ")", "if", "docker", "[", "'state'", "]", "!=", "'running'", ":", "Iaas", ".", "start", "(", "vm", ")", "# XXX", "remote_addr", "=", "docker", "[", "'ifaces'", "]", "[", "0", "]", "[", "'ips'", "]", "[", "0", "]", "[", "'ip'", "]", "port", "=", "unixpipe", ".", "setup", "(", "remote_addr", ",", "'root'", ",", "'/var/run/docker.sock'", ")", "os", ".", "environ", "[", "'DOCKER_HOST'", "]", "=", "'tcp://localhost:%d'", "%", "port", "cls", ".", "echo", "(", "'using DOCKER_HOST=%s'", "%", "os", ".", "environ", "[", "'DOCKER_HOST'", "]", ")", "subprocess", ".", "call", "(", "[", "'docker'", "]", "+", "list", "(", "args", ")", ")" ]
Setup forwarding connection to given VM and pipe docker cmds over SSH.
[ "Setup", "forwarding", "connection", "to", "given", "VM", "and", "pipe", "docker", "cmds", "over", "SSH", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/docker.py#L29-L48
11,121
Gandi/gandi.cli
gandi/cli/commands/vm.py
list
def list(gandi, state, id, limit, datacenter): """List virtual machines.""" options = { 'items_per_page': limit, } if state: options['state'] = state if datacenter: options['datacenter_id'] = gandi.datacenter.usable_id(datacenter) output_keys = ['hostname', 'state'] if id: output_keys.append('id') result = gandi.iaas.list(options) for num, vm in enumerate(result): if num: gandi.separator_line() output_vm(gandi, vm, [], output_keys) return result
python
def list(gandi, state, id, limit, datacenter): """List virtual machines.""" options = { 'items_per_page': limit, } if state: options['state'] = state if datacenter: options['datacenter_id'] = gandi.datacenter.usable_id(datacenter) output_keys = ['hostname', 'state'] if id: output_keys.append('id') result = gandi.iaas.list(options) for num, vm in enumerate(result): if num: gandi.separator_line() output_vm(gandi, vm, [], output_keys) return result
[ "def", "list", "(", "gandi", ",", "state", ",", "id", ",", "limit", ",", "datacenter", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", ",", "}", "if", "state", ":", "options", "[", "'state'", "]", "=", "state", "if", "datacenter", ":", "options", "[", "'datacenter_id'", "]", "=", "gandi", ".", "datacenter", ".", "usable_id", "(", "datacenter", ")", "output_keys", "=", "[", "'hostname'", ",", "'state'", "]", "if", "id", ":", "output_keys", ".", "append", "(", "'id'", ")", "result", "=", "gandi", ".", "iaas", ".", "list", "(", "options", ")", "for", "num", ",", "vm", "in", "enumerate", "(", "result", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_vm", "(", "gandi", ",", "vm", ",", "[", "]", ",", "output_keys", ")", "return", "result" ]
List virtual machines.
[ "List", "virtual", "machines", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vm.py#L32-L52
11,122
Gandi/gandi.cli
gandi/cli/commands/vm.py
info
def info(gandi, resource, stat): """Display information about a virtual machine. Resource can be a Hostname or an ID """ output_keys = ['hostname', 'state', 'cores', 'memory', 'console', 'datacenter', 'ip'] justify = 14 if stat is True: sampler = {'unit': 'hours', 'value': 1, 'function': 'max'} time_range = 3600 * 24 query_vif = 'vif.bytes.all' query_vbd = 'vbd.bytes.all' resource = sorted(tuple(set(resource))) datacenters = gandi.datacenter.list() ret = [] for num, item in enumerate(resource): if num: gandi.separator_line() vm = gandi.iaas.info(item) output_vm(gandi, vm, datacenters, output_keys, justify) ret.append(vm) for disk in vm['disks']: gandi.echo('') disk_out_keys = ['label', 'kernel_version', 'name', 'size'] output_image(gandi, disk, datacenters, disk_out_keys, justify, warn_deprecated=False) if stat is True: metrics_vif = gandi.metric.query(vm['id'], time_range, query_vif, 'vm', sampler) metrics_vbd = gandi.metric.query(vm['id'], time_range, query_vbd, 'vm', sampler) gandi.echo('') gandi.echo('vm network stats') output_metric(gandi, metrics_vif, 'direction', justify) gandi.echo('disk network stats') output_metric(gandi, metrics_vbd, 'direction', justify) return ret
python
def info(gandi, resource, stat): """Display information about a virtual machine. Resource can be a Hostname or an ID """ output_keys = ['hostname', 'state', 'cores', 'memory', 'console', 'datacenter', 'ip'] justify = 14 if stat is True: sampler = {'unit': 'hours', 'value': 1, 'function': 'max'} time_range = 3600 * 24 query_vif = 'vif.bytes.all' query_vbd = 'vbd.bytes.all' resource = sorted(tuple(set(resource))) datacenters = gandi.datacenter.list() ret = [] for num, item in enumerate(resource): if num: gandi.separator_line() vm = gandi.iaas.info(item) output_vm(gandi, vm, datacenters, output_keys, justify) ret.append(vm) for disk in vm['disks']: gandi.echo('') disk_out_keys = ['label', 'kernel_version', 'name', 'size'] output_image(gandi, disk, datacenters, disk_out_keys, justify, warn_deprecated=False) if stat is True: metrics_vif = gandi.metric.query(vm['id'], time_range, query_vif, 'vm', sampler) metrics_vbd = gandi.metric.query(vm['id'], time_range, query_vbd, 'vm', sampler) gandi.echo('') gandi.echo('vm network stats') output_metric(gandi, metrics_vif, 'direction', justify) gandi.echo('disk network stats') output_metric(gandi, metrics_vbd, 'direction', justify) return ret
[ "def", "info", "(", "gandi", ",", "resource", ",", "stat", ")", ":", "output_keys", "=", "[", "'hostname'", ",", "'state'", ",", "'cores'", ",", "'memory'", ",", "'console'", ",", "'datacenter'", ",", "'ip'", "]", "justify", "=", "14", "if", "stat", "is", "True", ":", "sampler", "=", "{", "'unit'", ":", "'hours'", ",", "'value'", ":", "1", ",", "'function'", ":", "'max'", "}", "time_range", "=", "3600", "*", "24", "query_vif", "=", "'vif.bytes.all'", "query_vbd", "=", "'vbd.bytes.all'", "resource", "=", "sorted", "(", "tuple", "(", "set", "(", "resource", ")", ")", ")", "datacenters", "=", "gandi", ".", "datacenter", ".", "list", "(", ")", "ret", "=", "[", "]", "for", "num", ",", "item", "in", "enumerate", "(", "resource", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "vm", "=", "gandi", ".", "iaas", ".", "info", "(", "item", ")", "output_vm", "(", "gandi", ",", "vm", ",", "datacenters", ",", "output_keys", ",", "justify", ")", "ret", ".", "append", "(", "vm", ")", "for", "disk", "in", "vm", "[", "'disks'", "]", ":", "gandi", ".", "echo", "(", "''", ")", "disk_out_keys", "=", "[", "'label'", ",", "'kernel_version'", ",", "'name'", ",", "'size'", "]", "output_image", "(", "gandi", ",", "disk", ",", "datacenters", ",", "disk_out_keys", ",", "justify", ",", "warn_deprecated", "=", "False", ")", "if", "stat", "is", "True", ":", "metrics_vif", "=", "gandi", ".", "metric", ".", "query", "(", "vm", "[", "'id'", "]", ",", "time_range", ",", "query_vif", ",", "'vm'", ",", "sampler", ")", "metrics_vbd", "=", "gandi", ".", "metric", ".", "query", "(", "vm", "[", "'id'", "]", ",", "time_range", ",", "query_vbd", ",", "'vm'", ",", "sampler", ")", "gandi", ".", "echo", "(", "''", ")", "gandi", ".", "echo", "(", "'vm network stats'", ")", "output_metric", "(", "gandi", ",", "metrics_vif", ",", "'direction'", ",", "justify", ")", "gandi", ".", "echo", "(", "'disk network stats'", ")", "output_metric", "(", "gandi", ",", "metrics_vbd", ",", "'direction'", ",", "justify", ")", "return", "ret" ]
Display information about a virtual machine. Resource can be a Hostname or an ID
[ "Display", "information", "about", "a", "virtual", "machine", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vm.py#L60-L99
11,123
Gandi/gandi.cli
gandi/cli/commands/vm.py
ssh
def ssh(gandi, resource, login, identity, wipe_key, wait, args): """Spawn an SSH session to virtual machine. Resource can be a Hostname or an ID """ if '@' in resource: (login, resource) = resource.split('@', 1) if wipe_key: gandi.iaas.ssh_keyscan(resource) if wait: gandi.iaas.wait_for_sshd(resource) gandi.iaas.ssh(resource, login, identity, args)
python
def ssh(gandi, resource, login, identity, wipe_key, wait, args): """Spawn an SSH session to virtual machine. Resource can be a Hostname or an ID """ if '@' in resource: (login, resource) = resource.split('@', 1) if wipe_key: gandi.iaas.ssh_keyscan(resource) if wait: gandi.iaas.wait_for_sshd(resource) gandi.iaas.ssh(resource, login, identity, args)
[ "def", "ssh", "(", "gandi", ",", "resource", ",", "login", ",", "identity", ",", "wipe_key", ",", "wait", ",", "args", ")", ":", "if", "'@'", "in", "resource", ":", "(", "login", ",", "resource", ")", "=", "resource", ".", "split", "(", "'@'", ",", "1", ")", "if", "wipe_key", ":", "gandi", ".", "iaas", ".", "ssh_keyscan", "(", "resource", ")", "if", "wait", ":", "gandi", ".", "iaas", ".", "wait_for_sshd", "(", "resource", ")", "gandi", ".", "iaas", ".", "ssh", "(", "resource", ",", "login", ",", "identity", ",", "args", ")" ]
Spawn an SSH session to virtual machine. Resource can be a Hostname or an ID
[ "Spawn", "an", "SSH", "session", "to", "virtual", "machine", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vm.py#L420-L431
11,124
Gandi/gandi.cli
gandi/cli/commands/vm.py
images
def images(gandi, label, datacenter): """List available system images for virtual machines. You can also filter results using label, by example: $ gandi vm images Ubuntu --datacenter LU or $ gandi vm images 'Ubuntu 10.04' --datacenter LU """ output_keys = ['label', 'os_arch', 'kernel_version', 'disk_id', 'dc', 'name'] datacenters = gandi.datacenter.list() result = gandi.image.list(datacenter, label) for num, image in enumerate(result): if num: gandi.separator_line() output_image(gandi, image, datacenters, output_keys) # also display usable disks result = gandi.disk.list_create(datacenter, label) for disk in result: gandi.separator_line() output_image(gandi, disk, datacenters, output_keys) return result
python
def images(gandi, label, datacenter): """List available system images for virtual machines. You can also filter results using label, by example: $ gandi vm images Ubuntu --datacenter LU or $ gandi vm images 'Ubuntu 10.04' --datacenter LU """ output_keys = ['label', 'os_arch', 'kernel_version', 'disk_id', 'dc', 'name'] datacenters = gandi.datacenter.list() result = gandi.image.list(datacenter, label) for num, image in enumerate(result): if num: gandi.separator_line() output_image(gandi, image, datacenters, output_keys) # also display usable disks result = gandi.disk.list_create(datacenter, label) for disk in result: gandi.separator_line() output_image(gandi, disk, datacenters, output_keys) return result
[ "def", "images", "(", "gandi", ",", "label", ",", "datacenter", ")", ":", "output_keys", "=", "[", "'label'", ",", "'os_arch'", ",", "'kernel_version'", ",", "'disk_id'", ",", "'dc'", ",", "'name'", "]", "datacenters", "=", "gandi", ".", "datacenter", ".", "list", "(", ")", "result", "=", "gandi", ".", "image", ".", "list", "(", "datacenter", ",", "label", ")", "for", "num", ",", "image", "in", "enumerate", "(", "result", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_image", "(", "gandi", ",", "image", ",", "datacenters", ",", "output_keys", ")", "# also display usable disks", "result", "=", "gandi", ".", "disk", ".", "list_create", "(", "datacenter", ",", "label", ")", "for", "disk", "in", "result", ":", "gandi", ".", "separator_line", "(", ")", "output_image", "(", "gandi", ",", "disk", ",", "datacenters", ",", "output_keys", ")", "return", "result" ]
List available system images for virtual machines. You can also filter results using label, by example: $ gandi vm images Ubuntu --datacenter LU or $ gandi vm images 'Ubuntu 10.04' --datacenter LU
[ "List", "available", "system", "images", "for", "virtual", "machines", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vm.py#L439-L467
11,125
Gandi/gandi.cli
gandi/cli/commands/vm.py
kernels
def kernels(gandi, vm, datacenter, flavor, match): """List available kernels.""" if vm: vm = gandi.iaas.info(vm) dc_list = gandi.datacenter.filtered_list(datacenter, vm) for num, dc in enumerate(dc_list): if num: gandi.echo('\n') output_datacenter(gandi, dc, ['dc_name']) kmap = gandi.kernel.list(dc['id'], flavor, match) for _flavor in kmap: gandi.separator_line() output_kernels(gandi, _flavor, kmap[_flavor])
python
def kernels(gandi, vm, datacenter, flavor, match): """List available kernels.""" if vm: vm = gandi.iaas.info(vm) dc_list = gandi.datacenter.filtered_list(datacenter, vm) for num, dc in enumerate(dc_list): if num: gandi.echo('\n') output_datacenter(gandi, dc, ['dc_name']) kmap = gandi.kernel.list(dc['id'], flavor, match) for _flavor in kmap: gandi.separator_line() output_kernels(gandi, _flavor, kmap[_flavor])
[ "def", "kernels", "(", "gandi", ",", "vm", ",", "datacenter", ",", "flavor", ",", "match", ")", ":", "if", "vm", ":", "vm", "=", "gandi", ".", "iaas", ".", "info", "(", "vm", ")", "dc_list", "=", "gandi", ".", "datacenter", ".", "filtered_list", "(", "datacenter", ",", "vm", ")", "for", "num", ",", "dc", "in", "enumerate", "(", "dc_list", ")", ":", "if", "num", ":", "gandi", ".", "echo", "(", "'\\n'", ")", "output_datacenter", "(", "gandi", ",", "dc", ",", "[", "'dc_name'", "]", ")", "kmap", "=", "gandi", ".", "kernel", ".", "list", "(", "dc", "[", "'id'", "]", ",", "flavor", ",", "match", ")", "for", "_flavor", "in", "kmap", ":", "gandi", ".", "separator_line", "(", ")", "output_kernels", "(", "gandi", ",", "_flavor", ",", "kmap", "[", "_flavor", "]", ")" ]
List available kernels.
[ "List", "available", "kernels", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vm.py#L479-L494
11,126
Gandi/gandi.cli
gandi/cli/commands/vm.py
datacenters
def datacenters(gandi, id): """List available datacenters.""" output_keys = ['iso', 'name', 'country', 'dc_code', 'status'] if id: output_keys.append('id') result = gandi.datacenter.list() for num, dc in enumerate(result): if num: gandi.separator_line() output_datacenter(gandi, dc, output_keys, justify=10) return result
python
def datacenters(gandi, id): """List available datacenters.""" output_keys = ['iso', 'name', 'country', 'dc_code', 'status'] if id: output_keys.append('id') result = gandi.datacenter.list() for num, dc in enumerate(result): if num: gandi.separator_line() output_datacenter(gandi, dc, output_keys, justify=10) return result
[ "def", "datacenters", "(", "gandi", ",", "id", ")", ":", "output_keys", "=", "[", "'iso'", ",", "'name'", ",", "'country'", ",", "'dc_code'", ",", "'status'", "]", "if", "id", ":", "output_keys", ".", "append", "(", "'id'", ")", "result", "=", "gandi", ".", "datacenter", ".", "list", "(", ")", "for", "num", ",", "dc", "in", "enumerate", "(", "result", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_datacenter", "(", "gandi", ",", "dc", ",", "output_keys", ",", "justify", "=", "10", ")", "return", "result" ]
List available datacenters.
[ "List", "available", "datacenters", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vm.py#L500-L512
11,127
Gandi/gandi.cli
gandi/cli/modules/hostedcert.py
HostedCert.usable_id
def usable_id(cls, id): """ Retrieve id from single input. """ hcs = cls.from_fqdn(id) if hcs: return [hc_['id'] for hc_ in hcs] try: return int(id) except (TypeError, ValueError): pass
python
def usable_id(cls, id): """ Retrieve id from single input. """ hcs = cls.from_fqdn(id) if hcs: return [hc_['id'] for hc_ in hcs] try: return int(id) except (TypeError, ValueError): pass
[ "def", "usable_id", "(", "cls", ",", "id", ")", ":", "hcs", "=", "cls", ".", "from_fqdn", "(", "id", ")", "if", "hcs", ":", "return", "[", "hc_", "[", "'id'", "]", "for", "hc_", "in", "hcs", "]", "try", ":", "return", "int", "(", "id", ")", "except", "(", "TypeError", ",", "ValueError", ")", ":", "pass" ]
Retrieve id from single input.
[ "Retrieve", "id", "from", "single", "input", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/hostedcert.py#L21-L30
11,128
Gandi/gandi.cli
gandi/cli/modules/hostedcert.py
HostedCert.infos
def infos(cls, fqdn): """ Display information about hosted certificates for a fqdn. """ if isinstance(fqdn, (list, tuple)): ids = [] for fqd_ in fqdn: ids.extend(cls.infos(fqd_)) return ids ids = cls.usable_id(fqdn) if not ids: return [] if not isinstance(ids, (list, tuple)): ids = [ids] return [cls.info(id_) for id_ in ids]
python
def infos(cls, fqdn): """ Display information about hosted certificates for a fqdn. """ if isinstance(fqdn, (list, tuple)): ids = [] for fqd_ in fqdn: ids.extend(cls.infos(fqd_)) return ids ids = cls.usable_id(fqdn) if not ids: return [] if not isinstance(ids, (list, tuple)): ids = [ids] return [cls.info(id_) for id_ in ids]
[ "def", "infos", "(", "cls", ",", "fqdn", ")", ":", "if", "isinstance", "(", "fqdn", ",", "(", "list", ",", "tuple", ")", ")", ":", "ids", "=", "[", "]", "for", "fqd_", "in", "fqdn", ":", "ids", ".", "extend", "(", "cls", ".", "infos", "(", "fqd_", ")", ")", "return", "ids", "ids", "=", "cls", ".", "usable_id", "(", "fqdn", ")", "if", "not", "ids", ":", "return", "[", "]", "if", "not", "isinstance", "(", "ids", ",", "(", "list", ",", "tuple", ")", ")", ":", "ids", "=", "[", "ids", "]", "return", "[", "cls", ".", "info", "(", "id_", ")", "for", "id_", "in", "ids", "]" ]
Display information about hosted certificates for a fqdn.
[ "Display", "information", "about", "hosted", "certificates", "for", "a", "fqdn", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/hostedcert.py#L44-L59
11,129
Gandi/gandi.cli
gandi/cli/modules/hostedcert.py
HostedCert.create
def create(cls, key, crt): """ Add a new crt in the hosted cert store. """ options = {'crt': crt, 'key': key} return cls.call('cert.hosted.create', options)
python
def create(cls, key, crt): """ Add a new crt in the hosted cert store. """ options = {'crt': crt, 'key': key} return cls.call('cert.hosted.create', options)
[ "def", "create", "(", "cls", ",", "key", ",", "crt", ")", ":", "options", "=", "{", "'crt'", ":", "crt", ",", "'key'", ":", "key", "}", "return", "cls", ".", "call", "(", "'cert.hosted.create'", ",", "options", ")" ]
Add a new crt in the hosted cert store.
[ "Add", "a", "new", "crt", "in", "the", "hosted", "cert", "store", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/hostedcert.py#L62-L65
11,130
Gandi/gandi.cli
gandi/cli/commands/domain.py
list
def list(gandi, limit): """List domains.""" options = {'items_per_page': limit} domains = gandi.domain.list(options) for domain in domains: gandi.echo(domain['fqdn']) return domains
python
def list(gandi, limit): """List domains.""" options = {'items_per_page': limit} domains = gandi.domain.list(options) for domain in domains: gandi.echo(domain['fqdn']) return domains
[ "def", "list", "(", "gandi", ",", "limit", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", "}", "domains", "=", "gandi", ".", "domain", ".", "list", "(", "options", ")", "for", "domain", "in", "domains", ":", "gandi", ".", "echo", "(", "domain", "[", "'fqdn'", "]", ")", "return", "domains" ]
List domains.
[ "List", "domains", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/domain.py#L26-L33
11,131
Gandi/gandi.cli
gandi/cli/commands/domain.py
info
def info(gandi, resource): """Display information about a domain.""" output_keys = ['fqdn', 'nameservers', 'services', 'zone_id', 'tags', 'created', 'expires', 'updated'] contact_field = ['owner', 'admin', 'bill', 'tech', 'reseller'] result = gandi.domain.info(resource) output_contact_info(gandi, result['contacts'], contact_field, justify=12) output_domain(gandi, result, output_keys, justify=12) return result
python
def info(gandi, resource): """Display information about a domain.""" output_keys = ['fqdn', 'nameservers', 'services', 'zone_id', 'tags', 'created', 'expires', 'updated'] contact_field = ['owner', 'admin', 'bill', 'tech', 'reseller'] result = gandi.domain.info(resource) output_contact_info(gandi, result['contacts'], contact_field, justify=12) output_domain(gandi, result, output_keys, justify=12) return result
[ "def", "info", "(", "gandi", ",", "resource", ")", ":", "output_keys", "=", "[", "'fqdn'", ",", "'nameservers'", ",", "'services'", ",", "'zone_id'", ",", "'tags'", ",", "'created'", ",", "'expires'", ",", "'updated'", "]", "contact_field", "=", "[", "'owner'", ",", "'admin'", ",", "'bill'", ",", "'tech'", ",", "'reseller'", "]", "result", "=", "gandi", ".", "domain", ".", "info", "(", "resource", ")", "output_contact_info", "(", "gandi", ",", "result", "[", "'contacts'", "]", ",", "contact_field", ",", "justify", "=", "12", ")", "output_domain", "(", "gandi", ",", "result", ",", "output_keys", ",", "justify", "=", "12", ")", "return", "result" ]
Display information about a domain.
[ "Display", "information", "about", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/domain.py#L39-L49
11,132
Gandi/gandi.cli
gandi/cli/commands/domain.py
create
def create(gandi, resource, domain, duration, owner, admin, tech, bill, nameserver, extra_parameter, background): """Buy a domain.""" if domain: gandi.echo('/!\ --domain option is deprecated and will be removed ' 'upon next release.') gandi.echo("You should use 'gandi domain create %s' instead." % domain) if (domain and resource) and (domain != resource): gandi.echo('/!\ You specified both an option and an argument which ' 'are different, please choose only one between: %s and %s.' % (domain, resource)) return _domain = domain or resource if not _domain: _domain = click.prompt('Name of the domain') result = gandi.domain.create(_domain, duration, owner, admin, tech, bill, nameserver, extra_parameter, background) if background: gandi.pretty_echo(result) return result
python
def create(gandi, resource, domain, duration, owner, admin, tech, bill, nameserver, extra_parameter, background): """Buy a domain.""" if domain: gandi.echo('/!\ --domain option is deprecated and will be removed ' 'upon next release.') gandi.echo("You should use 'gandi domain create %s' instead." % domain) if (domain and resource) and (domain != resource): gandi.echo('/!\ You specified both an option and an argument which ' 'are different, please choose only one between: %s and %s.' % (domain, resource)) return _domain = domain or resource if not _domain: _domain = click.prompt('Name of the domain') result = gandi.domain.create(_domain, duration, owner, admin, tech, bill, nameserver, extra_parameter, background) if background: gandi.pretty_echo(result) return result
[ "def", "create", "(", "gandi", ",", "resource", ",", "domain", ",", "duration", ",", "owner", ",", "admin", ",", "tech", ",", "bill", ",", "nameserver", ",", "extra_parameter", ",", "background", ")", ":", "if", "domain", ":", "gandi", ".", "echo", "(", "'/!\\ --domain option is deprecated and will be removed '", "'upon next release.'", ")", "gandi", ".", "echo", "(", "\"You should use 'gandi domain create %s' instead.\"", "%", "domain", ")", "if", "(", "domain", "and", "resource", ")", "and", "(", "domain", "!=", "resource", ")", ":", "gandi", ".", "echo", "(", "'/!\\ You specified both an option and an argument which '", "'are different, please choose only one between: %s and %s.'", "%", "(", "domain", ",", "resource", ")", ")", "return", "_domain", "=", "domain", "or", "resource", "if", "not", "_domain", ":", "_domain", "=", "click", ".", "prompt", "(", "'Name of the domain'", ")", "result", "=", "gandi", ".", "domain", ".", "create", "(", "_domain", ",", "duration", ",", "owner", ",", "admin", ",", "tech", ",", "bill", ",", "nameserver", ",", "extra_parameter", ",", "background", ")", "if", "background", ":", "gandi", ".", "pretty_echo", "(", "result", ")", "return", "result" ]
Buy a domain.
[ "Buy", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/domain.py#L74-L97
11,133
Gandi/gandi.cli
gandi/cli/commands/root.py
api
def api(gandi): """Display information about API used.""" key_name = 'API version' result = gandi.api.info() result[key_name] = result.pop('api_version') output_generic(gandi, result, [key_name]) return result
python
def api(gandi): """Display information about API used.""" key_name = 'API version' result = gandi.api.info() result[key_name] = result.pop('api_version') output_generic(gandi, result, [key_name]) return result
[ "def", "api", "(", "gandi", ")", ":", "key_name", "=", "'API version'", "result", "=", "gandi", ".", "api", ".", "info", "(", ")", "result", "[", "key_name", "]", "=", "result", ".", "pop", "(", "'api_version'", ")", "output_generic", "(", "gandi", ",", "result", ",", "[", "key_name", "]", ")", "return", "result" ]
Display information about API used.
[ "Display", "information", "about", "API", "used", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/root.py#L34-L42
11,134
Gandi/gandi.cli
gandi/cli/commands/root.py
help
def help(ctx, command): """Display help for a command.""" command = ' '.join(command) if not command: click.echo(cli.get_help(ctx)) return cmd = cli.get_command(ctx, command) if cmd: click.echo(cmd.get_help(ctx)) else: click.echo(cli.get_help(ctx))
python
def help(ctx, command): """Display help for a command.""" command = ' '.join(command) if not command: click.echo(cli.get_help(ctx)) return cmd = cli.get_command(ctx, command) if cmd: click.echo(cmd.get_help(ctx)) else: click.echo(cli.get_help(ctx))
[ "def", "help", "(", "ctx", ",", "command", ")", ":", "command", "=", "' '", ".", "join", "(", "command", ")", "if", "not", "command", ":", "click", ".", "echo", "(", "cli", ".", "get_help", "(", "ctx", ")", ")", "return", "cmd", "=", "cli", ".", "get_command", "(", "ctx", ",", "command", ")", "if", "cmd", ":", "click", ".", "echo", "(", "cmd", ".", "get_help", "(", "ctx", ")", ")", "else", ":", "click", ".", "echo", "(", "cli", ".", "get_help", "(", "ctx", ")", ")" ]
Display help for a command.
[ "Display", "help", "for", "a", "command", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/root.py#L48-L59
11,135
Gandi/gandi.cli
gandi/cli/commands/root.py
status
def status(gandi, service): """Display current status from status.gandi.net.""" if not service: global_status = gandi.status.status() if global_status['status'] == 'FOGGY': # something is going on but not affecting services filters = { 'category': 'Incident', 'current': True, } events = gandi.status.events(filters) for event in events: if event['services']: # do not process services continue event_url = gandi.status.event_timeline(event) service_detail = '%s - %s' % (event['title'], event_url) gandi.echo(service_detail) # then check other services descs = gandi.status.descriptions() needed = services = gandi.status.services() if service: needed = [serv for serv in services if serv['name'].lower() == service.lower()] for serv in needed: if serv['status'] != 'STORMY': output_service(gandi, serv['name'], descs[serv['status']]) continue filters = { 'category': 'Incident', 'services': serv['name'], 'current': True, } events = gandi.status.events(filters) for event in events: event_url = gandi.status.event_timeline(event) service_detail = '%s - %s' % (event['title'], event_url) output_service(gandi, serv['name'], service_detail) return services
python
def status(gandi, service): """Display current status from status.gandi.net.""" if not service: global_status = gandi.status.status() if global_status['status'] == 'FOGGY': # something is going on but not affecting services filters = { 'category': 'Incident', 'current': True, } events = gandi.status.events(filters) for event in events: if event['services']: # do not process services continue event_url = gandi.status.event_timeline(event) service_detail = '%s - %s' % (event['title'], event_url) gandi.echo(service_detail) # then check other services descs = gandi.status.descriptions() needed = services = gandi.status.services() if service: needed = [serv for serv in services if serv['name'].lower() == service.lower()] for serv in needed: if serv['status'] != 'STORMY': output_service(gandi, serv['name'], descs[serv['status']]) continue filters = { 'category': 'Incident', 'services': serv['name'], 'current': True, } events = gandi.status.events(filters) for event in events: event_url = gandi.status.event_timeline(event) service_detail = '%s - %s' % (event['title'], event_url) output_service(gandi, serv['name'], service_detail) return services
[ "def", "status", "(", "gandi", ",", "service", ")", ":", "if", "not", "service", ":", "global_status", "=", "gandi", ".", "status", ".", "status", "(", ")", "if", "global_status", "[", "'status'", "]", "==", "'FOGGY'", ":", "# something is going on but not affecting services", "filters", "=", "{", "'category'", ":", "'Incident'", ",", "'current'", ":", "True", ",", "}", "events", "=", "gandi", ".", "status", ".", "events", "(", "filters", ")", "for", "event", "in", "events", ":", "if", "event", "[", "'services'", "]", ":", "# do not process services", "continue", "event_url", "=", "gandi", ".", "status", ".", "event_timeline", "(", "event", ")", "service_detail", "=", "'%s - %s'", "%", "(", "event", "[", "'title'", "]", ",", "event_url", ")", "gandi", ".", "echo", "(", "service_detail", ")", "# then check other services", "descs", "=", "gandi", ".", "status", ".", "descriptions", "(", ")", "needed", "=", "services", "=", "gandi", ".", "status", ".", "services", "(", ")", "if", "service", ":", "needed", "=", "[", "serv", "for", "serv", "in", "services", "if", "serv", "[", "'name'", "]", ".", "lower", "(", ")", "==", "service", ".", "lower", "(", ")", "]", "for", "serv", "in", "needed", ":", "if", "serv", "[", "'status'", "]", "!=", "'STORMY'", ":", "output_service", "(", "gandi", ",", "serv", "[", "'name'", "]", ",", "descs", "[", "serv", "[", "'status'", "]", "]", ")", "continue", "filters", "=", "{", "'category'", ":", "'Incident'", ",", "'services'", ":", "serv", "[", "'name'", "]", ",", "'current'", ":", "True", ",", "}", "events", "=", "gandi", ".", "status", ".", "events", "(", "filters", ")", "for", "event", "in", "events", ":", "event_url", "=", "gandi", ".", "status", ".", "event_timeline", "(", "event", ")", "service_detail", "=", "'%s - %s'", "%", "(", "event", "[", "'title'", "]", ",", "event_url", ")", "output_service", "(", "gandi", ",", "serv", "[", "'name'", "]", ",", "service_detail", ")", "return", "services" ]
Display current status from status.gandi.net.
[ "Display", "current", "status", "from", "status", ".", "gandi", ".", "net", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/root.py#L65-L108
11,136
Gandi/gandi.cli
gandi/cli/commands/forward.py
list
def list(gandi, domain, limit): """List mail forwards for a domain.""" options = {'items_per_page': limit} result = gandi.forward.list(domain, options) for forward in result: output_forward(gandi, domain, forward) return result
python
def list(gandi, domain, limit): """List mail forwards for a domain.""" options = {'items_per_page': limit} result = gandi.forward.list(domain, options) for forward in result: output_forward(gandi, domain, forward) return result
[ "def", "list", "(", "gandi", ",", "domain", ",", "limit", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", "}", "result", "=", "gandi", ".", "forward", ".", "list", "(", "domain", ",", "options", ")", "for", "forward", "in", "result", ":", "output_forward", "(", "gandi", ",", "domain", ",", "forward", ")", "return", "result" ]
List mail forwards for a domain.
[ "List", "mail", "forwards", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/forward.py#L21-L27
11,137
Gandi/gandi.cli
gandi/cli/commands/forward.py
update
def update(gandi, address, dest_add, dest_del): """Update a domain mail forward.""" source, domain = address if not dest_add and not dest_del: gandi.echo('Nothing to update: you must provide destinations to ' 'update, use --dest-add/-a or -dest-del/-d parameters.') return result = gandi.forward.update(domain, source, dest_add, dest_del) return result
python
def update(gandi, address, dest_add, dest_del): """Update a domain mail forward.""" source, domain = address if not dest_add and not dest_del: gandi.echo('Nothing to update: you must provide destinations to ' 'update, use --dest-add/-a or -dest-del/-d parameters.') return result = gandi.forward.update(domain, source, dest_add, dest_del) return result
[ "def", "update", "(", "gandi", ",", "address", ",", "dest_add", ",", "dest_del", ")", ":", "source", ",", "domain", "=", "address", "if", "not", "dest_add", "and", "not", "dest_del", ":", "gandi", ".", "echo", "(", "'Nothing to update: you must provide destinations to '", "'update, use --dest-add/-a or -dest-del/-d parameters.'", ")", "return", "result", "=", "gandi", ".", "forward", ".", "update", "(", "domain", ",", "source", ",", "dest_add", ",", "dest_del", ")", "return", "result" ]
Update a domain mail forward.
[ "Update", "a", "domain", "mail", "forward", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/forward.py#L51-L62
11,138
Gandi/gandi.cli
gandi/cli/commands/forward.py
delete
def delete(gandi, address, force): """Delete a domain mail forward.""" source, domain = address if not force: proceed = click.confirm('Are you sure to delete the domain ' 'mail forward %s@%s ?' % (source, domain)) if not proceed: return result = gandi.forward.delete(domain, source) return result
python
def delete(gandi, address, force): """Delete a domain mail forward.""" source, domain = address if not force: proceed = click.confirm('Are you sure to delete the domain ' 'mail forward %s@%s ?' % (source, domain)) if not proceed: return result = gandi.forward.delete(domain, source) return result
[ "def", "delete", "(", "gandi", ",", "address", ",", "force", ")", ":", "source", ",", "domain", "=", "address", "if", "not", "force", ":", "proceed", "=", "click", ".", "confirm", "(", "'Are you sure to delete the domain '", "'mail forward %s@%s ?'", "%", "(", "source", ",", "domain", ")", ")", "if", "not", "proceed", ":", "return", "result", "=", "gandi", ".", "forward", ".", "delete", "(", "domain", ",", "source", ")", "return", "result" ]
Delete a domain mail forward.
[ "Delete", "a", "domain", "mail", "forward", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/forward.py#L71-L84
11,139
Gandi/gandi.cli
gandi/cli/commands/record.py
list
def list(gandi, domain, zone_id, output, format, limit): """List DNS zone records for a domain.""" options = { 'items_per_page': limit, } output_keys = ['name', 'type', 'value', 'ttl'] if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be ' 'managed at Gandi.' % domain) return records = gandi.record.list(zone_id, options) if not output and not format: for num, rec in enumerate(records): if num: gandi.separator_line() output_generic(gandi, rec, output_keys, justify=12) elif output: zone_filename = domain + "_" + str(zone_id) if os.path.isfile(zone_filename): open(zone_filename, 'w').close() for record in records: format_record = ('%s %s IN %s %s' % (record['name'], record['ttl'], record['type'], record['value'])) with open(zone_filename, 'ab') as zone_file: zone_file.write(format_record + '\n') gandi.echo('Your zone file have been writen in %s' % zone_filename) elif format: if format == 'text': for record in records: format_record = ('%s %s IN %s %s' % (record['name'], record['ttl'], record['type'], record['value'])) gandi.echo(format_record) if format == 'json': format_record = json.dumps(records, sort_keys=True, indent=4, separators=(',', ': ')) gandi.echo(format_record) return records
python
def list(gandi, domain, zone_id, output, format, limit): """List DNS zone records for a domain.""" options = { 'items_per_page': limit, } output_keys = ['name', 'type', 'value', 'ttl'] if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be ' 'managed at Gandi.' % domain) return records = gandi.record.list(zone_id, options) if not output and not format: for num, rec in enumerate(records): if num: gandi.separator_line() output_generic(gandi, rec, output_keys, justify=12) elif output: zone_filename = domain + "_" + str(zone_id) if os.path.isfile(zone_filename): open(zone_filename, 'w').close() for record in records: format_record = ('%s %s IN %s %s' % (record['name'], record['ttl'], record['type'], record['value'])) with open(zone_filename, 'ab') as zone_file: zone_file.write(format_record + '\n') gandi.echo('Your zone file have been writen in %s' % zone_filename) elif format: if format == 'text': for record in records: format_record = ('%s %s IN %s %s' % (record['name'], record['ttl'], record['type'], record['value'])) gandi.echo(format_record) if format == 'json': format_record = json.dumps(records, sort_keys=True, indent=4, separators=(',', ': ')) gandi.echo(format_record) return records
[ "def", "list", "(", "gandi", ",", "domain", ",", "zone_id", ",", "output", ",", "format", ",", "limit", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", ",", "}", "output_keys", "=", "[", "'name'", ",", "'type'", ",", "'value'", ",", "'ttl'", "]", "if", "not", "zone_id", ":", "result", "=", "gandi", ".", "domain", ".", "info", "(", "domain", ")", "zone_id", "=", "result", "[", "'zone_id'", "]", "if", "not", "zone_id", ":", "gandi", ".", "echo", "(", "'No zone records found, domain %s doesn\\'t seems to be '", "'managed at Gandi.'", "%", "domain", ")", "return", "records", "=", "gandi", ".", "record", ".", "list", "(", "zone_id", ",", "options", ")", "if", "not", "output", "and", "not", "format", ":", "for", "num", ",", "rec", "in", "enumerate", "(", "records", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_generic", "(", "gandi", ",", "rec", ",", "output_keys", ",", "justify", "=", "12", ")", "elif", "output", ":", "zone_filename", "=", "domain", "+", "\"_\"", "+", "str", "(", "zone_id", ")", "if", "os", ".", "path", ".", "isfile", "(", "zone_filename", ")", ":", "open", "(", "zone_filename", ",", "'w'", ")", ".", "close", "(", ")", "for", "record", "in", "records", ":", "format_record", "=", "(", "'%s %s IN %s %s'", "%", "(", "record", "[", "'name'", "]", ",", "record", "[", "'ttl'", "]", ",", "record", "[", "'type'", "]", ",", "record", "[", "'value'", "]", ")", ")", "with", "open", "(", "zone_filename", ",", "'ab'", ")", "as", "zone_file", ":", "zone_file", ".", "write", "(", "format_record", "+", "'\\n'", ")", "gandi", ".", "echo", "(", "'Your zone file have been writen in %s'", "%", "zone_filename", ")", "elif", "format", ":", "if", "format", "==", "'text'", ":", "for", "record", "in", "records", ":", "format_record", "=", "(", "'%s %s IN %s %s'", "%", "(", "record", "[", "'name'", "]", ",", "record", "[", "'ttl'", "]", ",", "record", "[", "'type'", "]", ",", "record", "[", "'value'", "]", ")", ")", "gandi", ".", "echo", "(", "format_record", ")", "if", "format", "==", "'json'", ":", "format_record", "=", "json", ".", "dumps", "(", "records", ",", "sort_keys", "=", "True", ",", "indent", "=", "4", ",", "separators", "=", "(", "','", ",", "': '", ")", ")", "gandi", ".", "echo", "(", "format_record", ")", "return", "records" ]
List DNS zone records for a domain.
[ "List", "DNS", "zone", "records", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/record.py#L31-L77
11,140
Gandi/gandi.cli
gandi/cli/commands/record.py
create
def create(gandi, domain, zone_id, name, type, value, ttl): """Create new DNS zone record entry for a domain.""" if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be ' 'managed at Gandi.' % domain) return record = {'type': type, 'name': name, 'value': value} if ttl: record['ttl'] = ttl result = gandi.record.create(zone_id, record) return result
python
def create(gandi, domain, zone_id, name, type, value, ttl): """Create new DNS zone record entry for a domain.""" if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be ' 'managed at Gandi.' % domain) return record = {'type': type, 'name': name, 'value': value} if ttl: record['ttl'] = ttl result = gandi.record.create(zone_id, record) return result
[ "def", "create", "(", "gandi", ",", "domain", ",", "zone_id", ",", "name", ",", "type", ",", "value", ",", "ttl", ")", ":", "if", "not", "zone_id", ":", "result", "=", "gandi", ".", "domain", ".", "info", "(", "domain", ")", "zone_id", "=", "result", "[", "'zone_id'", "]", "if", "not", "zone_id", ":", "gandi", ".", "echo", "(", "'No zone records found, domain %s doesn\\'t seems to be '", "'managed at Gandi.'", "%", "domain", ")", "return", "record", "=", "{", "'type'", ":", "type", ",", "'name'", ":", "name", ",", "'value'", ":", "value", "}", "if", "ttl", ":", "record", "[", "'ttl'", "]", "=", "ttl", "result", "=", "gandi", ".", "record", ".", "create", "(", "zone_id", ",", "record", ")", "return", "result" ]
Create new DNS zone record entry for a domain.
[ "Create", "new", "DNS", "zone", "record", "entry", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/record.py#L101-L118
11,141
Gandi/gandi.cli
gandi/cli/commands/record.py
delete
def delete(gandi, domain, zone_id, name, type, value): """Delete a record entry for a domain""" if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be ' 'managed at Gandi.' % domain) return if not name and not type and not value: proceed = click.confirm('This command without parameters --type, ' '--name or --value will remove all records' ' in this zone file. Are you sur to ' 'perform this action ?') if not proceed: return record = {'name': name, 'type': type, 'value': value} result = gandi.record.delete(zone_id, record) return result
python
def delete(gandi, domain, zone_id, name, type, value): """Delete a record entry for a domain""" if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be ' 'managed at Gandi.' % domain) return if not name and not type and not value: proceed = click.confirm('This command without parameters --type, ' '--name or --value will remove all records' ' in this zone file. Are you sur to ' 'perform this action ?') if not proceed: return record = {'name': name, 'type': type, 'value': value} result = gandi.record.delete(zone_id, record) return result
[ "def", "delete", "(", "gandi", ",", "domain", ",", "zone_id", ",", "name", ",", "type", ",", "value", ")", ":", "if", "not", "zone_id", ":", "result", "=", "gandi", ".", "domain", ".", "info", "(", "domain", ")", "zone_id", "=", "result", "[", "'zone_id'", "]", "if", "not", "zone_id", ":", "gandi", ".", "echo", "(", "'No zone records found, domain %s doesn\\'t seems to be '", "'managed at Gandi.'", "%", "domain", ")", "return", "if", "not", "name", "and", "not", "type", "and", "not", "value", ":", "proceed", "=", "click", ".", "confirm", "(", "'This command without parameters --type, '", "'--name or --value will remove all records'", "' in this zone file. Are you sur to '", "'perform this action ?'", ")", "if", "not", "proceed", ":", "return", "record", "=", "{", "'name'", ":", "name", ",", "'type'", ":", "type", ",", "'value'", ":", "value", "}", "result", "=", "gandi", ".", "record", ".", "delete", "(", "zone_id", ",", "record", ")", "return", "result" ]
Delete a record entry for a domain
[ "Delete", "a", "record", "entry", "for", "a", "domain" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/record.py#L138-L157
11,142
Gandi/gandi.cli
gandi/cli/commands/record.py
update
def update(gandi, domain, zone_id, file, record, new_record): """Update records entries for a domain. You can update an individual record using --record and --new-record parameters Or you can use a plaintext file to update all records of a DNS zone at once with --file parameter. """ if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be' ' managed at Gandi.' % domain) return if file: records = file.read() result = gandi.record.zone_update(zone_id, records) return result elif record and new_record: result = gandi.record.update(zone_id, record, new_record) return result else: gandi.echo('You must indicate a zone file or a record.' ' Use `gandi record update --help` for more information')
python
def update(gandi, domain, zone_id, file, record, new_record): """Update records entries for a domain. You can update an individual record using --record and --new-record parameters Or you can use a plaintext file to update all records of a DNS zone at once with --file parameter. """ if not zone_id: result = gandi.domain.info(domain) zone_id = result['zone_id'] if not zone_id: gandi.echo('No zone records found, domain %s doesn\'t seems to be' ' managed at Gandi.' % domain) return if file: records = file.read() result = gandi.record.zone_update(zone_id, records) return result elif record and new_record: result = gandi.record.update(zone_id, record, new_record) return result else: gandi.echo('You must indicate a zone file or a record.' ' Use `gandi record update --help` for more information')
[ "def", "update", "(", "gandi", ",", "domain", ",", "zone_id", ",", "file", ",", "record", ",", "new_record", ")", ":", "if", "not", "zone_id", ":", "result", "=", "gandi", ".", "domain", ".", "info", "(", "domain", ")", "zone_id", "=", "result", "[", "'zone_id'", "]", "if", "not", "zone_id", ":", "gandi", ".", "echo", "(", "'No zone records found, domain %s doesn\\'t seems to be'", "' managed at Gandi.'", "%", "domain", ")", "return", "if", "file", ":", "records", "=", "file", ".", "read", "(", ")", "result", "=", "gandi", ".", "record", ".", "zone_update", "(", "zone_id", ",", "records", ")", "return", "result", "elif", "record", "and", "new_record", ":", "result", "=", "gandi", ".", "record", ".", "update", "(", "zone_id", ",", "record", ",", "new_record", ")", "return", "result", "else", ":", "gandi", ".", "echo", "(", "'You must indicate a zone file or a record.'", "' Use `gandi record update --help` for more information'", ")" ]
Update records entries for a domain. You can update an individual record using --record and --new-record parameters Or you can use a plaintext file to update all records of a DNS zone at once with --file parameter.
[ "Update", "records", "entries", "for", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/record.py#L174-L200
11,143
Gandi/gandi.cli
gandi/cli/modules/mail.py
Mail.set_alias
def set_alias(cls, domain, login, aliases): """Update aliases on a mailbox.""" return cls.call('domain.mailbox.alias.set', domain, login, aliases)
python
def set_alias(cls, domain, login, aliases): """Update aliases on a mailbox.""" return cls.call('domain.mailbox.alias.set', domain, login, aliases)
[ "def", "set_alias", "(", "cls", ",", "domain", ",", "login", ",", "aliases", ")", ":", "return", "cls", ".", "call", "(", "'domain.mailbox.alias.set'", ",", "domain", ",", "login", ",", "aliases", ")" ]
Update aliases on a mailbox.
[ "Update", "aliases", "on", "a", "mailbox", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/mail.py#L82-L84
11,144
Gandi/gandi.cli
gandi/cli/modules/record.py
Record.list
def list(cls, zone_id, options=None): """List zone records for a zone.""" options = options if options else {} return cls.call('domain.zone.record.list', zone_id, 0, options)
python
def list(cls, zone_id, options=None): """List zone records for a zone.""" options = options if options else {} return cls.call('domain.zone.record.list', zone_id, 0, options)
[ "def", "list", "(", "cls", ",", "zone_id", ",", "options", "=", "None", ")", ":", "options", "=", "options", "if", "options", "else", "{", "}", "return", "cls", ".", "call", "(", "'domain.zone.record.list'", ",", "zone_id", ",", "0", ",", "options", ")" ]
List zone records for a zone.
[ "List", "zone", "records", "for", "a", "zone", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/record.py#L36-L39
11,145
Gandi/gandi.cli
gandi/cli/modules/record.py
Record.add
def add(cls, zone_id, version_id, record): """Add record to a zone.""" return cls.call('domain.zone.record.add', zone_id, version_id, record)
python
def add(cls, zone_id, version_id, record): """Add record to a zone.""" return cls.call('domain.zone.record.add', zone_id, version_id, record)
[ "def", "add", "(", "cls", ",", "zone_id", ",", "version_id", ",", "record", ")", ":", "return", "cls", ".", "call", "(", "'domain.zone.record.add'", ",", "zone_id", ",", "version_id", ",", "record", ")" ]
Add record to a zone.
[ "Add", "record", "to", "a", "zone", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/record.py#L42-L44
11,146
Gandi/gandi.cli
gandi/cli/modules/record.py
Record.create
def create(cls, zone_id, record): """Create a new zone version for record.""" cls.echo('Creating new zone version') new_version_id = Zone.new(zone_id) cls.echo('Updating zone version') cls.add(zone_id, new_version_id, record) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id
python
def create(cls, zone_id, record): """Create a new zone version for record.""" cls.echo('Creating new zone version') new_version_id = Zone.new(zone_id) cls.echo('Updating zone version') cls.add(zone_id, new_version_id, record) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id
[ "def", "create", "(", "cls", ",", "zone_id", ",", "record", ")", ":", "cls", ".", "echo", "(", "'Creating new zone version'", ")", "new_version_id", "=", "Zone", ".", "new", "(", "zone_id", ")", "cls", ".", "echo", "(", "'Updating zone version'", ")", "cls", ".", "add", "(", "zone_id", ",", "new_version_id", ",", "record", ")", "cls", ".", "echo", "(", "'Activation of new zone version'", ")", "Zone", ".", "set", "(", "zone_id", ",", "new_version_id", ")", "return", "new_version_id" ]
Create a new zone version for record.
[ "Create", "a", "new", "zone", "version", "for", "record", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/record.py#L47-L58
11,147
Gandi/gandi.cli
gandi/cli/modules/record.py
Record.delete
def delete(cls, zone_id, record): """Delete a record for a zone""" cls.echo('Creating new zone record') new_version_id = Zone.new(zone_id) cls.echo('Deleting zone record') cls.call('domain.zone.record.delete', zone_id, new_version_id, record) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id
python
def delete(cls, zone_id, record): """Delete a record for a zone""" cls.echo('Creating new zone record') new_version_id = Zone.new(zone_id) cls.echo('Deleting zone record') cls.call('domain.zone.record.delete', zone_id, new_version_id, record) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id
[ "def", "delete", "(", "cls", ",", "zone_id", ",", "record", ")", ":", "cls", ".", "echo", "(", "'Creating new zone record'", ")", "new_version_id", "=", "Zone", ".", "new", "(", "zone_id", ")", "cls", ".", "echo", "(", "'Deleting zone record'", ")", "cls", ".", "call", "(", "'domain.zone.record.delete'", ",", "zone_id", ",", "new_version_id", ",", "record", ")", "cls", ".", "echo", "(", "'Activation of new zone version'", ")", "Zone", ".", "set", "(", "zone_id", ",", "new_version_id", ")", "return", "new_version_id" ]
Delete a record for a zone
[ "Delete", "a", "record", "for", "a", "zone" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/record.py#L61-L72
11,148
Gandi/gandi.cli
gandi/cli/modules/record.py
Record.zone_update
def zone_update(cls, zone_id, records): """Update records for a zone""" cls.echo('Creating new zone file') new_version_id = Zone.new(zone_id) cls.echo('Updating zone records') cls.call('domain.zone.record.set', zone_id, new_version_id, records) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id
python
def zone_update(cls, zone_id, records): """Update records for a zone""" cls.echo('Creating new zone file') new_version_id = Zone.new(zone_id) cls.echo('Updating zone records') cls.call('domain.zone.record.set', zone_id, new_version_id, records) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id
[ "def", "zone_update", "(", "cls", ",", "zone_id", ",", "records", ")", ":", "cls", ".", "echo", "(", "'Creating new zone file'", ")", "new_version_id", "=", "Zone", ".", "new", "(", "zone_id", ")", "cls", ".", "echo", "(", "'Updating zone records'", ")", "cls", ".", "call", "(", "'domain.zone.record.set'", ",", "zone_id", ",", "new_version_id", ",", "records", ")", "cls", ".", "echo", "(", "'Activation of new zone version'", ")", "Zone", ".", "set", "(", "zone_id", ",", "new_version_id", ")", "return", "new_version_id" ]
Update records for a zone
[ "Update", "records", "for", "a", "zone" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/record.py#L75-L86
11,149
Gandi/gandi.cli
gandi/cli/modules/record.py
Record.update
def update(cls, zone_id, old_record, new_record): """Update a record in a zone file""" cls.echo('Creating new zone file') new_version_id = Zone.new(zone_id) new_record = new_record.replace(' IN', '') new_record = new_record.split(' ', 4) params_newrecord = {'name': new_record[0], 'ttl': int(new_record[1]), 'type': new_record[2], 'value': new_record[3]} old_record = old_record.replace(' IN', '') old_record = old_record.split(' ', 4) try: params = {'name': old_record[0], 'ttl': int(old_record[1]), 'type': old_record[2], 'value': old_record[3]} except IndexError: # failed to retrieve all values, try only use the name params = {'name': old_record[0]} record = cls.call('domain.zone.record.list', zone_id, new_version_id, params) if record: cls.echo('Updating zone records') try: cls.call('domain.zone.record.update', zone_id, new_version_id, {'id': record[0]['id']}, params_newrecord) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id except Exception as err: cls.echo('An error as occured: %s' % err) Zone.delete(zone_id, new_version_id) else: cls.echo('The record to update does not exist. Check records' ' already created with `gandi record list example.com' ' --output`') return False
python
def update(cls, zone_id, old_record, new_record): """Update a record in a zone file""" cls.echo('Creating new zone file') new_version_id = Zone.new(zone_id) new_record = new_record.replace(' IN', '') new_record = new_record.split(' ', 4) params_newrecord = {'name': new_record[0], 'ttl': int(new_record[1]), 'type': new_record[2], 'value': new_record[3]} old_record = old_record.replace(' IN', '') old_record = old_record.split(' ', 4) try: params = {'name': old_record[0], 'ttl': int(old_record[1]), 'type': old_record[2], 'value': old_record[3]} except IndexError: # failed to retrieve all values, try only use the name params = {'name': old_record[0]} record = cls.call('domain.zone.record.list', zone_id, new_version_id, params) if record: cls.echo('Updating zone records') try: cls.call('domain.zone.record.update', zone_id, new_version_id, {'id': record[0]['id']}, params_newrecord) cls.echo('Activation of new zone version') Zone.set(zone_id, new_version_id) return new_version_id except Exception as err: cls.echo('An error as occured: %s' % err) Zone.delete(zone_id, new_version_id) else: cls.echo('The record to update does not exist. Check records' ' already created with `gandi record list example.com' ' --output`') return False
[ "def", "update", "(", "cls", ",", "zone_id", ",", "old_record", ",", "new_record", ")", ":", "cls", ".", "echo", "(", "'Creating new zone file'", ")", "new_version_id", "=", "Zone", ".", "new", "(", "zone_id", ")", "new_record", "=", "new_record", ".", "replace", "(", "' IN'", ",", "''", ")", "new_record", "=", "new_record", ".", "split", "(", "' '", ",", "4", ")", "params_newrecord", "=", "{", "'name'", ":", "new_record", "[", "0", "]", ",", "'ttl'", ":", "int", "(", "new_record", "[", "1", "]", ")", ",", "'type'", ":", "new_record", "[", "2", "]", ",", "'value'", ":", "new_record", "[", "3", "]", "}", "old_record", "=", "old_record", ".", "replace", "(", "' IN'", ",", "''", ")", "old_record", "=", "old_record", ".", "split", "(", "' '", ",", "4", ")", "try", ":", "params", "=", "{", "'name'", ":", "old_record", "[", "0", "]", ",", "'ttl'", ":", "int", "(", "old_record", "[", "1", "]", ")", ",", "'type'", ":", "old_record", "[", "2", "]", ",", "'value'", ":", "old_record", "[", "3", "]", "}", "except", "IndexError", ":", "# failed to retrieve all values, try only use the name", "params", "=", "{", "'name'", ":", "old_record", "[", "0", "]", "}", "record", "=", "cls", ".", "call", "(", "'domain.zone.record.list'", ",", "zone_id", ",", "new_version_id", ",", "params", ")", "if", "record", ":", "cls", ".", "echo", "(", "'Updating zone records'", ")", "try", ":", "cls", ".", "call", "(", "'domain.zone.record.update'", ",", "zone_id", ",", "new_version_id", ",", "{", "'id'", ":", "record", "[", "0", "]", "[", "'id'", "]", "}", ",", "params_newrecord", ")", "cls", ".", "echo", "(", "'Activation of new zone version'", ")", "Zone", ".", "set", "(", "zone_id", ",", "new_version_id", ")", "return", "new_version_id", "except", "Exception", "as", "err", ":", "cls", ".", "echo", "(", "'An error as occured: %s'", "%", "err", ")", "Zone", ".", "delete", "(", "zone_id", ",", "new_version_id", ")", "else", ":", "cls", ".", "echo", "(", "'The record to update does not exist. Check records'", "' already created with `gandi record list example.com'", "' --output`'", ")", "return", "False" ]
Update a record in a zone file
[ "Update", "a", "record", "in", "a", "zone", "file" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/record.py#L89-L126
11,150
Gandi/gandi.cli
gandi/cli/commands/vhost.py
list
def list(gandi, limit, id, names): """ List vhosts. """ options = { 'items_per_page': limit, } output_keys = ['name', 'state', 'date_creation'] if id: # When we will have more than paas vhost, we will append rproxy_id output_keys.append('paas_id') paas_names = {} if names: output_keys.append('paas_name') paas_names = gandi.paas.list_names() result = gandi.vhost.list(options) for num, vhost in enumerate(result): paas = paas_names.get(vhost['paas_id']) if num: gandi.separator_line() output_vhost(gandi, vhost, paas, output_keys) return result
python
def list(gandi, limit, id, names): """ List vhosts. """ options = { 'items_per_page': limit, } output_keys = ['name', 'state', 'date_creation'] if id: # When we will have more than paas vhost, we will append rproxy_id output_keys.append('paas_id') paas_names = {} if names: output_keys.append('paas_name') paas_names = gandi.paas.list_names() result = gandi.vhost.list(options) for num, vhost in enumerate(result): paas = paas_names.get(vhost['paas_id']) if num: gandi.separator_line() output_vhost(gandi, vhost, paas, output_keys) return result
[ "def", "list", "(", "gandi", ",", "limit", ",", "id", ",", "names", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", ",", "}", "output_keys", "=", "[", "'name'", ",", "'state'", ",", "'date_creation'", "]", "if", "id", ":", "# When we will have more than paas vhost, we will append rproxy_id", "output_keys", ".", "append", "(", "'paas_id'", ")", "paas_names", "=", "{", "}", "if", "names", ":", "output_keys", ".", "append", "(", "'paas_name'", ")", "paas_names", "=", "gandi", ".", "paas", ".", "list_names", "(", ")", "result", "=", "gandi", ".", "vhost", ".", "list", "(", "options", ")", "for", "num", ",", "vhost", "in", "enumerate", "(", "result", ")", ":", "paas", "=", "paas_names", ".", "get", "(", "vhost", "[", "'paas_id'", "]", ")", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_vhost", "(", "gandi", ",", "vhost", ",", "paas", ",", "output_keys", ")", "return", "result" ]
List vhosts.
[ "List", "vhosts", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vhost.py#L22-L45
11,151
Gandi/gandi.cli
gandi/cli/commands/vhost.py
info
def info(gandi, resource, id): """ Display information about a vhost. Resource must be the vhost fqdn. """ output_keys = ['name', 'state', 'date_creation', 'paas_name', 'ssl'] if id: # When we will have more than paas vhost, we will append rproxy_id output_keys.append('paas_id') paas_names = gandi.paas.list_names() ret = [] paas = None for num, item in enumerate(resource): vhost = gandi.vhost.info(item) try: hostedcert = gandi.hostedcert.infos(vhost['name']) vhost['ssl'] = 'activated' if hostedcert else 'disabled' except ValueError: vhost['ssl'] = 'disabled' paas = paas_names.get(vhost['paas_id']) if num: gandi.separator_line() ret.append(output_vhost(gandi, vhost, paas, output_keys)) return ret
python
def info(gandi, resource, id): """ Display information about a vhost. Resource must be the vhost fqdn. """ output_keys = ['name', 'state', 'date_creation', 'paas_name', 'ssl'] if id: # When we will have more than paas vhost, we will append rproxy_id output_keys.append('paas_id') paas_names = gandi.paas.list_names() ret = [] paas = None for num, item in enumerate(resource): vhost = gandi.vhost.info(item) try: hostedcert = gandi.hostedcert.infos(vhost['name']) vhost['ssl'] = 'activated' if hostedcert else 'disabled' except ValueError: vhost['ssl'] = 'disabled' paas = paas_names.get(vhost['paas_id']) if num: gandi.separator_line() ret.append(output_vhost(gandi, vhost, paas, output_keys)) return ret
[ "def", "info", "(", "gandi", ",", "resource", ",", "id", ")", ":", "output_keys", "=", "[", "'name'", ",", "'state'", ",", "'date_creation'", ",", "'paas_name'", ",", "'ssl'", "]", "if", "id", ":", "# When we will have more than paas vhost, we will append rproxy_id", "output_keys", ".", "append", "(", "'paas_id'", ")", "paas_names", "=", "gandi", ".", "paas", ".", "list_names", "(", ")", "ret", "=", "[", "]", "paas", "=", "None", "for", "num", ",", "item", "in", "enumerate", "(", "resource", ")", ":", "vhost", "=", "gandi", ".", "vhost", ".", "info", "(", "item", ")", "try", ":", "hostedcert", "=", "gandi", ".", "hostedcert", ".", "infos", "(", "vhost", "[", "'name'", "]", ")", "vhost", "[", "'ssl'", "]", "=", "'activated'", "if", "hostedcert", "else", "'disabled'", "except", "ValueError", ":", "vhost", "[", "'ssl'", "]", "=", "'disabled'", "paas", "=", "paas_names", ".", "get", "(", "vhost", "[", "'paas_id'", "]", ")", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "ret", ".", "append", "(", "output_vhost", "(", "gandi", ",", "vhost", ",", "paas", ",", "output_keys", ")", ")", "return", "ret" ]
Display information about a vhost. Resource must be the vhost fqdn.
[ "Display", "information", "about", "a", "vhost", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vhost.py#L52-L79
11,152
Gandi/gandi.cli
gandi/cli/commands/vhost.py
update
def update(gandi, resource, ssl, private_key, poll_cert): """ Update a vhost. Right now you can only activate ssl on the vhost. """ gandi.hostedcert.activate_ssl(resource, ssl, private_key, poll_cert)
python
def update(gandi, resource, ssl, private_key, poll_cert): """ Update a vhost. Right now you can only activate ssl on the vhost. """ gandi.hostedcert.activate_ssl(resource, ssl, private_key, poll_cert)
[ "def", "update", "(", "gandi", ",", "resource", ",", "ssl", ",", "private_key", ",", "poll_cert", ")", ":", "gandi", ".", "hostedcert", ".", "activate_ssl", "(", "resource", ",", "ssl", ",", "private_key", ",", "poll_cert", ")" ]
Update a vhost. Right now you can only activate ssl on the vhost.
[ "Update", "a", "vhost", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vhost.py#L119-L124
11,153
Gandi/gandi.cli
gandi/cli/core/params.py
option
def option(*param_decls, **attrs): """Attach an option to the command. All positional arguments are passed as parameter declarations to :class:`Option`, all keyword arguments are forwarded unchanged. This is equivalent to creating an :class:`Option` instance manually and attaching it to the :attr:`Command.params` list. """ def decorator(f): _param_memo(f, GandiOption(param_decls, **attrs)) return f return decorator
python
def option(*param_decls, **attrs): """Attach an option to the command. All positional arguments are passed as parameter declarations to :class:`Option`, all keyword arguments are forwarded unchanged. This is equivalent to creating an :class:`Option` instance manually and attaching it to the :attr:`Command.params` list. """ def decorator(f): _param_memo(f, GandiOption(param_decls, **attrs)) return f return decorator
[ "def", "option", "(", "*", "param_decls", ",", "*", "*", "attrs", ")", ":", "def", "decorator", "(", "f", ")", ":", "_param_memo", "(", "f", ",", "GandiOption", "(", "param_decls", ",", "*", "*", "attrs", ")", ")", "return", "f", "return", "decorator" ]
Attach an option to the command. All positional arguments are passed as parameter declarations to :class:`Option`, all keyword arguments are forwarded unchanged. This is equivalent to creating an :class:`Option` instance manually and attaching it to the :attr:`Command.params` list.
[ "Attach", "an", "option", "to", "the", "command", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L586-L597
11,154
Gandi/gandi.cli
gandi/cli/core/params.py
GandiChoice.choices
def choices(self): """ Retrieve choices from API if possible""" if not self._choices: gandi = self.gandi or GandiContextHelper() self._choices = self._get_choices(gandi) if not self._choices: api = gandi.get_api_connector() gandi.echo('Please check that you are connecting to the good ' "api '%s' and that it's running." % (api.host)) sys.exit(1) return self._choices
python
def choices(self): """ Retrieve choices from API if possible""" if not self._choices: gandi = self.gandi or GandiContextHelper() self._choices = self._get_choices(gandi) if not self._choices: api = gandi.get_api_connector() gandi.echo('Please check that you are connecting to the good ' "api '%s' and that it's running." % (api.host)) sys.exit(1) return self._choices
[ "def", "choices", "(", "self", ")", ":", "if", "not", "self", ".", "_choices", ":", "gandi", "=", "self", ".", "gandi", "or", "GandiContextHelper", "(", ")", "self", ".", "_choices", "=", "self", ".", "_get_choices", "(", "gandi", ")", "if", "not", "self", ".", "_choices", ":", "api", "=", "gandi", ".", "get_api_connector", "(", ")", "gandi", ".", "echo", "(", "'Please check that you are connecting to the good '", "\"api '%s' and that it's running.\"", "%", "(", "api", ".", "host", ")", ")", "sys", ".", "exit", "(", "1", ")", "return", "self", ".", "_choices" ]
Retrieve choices from API if possible
[ "Retrieve", "choices", "from", "API", "if", "possible" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L28-L39
11,155
Gandi/gandi.cli
gandi/cli/core/params.py
DiskImageParamType.convert
def convert(self, value, param, ctx): """ Try to find correct disk image regarding version. """ self.gandi = ctx.obj # remove deprecated * prefix choices = [choice.replace('*', '') for choice in self.choices] value = value.replace('*', '') # Exact match if value in choices: return value # Try to find 64 bits version new_value = '%s 64 bits' % value if new_value in choices: return new_value # Try to find without specific bits version p = re.compile(' (64|32) bits') new_value = p.sub('', value) if new_value in choices: return new_value self.fail('invalid choice: %s. (choose from %s)' % (value, ', '.join(self.choices)), param, ctx)
python
def convert(self, value, param, ctx): """ Try to find correct disk image regarding version. """ self.gandi = ctx.obj # remove deprecated * prefix choices = [choice.replace('*', '') for choice in self.choices] value = value.replace('*', '') # Exact match if value in choices: return value # Try to find 64 bits version new_value = '%s 64 bits' % value if new_value in choices: return new_value # Try to find without specific bits version p = re.compile(' (64|32) bits') new_value = p.sub('', value) if new_value in choices: return new_value self.fail('invalid choice: %s. (choose from %s)' % (value, ', '.join(self.choices)), param, ctx)
[ "def", "convert", "(", "self", ",", "value", ",", "param", ",", "ctx", ")", ":", "self", ".", "gandi", "=", "ctx", ".", "obj", "# remove deprecated * prefix", "choices", "=", "[", "choice", ".", "replace", "(", "'*'", ",", "''", ")", "for", "choice", "in", "self", ".", "choices", "]", "value", "=", "value", ".", "replace", "(", "'*'", ",", "''", ")", "# Exact match", "if", "value", "in", "choices", ":", "return", "value", "# Try to find 64 bits version", "new_value", "=", "'%s 64 bits'", "%", "value", "if", "new_value", "in", "choices", ":", "return", "new_value", "# Try to find without specific bits version", "p", "=", "re", ".", "compile", "(", "' (64|32) bits'", ")", "new_value", "=", "p", ".", "sub", "(", "''", ",", "value", ")", "if", "new_value", "in", "choices", ":", "return", "new_value", "self", ".", "fail", "(", "'invalid choice: %s. (choose from %s)'", "%", "(", "value", ",", "', '", ".", "join", "(", "self", ".", "choices", ")", ")", ",", "param", ",", "ctx", ")" ]
Try to find correct disk image regarding version.
[ "Try", "to", "find", "correct", "disk", "image", "regarding", "version", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L128-L150
11,156
Gandi/gandi.cli
gandi/cli/core/params.py
KernelParamType.convert
def convert(self, value, param, ctx): """ Try to find correct kernel regarding version. """ self.gandi = ctx.obj # Exact match first if value in self.choices: return value # Also try with x86-64 suffix new_value = '%s-x86_64' % value if new_value in self.choices: return new_value self.fail('invalid choice: %s. (choose from %s)' % (value, ', '.join(self.choices)), param, ctx)
python
def convert(self, value, param, ctx): """ Try to find correct kernel regarding version. """ self.gandi = ctx.obj # Exact match first if value in self.choices: return value # Also try with x86-64 suffix new_value = '%s-x86_64' % value if new_value in self.choices: return new_value self.fail('invalid choice: %s. (choose from %s)' % (value, ', '.join(self.choices)), param, ctx)
[ "def", "convert", "(", "self", ",", "value", ",", "param", ",", "ctx", ")", ":", "self", ".", "gandi", "=", "ctx", ".", "obj", "# Exact match first", "if", "value", "in", "self", ".", "choices", ":", "return", "value", "# Also try with x86-64 suffix", "new_value", "=", "'%s-x86_64'", "%", "value", "if", "new_value", "in", "self", ".", "choices", ":", "return", "new_value", "self", ".", "fail", "(", "'invalid choice: %s. (choose from %s)'", "%", "(", "value", ",", "', '", ".", "join", "(", "self", ".", "choices", ")", ")", ",", "param", ",", "ctx", ")" ]
Try to find correct kernel regarding version.
[ "Try", "to", "find", "correct", "kernel", "regarding", "version", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L164-L177
11,157
Gandi/gandi.cli
gandi/cli/core/params.py
SnapshotParamType.convert
def convert(self, value, param, ctx): """ Convert value to int. """ self.gandi = ctx.obj value = click.Choice.convert(self, value, param, ctx) return int(value)
python
def convert(self, value, param, ctx): """ Convert value to int. """ self.gandi = ctx.obj value = click.Choice.convert(self, value, param, ctx) return int(value)
[ "def", "convert", "(", "self", ",", "value", ",", "param", ",", "ctx", ")", ":", "self", ".", "gandi", "=", "ctx", ".", "obj", "value", "=", "click", ".", "Choice", ".", "convert", "(", "self", ",", "value", ",", "param", ",", "ctx", ")", "return", "int", "(", "value", ")" ]
Convert value to int.
[ "Convert", "value", "to", "int", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L198-L202
11,158
Gandi/gandi.cli
gandi/cli/core/params.py
GandiOption.display_value
def display_value(self, ctx, value): """ Display value to be used for this parameter. """ gandi = ctx.obj gandi.log('%s: %s' % (self.name, (value if value is not None else 'Not found')))
python
def display_value(self, ctx, value): """ Display value to be used for this parameter. """ gandi = ctx.obj gandi.log('%s: %s' % (self.name, (value if value is not None else 'Not found')))
[ "def", "display_value", "(", "self", ",", "ctx", ",", "value", ")", ":", "gandi", "=", "ctx", ".", "obj", "gandi", ".", "log", "(", "'%s: %s'", "%", "(", "self", ".", "name", ",", "(", "value", "if", "value", "is", "not", "None", "else", "'Not found'", ")", ")", ")" ]
Display value to be used for this parameter.
[ "Display", "value", "to", "be", "used", "for", "this", "parameter", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L526-L530
11,159
Gandi/gandi.cli
gandi/cli/core/params.py
GandiOption.get_default
def get_default(self, ctx): """ Retrieve default value and display it when prompt disabled. """ value = click.Option.get_default(self, ctx) if not self.prompt: # value found in default display it self.display_value(ctx, value) return value
python
def get_default(self, ctx): """ Retrieve default value and display it when prompt disabled. """ value = click.Option.get_default(self, ctx) if not self.prompt: # value found in default display it self.display_value(ctx, value) return value
[ "def", "get_default", "(", "self", ",", "ctx", ")", ":", "value", "=", "click", ".", "Option", ".", "get_default", "(", "self", ",", "ctx", ")", "if", "not", "self", ".", "prompt", ":", "# value found in default display it", "self", ".", "display_value", "(", "ctx", ",", "value", ")", "return", "value" ]
Retrieve default value and display it when prompt disabled.
[ "Retrieve", "default", "value", "and", "display", "it", "when", "prompt", "disabled", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L532-L538
11,160
Gandi/gandi.cli
gandi/cli/core/params.py
GandiOption.consume_value
def consume_value(self, ctx, opts): """ Retrieve default value and display it when prompt is disabled. """ value = click.Option.consume_value(self, ctx, opts) if not value: # value not found by click on command line # now check using our context helper in order into # local configuration # global configuration gandi = ctx.obj value = gandi.get(self.name) if value is not None: # value found in configuration display it self.display_value(ctx, value) else: if self.default is None and self.required: metavar = '' if self.type.name not in ['integer', 'text']: metavar = self.make_metavar() prompt = '%s %s' % (self.help, metavar) gandi.echo(prompt) return value
python
def consume_value(self, ctx, opts): """ Retrieve default value and display it when prompt is disabled. """ value = click.Option.consume_value(self, ctx, opts) if not value: # value not found by click on command line # now check using our context helper in order into # local configuration # global configuration gandi = ctx.obj value = gandi.get(self.name) if value is not None: # value found in configuration display it self.display_value(ctx, value) else: if self.default is None and self.required: metavar = '' if self.type.name not in ['integer', 'text']: metavar = self.make_metavar() prompt = '%s %s' % (self.help, metavar) gandi.echo(prompt) return value
[ "def", "consume_value", "(", "self", ",", "ctx", ",", "opts", ")", ":", "value", "=", "click", ".", "Option", ".", "consume_value", "(", "self", ",", "ctx", ",", "opts", ")", "if", "not", "value", ":", "# value not found by click on command line", "# now check using our context helper in order into", "# local configuration", "# global configuration", "gandi", "=", "ctx", ".", "obj", "value", "=", "gandi", ".", "get", "(", "self", ".", "name", ")", "if", "value", "is", "not", "None", ":", "# value found in configuration display it", "self", ".", "display_value", "(", "ctx", ",", "value", ")", "else", ":", "if", "self", ".", "default", "is", "None", "and", "self", ".", "required", ":", "metavar", "=", "''", "if", "self", ".", "type", ".", "name", "not", "in", "[", "'integer'", ",", "'text'", "]", ":", "metavar", "=", "self", ".", "make_metavar", "(", ")", "prompt", "=", "'%s %s'", "%", "(", "self", ".", "help", ",", "metavar", ")", "gandi", ".", "echo", "(", "prompt", ")", "return", "value" ]
Retrieve default value and display it when prompt is disabled.
[ "Retrieve", "default", "value", "and", "display", "it", "when", "prompt", "is", "disabled", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L540-L560
11,161
Gandi/gandi.cli
gandi/cli/modules/domain.py
Domain.create
def create(cls, fqdn, duration, owner, admin, tech, bill, nameserver, extra_parameter, background): """Create a domain.""" fqdn = fqdn.lower() if not background and not cls.intty(): background = True result = cls.call('domain.available', [fqdn]) while result[fqdn] == 'pending': time.sleep(1) result = cls.call('domain.available', [fqdn]) if result[fqdn] == 'unavailable': raise DomainNotAvailable('%s is not available' % fqdn) # retrieve handle of user and save it to configuration user_handle = cls.call('contact.info')['handle'] cls.configure(True, 'api.handle', user_handle) owner_ = owner or user_handle admin_ = admin or user_handle tech_ = tech or user_handle bill_ = bill or user_handle domain_params = { 'duration': duration, 'owner': owner_, 'admin': admin_, 'tech': tech_, 'bill': bill_, } if nameserver: domain_params['nameservers'] = nameserver if extra_parameter: domain_params['extra'] = {} for extra in extra_parameter: domain_params['extra'][extra[0]] = extra[1] result = cls.call('domain.create', fqdn, domain_params) if background: return result # interactive mode, run a progress bar cls.echo('Creating your domain.') cls.display_progress(result) cls.echo('Your domain %s has been created.' % fqdn)
python
def create(cls, fqdn, duration, owner, admin, tech, bill, nameserver, extra_parameter, background): """Create a domain.""" fqdn = fqdn.lower() if not background and not cls.intty(): background = True result = cls.call('domain.available', [fqdn]) while result[fqdn] == 'pending': time.sleep(1) result = cls.call('domain.available', [fqdn]) if result[fqdn] == 'unavailable': raise DomainNotAvailable('%s is not available' % fqdn) # retrieve handle of user and save it to configuration user_handle = cls.call('contact.info')['handle'] cls.configure(True, 'api.handle', user_handle) owner_ = owner or user_handle admin_ = admin or user_handle tech_ = tech or user_handle bill_ = bill or user_handle domain_params = { 'duration': duration, 'owner': owner_, 'admin': admin_, 'tech': tech_, 'bill': bill_, } if nameserver: domain_params['nameservers'] = nameserver if extra_parameter: domain_params['extra'] = {} for extra in extra_parameter: domain_params['extra'][extra[0]] = extra[1] result = cls.call('domain.create', fqdn, domain_params) if background: return result # interactive mode, run a progress bar cls.echo('Creating your domain.') cls.display_progress(result) cls.echo('Your domain %s has been created.' % fqdn)
[ "def", "create", "(", "cls", ",", "fqdn", ",", "duration", ",", "owner", ",", "admin", ",", "tech", ",", "bill", ",", "nameserver", ",", "extra_parameter", ",", "background", ")", ":", "fqdn", "=", "fqdn", ".", "lower", "(", ")", "if", "not", "background", "and", "not", "cls", ".", "intty", "(", ")", ":", "background", "=", "True", "result", "=", "cls", ".", "call", "(", "'domain.available'", ",", "[", "fqdn", "]", ")", "while", "result", "[", "fqdn", "]", "==", "'pending'", ":", "time", ".", "sleep", "(", "1", ")", "result", "=", "cls", ".", "call", "(", "'domain.available'", ",", "[", "fqdn", "]", ")", "if", "result", "[", "fqdn", "]", "==", "'unavailable'", ":", "raise", "DomainNotAvailable", "(", "'%s is not available'", "%", "fqdn", ")", "# retrieve handle of user and save it to configuration", "user_handle", "=", "cls", ".", "call", "(", "'contact.info'", ")", "[", "'handle'", "]", "cls", ".", "configure", "(", "True", ",", "'api.handle'", ",", "user_handle", ")", "owner_", "=", "owner", "or", "user_handle", "admin_", "=", "admin", "or", "user_handle", "tech_", "=", "tech", "or", "user_handle", "bill_", "=", "bill", "or", "user_handle", "domain_params", "=", "{", "'duration'", ":", "duration", ",", "'owner'", ":", "owner_", ",", "'admin'", ":", "admin_", ",", "'tech'", ":", "tech_", ",", "'bill'", ":", "bill_", ",", "}", "if", "nameserver", ":", "domain_params", "[", "'nameservers'", "]", "=", "nameserver", "if", "extra_parameter", ":", "domain_params", "[", "'extra'", "]", "=", "{", "}", "for", "extra", "in", "extra_parameter", ":", "domain_params", "[", "'extra'", "]", "[", "extra", "[", "0", "]", "]", "=", "extra", "[", "1", "]", "result", "=", "cls", ".", "call", "(", "'domain.create'", ",", "fqdn", ",", "domain_params", ")", "if", "background", ":", "return", "result", "# interactive mode, run a progress bar", "cls", ".", "echo", "(", "'Creating your domain.'", ")", "cls", ".", "display_progress", "(", "result", ")", "cls", ".", "echo", "(", "'Your domain %s has been created.'", "%", "fqdn", ")" ]
Create a domain.
[ "Create", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/domain.py#L30-L77
11,162
Gandi/gandi.cli
gandi/cli/modules/domain.py
Domain.from_fqdn
def from_fqdn(cls, fqdn): """Retrieve domain id associated to a FQDN.""" result = cls.list({'fqdn': fqdn}) if len(result) > 0: return result[0]['id']
python
def from_fqdn(cls, fqdn): """Retrieve domain id associated to a FQDN.""" result = cls.list({'fqdn': fqdn}) if len(result) > 0: return result[0]['id']
[ "def", "from_fqdn", "(", "cls", ",", "fqdn", ")", ":", "result", "=", "cls", ".", "list", "(", "{", "'fqdn'", ":", "fqdn", "}", ")", "if", "len", "(", "result", ")", ">", "0", ":", "return", "result", "[", "0", "]", "[", "'id'", "]" ]
Retrieve domain id associated to a FQDN.
[ "Retrieve", "domain", "id", "associated", "to", "a", "FQDN", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/domain.py#L122-L126
11,163
Gandi/gandi.cli
gandi/cli/commands/disk.py
list
def list(gandi, only_data, only_snapshot, attached, detached, type, id, vm, snapshotprofile, datacenter, limit): """ List disks. """ options = { 'items_per_page': limit, } if attached and detached: raise UsageError('You cannot use both --attached and --detached.') if only_data: options.setdefault('type', []).append('data') if only_snapshot: options.setdefault('type', []).append('snapshot') if datacenter: options['datacenter_id'] = gandi.datacenter.usable_id(datacenter) output_keys = ['name', 'state', 'size'] if type: output_keys.append('type') if id: output_keys.append('id') if vm: output_keys.append('vm') profiles = [] if snapshotprofile: output_keys.append('profile') profiles = gandi.snapshotprofile.list() result = gandi.disk.list(options) vms = dict([(vm_['id'], vm_) for vm_ in gandi.iaas.list()]) # filter results per attached/detached disks = [] for disk in result: if attached and not disk['vms_id']: continue if detached and disk['vms_id']: continue disks.append(disk) for num, disk in enumerate(disks): if num: gandi.separator_line() output_disk(gandi, disk, [], vms, profiles, output_keys) return result
python
def list(gandi, only_data, only_snapshot, attached, detached, type, id, vm, snapshotprofile, datacenter, limit): """ List disks. """ options = { 'items_per_page': limit, } if attached and detached: raise UsageError('You cannot use both --attached and --detached.') if only_data: options.setdefault('type', []).append('data') if only_snapshot: options.setdefault('type', []).append('snapshot') if datacenter: options['datacenter_id'] = gandi.datacenter.usable_id(datacenter) output_keys = ['name', 'state', 'size'] if type: output_keys.append('type') if id: output_keys.append('id') if vm: output_keys.append('vm') profiles = [] if snapshotprofile: output_keys.append('profile') profiles = gandi.snapshotprofile.list() result = gandi.disk.list(options) vms = dict([(vm_['id'], vm_) for vm_ in gandi.iaas.list()]) # filter results per attached/detached disks = [] for disk in result: if attached and not disk['vms_id']: continue if detached and disk['vms_id']: continue disks.append(disk) for num, disk in enumerate(disks): if num: gandi.separator_line() output_disk(gandi, disk, [], vms, profiles, output_keys) return result
[ "def", "list", "(", "gandi", ",", "only_data", ",", "only_snapshot", ",", "attached", ",", "detached", ",", "type", ",", "id", ",", "vm", ",", "snapshotprofile", ",", "datacenter", ",", "limit", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", ",", "}", "if", "attached", "and", "detached", ":", "raise", "UsageError", "(", "'You cannot use both --attached and --detached.'", ")", "if", "only_data", ":", "options", ".", "setdefault", "(", "'type'", ",", "[", "]", ")", ".", "append", "(", "'data'", ")", "if", "only_snapshot", ":", "options", ".", "setdefault", "(", "'type'", ",", "[", "]", ")", ".", "append", "(", "'snapshot'", ")", "if", "datacenter", ":", "options", "[", "'datacenter_id'", "]", "=", "gandi", ".", "datacenter", ".", "usable_id", "(", "datacenter", ")", "output_keys", "=", "[", "'name'", ",", "'state'", ",", "'size'", "]", "if", "type", ":", "output_keys", ".", "append", "(", "'type'", ")", "if", "id", ":", "output_keys", ".", "append", "(", "'id'", ")", "if", "vm", ":", "output_keys", ".", "append", "(", "'vm'", ")", "profiles", "=", "[", "]", "if", "snapshotprofile", ":", "output_keys", ".", "append", "(", "'profile'", ")", "profiles", "=", "gandi", ".", "snapshotprofile", ".", "list", "(", ")", "result", "=", "gandi", ".", "disk", ".", "list", "(", "options", ")", "vms", "=", "dict", "(", "[", "(", "vm_", "[", "'id'", "]", ",", "vm_", ")", "for", "vm_", "in", "gandi", ".", "iaas", ".", "list", "(", ")", "]", ")", "# filter results per attached/detached", "disks", "=", "[", "]", "for", "disk", "in", "result", ":", "if", "attached", "and", "not", "disk", "[", "'vms_id'", "]", ":", "continue", "if", "detached", "and", "disk", "[", "'vms_id'", "]", ":", "continue", "disks", ".", "append", "(", "disk", ")", "for", "num", ",", "disk", "in", "enumerate", "(", "disks", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_disk", "(", "gandi", ",", "disk", ",", "[", "]", ",", "vms", ",", "profiles", ",", "output_keys", ")", "return", "result" ]
List disks.
[ "List", "disks", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L38-L85
11,164
Gandi/gandi.cli
gandi/cli/commands/disk.py
info
def info(gandi, resource): """ Display information about a disk. Resource can be a disk name or ID """ output_keys = ['name', 'state', 'size', 'type', 'id', 'dc', 'vm', 'profile', 'kernel', 'cmdline'] resource = sorted(tuple(set(resource))) vms = dict([(vm['id'], vm) for vm in gandi.iaas.list()]) datacenters = gandi.datacenter.list() result = [] for num, item in enumerate(resource): if num: gandi.separator_line() disk = gandi.disk.info(item) output_disk(gandi, disk, datacenters, vms, [], output_keys) result.append(disk) return result
python
def info(gandi, resource): """ Display information about a disk. Resource can be a disk name or ID """ output_keys = ['name', 'state', 'size', 'type', 'id', 'dc', 'vm', 'profile', 'kernel', 'cmdline'] resource = sorted(tuple(set(resource))) vms = dict([(vm['id'], vm) for vm in gandi.iaas.list()]) datacenters = gandi.datacenter.list() result = [] for num, item in enumerate(resource): if num: gandi.separator_line() disk = gandi.disk.info(item) output_disk(gandi, disk, datacenters, vms, [], output_keys) result.append(disk) return result
[ "def", "info", "(", "gandi", ",", "resource", ")", ":", "output_keys", "=", "[", "'name'", ",", "'state'", ",", "'size'", ",", "'type'", ",", "'id'", ",", "'dc'", ",", "'vm'", ",", "'profile'", ",", "'kernel'", ",", "'cmdline'", "]", "resource", "=", "sorted", "(", "tuple", "(", "set", "(", "resource", ")", ")", ")", "vms", "=", "dict", "(", "[", "(", "vm", "[", "'id'", "]", ",", "vm", ")", "for", "vm", "in", "gandi", ".", "iaas", ".", "list", "(", ")", "]", ")", "datacenters", "=", "gandi", ".", "datacenter", ".", "list", "(", ")", "result", "=", "[", "]", "for", "num", ",", "item", "in", "enumerate", "(", "resource", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "disk", "=", "gandi", ".", "disk", ".", "info", "(", "item", ")", "output_disk", "(", "gandi", ",", "disk", ",", "datacenters", ",", "vms", ",", "[", "]", ",", "output_keys", ")", "result", ".", "append", "(", "disk", ")", "return", "result" ]
Display information about a disk. Resource can be a disk name or ID
[ "Display", "information", "about", "a", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L91-L111
11,165
Gandi/gandi.cli
gandi/cli/commands/disk.py
detach
def detach(gandi, resource, background, force): """ Detach disks from currectly attached vm. Resource can be a disk name, or ID """ resource = sorted(tuple(set(resource))) if not force: proceed = click.confirm('Are you sure you want to detach %s?' % ', '.join(resource)) if not proceed: return result = gandi.disk.detach(resource, background) if background: gandi.pretty_echo(result) return result
python
def detach(gandi, resource, background, force): """ Detach disks from currectly attached vm. Resource can be a disk name, or ID """ resource = sorted(tuple(set(resource))) if not force: proceed = click.confirm('Are you sure you want to detach %s?' % ', '.join(resource)) if not proceed: return result = gandi.disk.detach(resource, background) if background: gandi.pretty_echo(result) return result
[ "def", "detach", "(", "gandi", ",", "resource", ",", "background", ",", "force", ")", ":", "resource", "=", "sorted", "(", "tuple", "(", "set", "(", "resource", ")", ")", ")", "if", "not", "force", ":", "proceed", "=", "click", ".", "confirm", "(", "'Are you sure you want to detach %s?'", "%", "', '", ".", "join", "(", "resource", ")", ")", "if", "not", "proceed", ":", "return", "result", "=", "gandi", ".", "disk", ".", "detach", "(", "resource", ",", "background", ")", "if", "background", ":", "gandi", ".", "pretty_echo", "(", "result", ")", "return", "result" ]
Detach disks from currectly attached vm. Resource can be a disk name, or ID
[ "Detach", "disks", "from", "currectly", "attached", "vm", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L122-L138
11,166
Gandi/gandi.cli
gandi/cli/commands/disk.py
attach
def attach(gandi, disk, vm, position, read_only, background, force): """ Attach disk to vm. disk can be a disk name, or ID vm can be a vm name, or ID """ if not force: proceed = click.confirm("Are you sure you want to attach disk '%s'" " to vm '%s'?" % (disk, vm)) if not proceed: return disk_info = gandi.disk.info(disk) attached = disk_info.get('vms_id', False) if attached and not force: gandi.echo('This disk is still attached') proceed = click.confirm('Are you sure you want to detach %s?' % disk) if not proceed: return result = gandi.disk.attach(disk, vm, background, position, read_only) if background and result: gandi.pretty_echo(result) return result
python
def attach(gandi, disk, vm, position, read_only, background, force): """ Attach disk to vm. disk can be a disk name, or ID vm can be a vm name, or ID """ if not force: proceed = click.confirm("Are you sure you want to attach disk '%s'" " to vm '%s'?" % (disk, vm)) if not proceed: return disk_info = gandi.disk.info(disk) attached = disk_info.get('vms_id', False) if attached and not force: gandi.echo('This disk is still attached') proceed = click.confirm('Are you sure you want to detach %s?' % disk) if not proceed: return result = gandi.disk.attach(disk, vm, background, position, read_only) if background and result: gandi.pretty_echo(result) return result
[ "def", "attach", "(", "gandi", ",", "disk", ",", "vm", ",", "position", ",", "read_only", ",", "background", ",", "force", ")", ":", "if", "not", "force", ":", "proceed", "=", "click", ".", "confirm", "(", "\"Are you sure you want to attach disk '%s'\"", "\" to vm '%s'?\"", "%", "(", "disk", ",", "vm", ")", ")", "if", "not", "proceed", ":", "return", "disk_info", "=", "gandi", ".", "disk", ".", "info", "(", "disk", ")", "attached", "=", "disk_info", ".", "get", "(", "'vms_id'", ",", "False", ")", "if", "attached", "and", "not", "force", ":", "gandi", ".", "echo", "(", "'This disk is still attached'", ")", "proceed", "=", "click", ".", "confirm", "(", "'Are you sure you want to detach %s?'", "%", "disk", ")", "if", "not", "proceed", ":", "return", "result", "=", "gandi", ".", "disk", ".", "attach", "(", "disk", ",", "vm", ",", "background", ",", "position", ",", "read_only", ")", "if", "background", "and", "result", ":", "gandi", ".", "pretty_echo", "(", "result", ")", "return", "result" ]
Attach disk to vm. disk can be a disk name, or ID vm can be a vm name, or ID
[ "Attach", "disk", "to", "vm", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L156-L181
11,167
Gandi/gandi.cli
gandi/cli/commands/disk.py
update
def update(gandi, resource, cmdline, kernel, name, size, snapshotprofile, delete_snapshotprofile, background): """ Update a disk. Resource can be a disk name, or ID """ if snapshotprofile and delete_snapshotprofile: raise UsageError('You must not set snapshotprofile and ' 'delete-snapshotprofile.') if delete_snapshotprofile: snapshotprofile = '' if kernel: source_info = gandi.disk.info(resource) available = gandi.kernel.is_available(source_info, kernel) if not available: raise UsageError('Kernel %s is not available for disk %s' % (kernel, resource)) result = gandi.disk.update(resource, name, size, snapshotprofile, background, cmdline, kernel) if background: gandi.pretty_echo(result) return result
python
def update(gandi, resource, cmdline, kernel, name, size, snapshotprofile, delete_snapshotprofile, background): """ Update a disk. Resource can be a disk name, or ID """ if snapshotprofile and delete_snapshotprofile: raise UsageError('You must not set snapshotprofile and ' 'delete-snapshotprofile.') if delete_snapshotprofile: snapshotprofile = '' if kernel: source_info = gandi.disk.info(resource) available = gandi.kernel.is_available(source_info, kernel) if not available: raise UsageError('Kernel %s is not available for disk %s' % (kernel, resource)) result = gandi.disk.update(resource, name, size, snapshotprofile, background, cmdline, kernel) if background: gandi.pretty_echo(result) return result
[ "def", "update", "(", "gandi", ",", "resource", ",", "cmdline", ",", "kernel", ",", "name", ",", "size", ",", "snapshotprofile", ",", "delete_snapshotprofile", ",", "background", ")", ":", "if", "snapshotprofile", "and", "delete_snapshotprofile", ":", "raise", "UsageError", "(", "'You must not set snapshotprofile and '", "'delete-snapshotprofile.'", ")", "if", "delete_snapshotprofile", ":", "snapshotprofile", "=", "''", "if", "kernel", ":", "source_info", "=", "gandi", ".", "disk", ".", "info", "(", "resource", ")", "available", "=", "gandi", ".", "kernel", ".", "is_available", "(", "source_info", ",", "kernel", ")", "if", "not", "available", ":", "raise", "UsageError", "(", "'Kernel %s is not available for disk %s'", "%", "(", "kernel", ",", "resource", ")", ")", "result", "=", "gandi", ".", "disk", ".", "update", "(", "resource", ",", "name", ",", "size", ",", "snapshotprofile", ",", "background", ",", "cmdline", ",", "kernel", ")", "if", "background", ":", "gandi", ".", "pretty_echo", "(", "result", ")", "return", "result" ]
Update a disk. Resource can be a disk name, or ID
[ "Update", "a", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L204-L229
11,168
Gandi/gandi.cli
gandi/cli/commands/disk.py
delete
def delete(gandi, resource, force, background): """ Delete a disk. """ output_keys = ['id', 'type', 'step'] resource = sorted(tuple(set(resource))) if not force: disk_info = "'%s'" % ', '.join(resource) proceed = click.confirm('Are you sure you want to delete disk %s?' % disk_info) if not proceed: return opers = gandi.disk.delete(resource, background) if background: for oper in opers: output_generic(gandi, oper, output_keys) return opers
python
def delete(gandi, resource, force, background): """ Delete a disk. """ output_keys = ['id', 'type', 'step'] resource = sorted(tuple(set(resource))) if not force: disk_info = "'%s'" % ', '.join(resource) proceed = click.confirm('Are you sure you want to delete disk %s?' % disk_info) if not proceed: return opers = gandi.disk.delete(resource, background) if background: for oper in opers: output_generic(gandi, oper, output_keys) return opers
[ "def", "delete", "(", "gandi", ",", "resource", ",", "force", ",", "background", ")", ":", "output_keys", "=", "[", "'id'", ",", "'type'", ",", "'step'", "]", "resource", "=", "sorted", "(", "tuple", "(", "set", "(", "resource", ")", ")", ")", "if", "not", "force", ":", "disk_info", "=", "\"'%s'\"", "%", "', '", ".", "join", "(", "resource", ")", "proceed", "=", "click", ".", "confirm", "(", "'Are you sure you want to delete disk %s?'", "%", "disk_info", ")", "if", "not", "proceed", ":", "return", "opers", "=", "gandi", ".", "disk", ".", "delete", "(", "resource", ",", "background", ")", "if", "background", ":", "for", "oper", "in", "opers", ":", "output_generic", "(", "gandi", ",", "oper", ",", "output_keys", ")", "return", "opers" ]
Delete a disk.
[ "Delete", "a", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L240-L258
11,169
Gandi/gandi.cli
gandi/cli/commands/disk.py
create
def create(gandi, name, vm, size, snapshotprofile, datacenter, source, background): """ Create a new disk. """ try: gandi.datacenter.is_opened(datacenter, 'iaas') except DatacenterLimited as exc: gandi.echo('/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % (datacenter, exc.date)) if vm: vm_dc = gandi.iaas.info(vm) vm_dc_id = vm_dc['datacenter_id'] dc_id = int(gandi.datacenter.usable_id(datacenter)) if vm_dc_id != dc_id: gandi.echo('/!\ VM %s datacenter will be used instead of %s.' % (vm, datacenter)) datacenter = vm_dc_id output_keys = ['id', 'type', 'step'] name = name or randomstring('vdi') disk_type = 'data' oper = gandi.disk.create(name, vm, size, snapshotprofile, datacenter, source, disk_type, background) if background: output_generic(gandi, oper, output_keys) return oper
python
def create(gandi, name, vm, size, snapshotprofile, datacenter, source, background): """ Create a new disk. """ try: gandi.datacenter.is_opened(datacenter, 'iaas') except DatacenterLimited as exc: gandi.echo('/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % (datacenter, exc.date)) if vm: vm_dc = gandi.iaas.info(vm) vm_dc_id = vm_dc['datacenter_id'] dc_id = int(gandi.datacenter.usable_id(datacenter)) if vm_dc_id != dc_id: gandi.echo('/!\ VM %s datacenter will be used instead of %s.' % (vm, datacenter)) datacenter = vm_dc_id output_keys = ['id', 'type', 'step'] name = name or randomstring('vdi') disk_type = 'data' oper = gandi.disk.create(name, vm, size, snapshotprofile, datacenter, source, disk_type, background) if background: output_generic(gandi, oper, output_keys) return oper
[ "def", "create", "(", "gandi", ",", "name", ",", "vm", ",", "size", ",", "snapshotprofile", ",", "datacenter", ",", "source", ",", "background", ")", ":", "try", ":", "gandi", ".", "datacenter", ".", "is_opened", "(", "datacenter", ",", "'iaas'", ")", "except", "DatacenterLimited", "as", "exc", ":", "gandi", ".", "echo", "(", "'/!\\ Datacenter %s will be closed on %s, '", "'please consider using another datacenter.'", "%", "(", "datacenter", ",", "exc", ".", "date", ")", ")", "if", "vm", ":", "vm_dc", "=", "gandi", ".", "iaas", ".", "info", "(", "vm", ")", "vm_dc_id", "=", "vm_dc", "[", "'datacenter_id'", "]", "dc_id", "=", "int", "(", "gandi", ".", "datacenter", ".", "usable_id", "(", "datacenter", ")", ")", "if", "vm_dc_id", "!=", "dc_id", ":", "gandi", ".", "echo", "(", "'/!\\ VM %s datacenter will be used instead of %s.'", "%", "(", "vm", ",", "datacenter", ")", ")", "datacenter", "=", "vm_dc_id", "output_keys", "=", "[", "'id'", ",", "'type'", ",", "'step'", "]", "name", "=", "name", "or", "randomstring", "(", "'vdi'", ")", "disk_type", "=", "'data'", "oper", "=", "gandi", ".", "disk", ".", "create", "(", "name", ",", "vm", ",", "size", ",", "snapshotprofile", ",", "datacenter", ",", "source", ",", "disk_type", ",", "background", ")", "if", "background", ":", "output_generic", "(", "gandi", ",", "oper", ",", "output_keys", ")", "return", "oper" ]
Create a new disk.
[ "Create", "a", "new", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L280-L309
11,170
Gandi/gandi.cli
gandi/cli/commands/disk.py
snapshot
def snapshot(gandi, name, resource, background): """ Create a snapshot on the fly. """ name = name or randomstring('snp') source_info = gandi.disk.info(resource) datacenter = source_info['datacenter_id'] result = gandi.disk.create(name, None, None, None, datacenter, resource, 'snapshot', background) if background: gandi.pretty_echo(result) return result
python
def snapshot(gandi, name, resource, background): """ Create a snapshot on the fly. """ name = name or randomstring('snp') source_info = gandi.disk.info(resource) datacenter = source_info['datacenter_id'] result = gandi.disk.create(name, None, None, None, datacenter, resource, 'snapshot', background) if background: gandi.pretty_echo(result) return result
[ "def", "snapshot", "(", "gandi", ",", "name", ",", "resource", ",", "background", ")", ":", "name", "=", "name", "or", "randomstring", "(", "'snp'", ")", "source_info", "=", "gandi", ".", "disk", ".", "info", "(", "resource", ")", "datacenter", "=", "source_info", "[", "'datacenter_id'", "]", "result", "=", "gandi", ".", "disk", ".", "create", "(", "name", ",", "None", ",", "None", ",", "None", ",", "datacenter", ",", "resource", ",", "'snapshot'", ",", "background", ")", "if", "background", ":", "gandi", ".", "pretty_echo", "(", "result", ")", "return", "result" ]
Create a snapshot on the fly.
[ "Create", "a", "snapshot", "on", "the", "fly", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L319-L330
11,171
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
format_list
def format_list(data): """ Remove useless characters to output a clean list.""" if isinstance(data, (list, tuple)): to_clean = ['[', ']', '(', ')', "'"] for item in to_clean: data = str(data).replace("u\"", "\"").replace("u\'", "\'") data = str(data).replace(item, '') return data
python
def format_list(data): """ Remove useless characters to output a clean list.""" if isinstance(data, (list, tuple)): to_clean = ['[', ']', '(', ')', "'"] for item in to_clean: data = str(data).replace("u\"", "\"").replace("u\'", "\'") data = str(data).replace(item, '') return data
[ "def", "format_list", "(", "data", ")", ":", "if", "isinstance", "(", "data", ",", "(", "list", ",", "tuple", ")", ")", ":", "to_clean", "=", "[", "'['", ",", "']'", ",", "'('", ",", "')'", ",", "\"'\"", "]", "for", "item", "in", "to_clean", ":", "data", "=", "str", "(", "data", ")", ".", "replace", "(", "\"u\\\"\"", ",", "\"\\\"\"", ")", ".", "replace", "(", "\"u\\'\"", ",", "\"\\'\"", ")", "data", "=", "str", "(", "data", ")", ".", "replace", "(", "item", ",", "''", ")", "return", "data" ]
Remove useless characters to output a clean list.
[ "Remove", "useless", "characters", "to", "output", "a", "clean", "list", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L70-L77
11,172
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_account
def output_account(gandi, account, output_keys, justify=17): """ Helper to output an account information.""" output_generic(gandi, account, output_keys, justify) if 'prepaid' in output_keys: prepaid = '%s %s' % (account['prepaid_info']['amount'], account['prepaid_info']['currency']) output_line(gandi, 'prepaid', prepaid, justify) if 'credit' in output_keys: output_line(gandi, 'credits', None, justify) available = account.get('credits') output_line(gandi, ' available', available, justify) # sometimes rating is returning nothing usage_str = left_str = 'not available' usage = account.get('credit_usage', 0) left = account.get('left') if usage: usage_str = '%d/h' % usage years, months, days, hours = left left_str = ('%d year(s) %d month(s) %d day(s) %d hour(s)' % (years, months, days, hours)) output_line(gandi, ' usage', usage_str, justify) output_line(gandi, ' time left', left_str, justify)
python
def output_account(gandi, account, output_keys, justify=17): """ Helper to output an account information.""" output_generic(gandi, account, output_keys, justify) if 'prepaid' in output_keys: prepaid = '%s %s' % (account['prepaid_info']['amount'], account['prepaid_info']['currency']) output_line(gandi, 'prepaid', prepaid, justify) if 'credit' in output_keys: output_line(gandi, 'credits', None, justify) available = account.get('credits') output_line(gandi, ' available', available, justify) # sometimes rating is returning nothing usage_str = left_str = 'not available' usage = account.get('credit_usage', 0) left = account.get('left') if usage: usage_str = '%d/h' % usage years, months, days, hours = left left_str = ('%d year(s) %d month(s) %d day(s) %d hour(s)' % (years, months, days, hours)) output_line(gandi, ' usage', usage_str, justify) output_line(gandi, ' time left', left_str, justify)
[ "def", "output_account", "(", "gandi", ",", "account", ",", "output_keys", ",", "justify", "=", "17", ")", ":", "output_generic", "(", "gandi", ",", "account", ",", "output_keys", ",", "justify", ")", "if", "'prepaid'", "in", "output_keys", ":", "prepaid", "=", "'%s %s'", "%", "(", "account", "[", "'prepaid_info'", "]", "[", "'amount'", "]", ",", "account", "[", "'prepaid_info'", "]", "[", "'currency'", "]", ")", "output_line", "(", "gandi", ",", "'prepaid'", ",", "prepaid", ",", "justify", ")", "if", "'credit'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'credits'", ",", "None", ",", "justify", ")", "available", "=", "account", ".", "get", "(", "'credits'", ")", "output_line", "(", "gandi", ",", "' available'", ",", "available", ",", "justify", ")", "# sometimes rating is returning nothing", "usage_str", "=", "left_str", "=", "'not available'", "usage", "=", "account", ".", "get", "(", "'credit_usage'", ",", "0", ")", "left", "=", "account", ".", "get", "(", "'left'", ")", "if", "usage", ":", "usage_str", "=", "'%d/h'", "%", "usage", "years", ",", "months", ",", "days", ",", "hours", "=", "left", "left_str", "=", "(", "'%d year(s) %d month(s) %d day(s) %d hour(s)'", "%", "(", "years", ",", "months", ",", "days", ",", "hours", ")", ")", "output_line", "(", "gandi", ",", "' usage'", ",", "usage_str", ",", "justify", ")", "output_line", "(", "gandi", ",", "' time left'", ",", "left_str", ",", "justify", ")" ]
Helper to output an account information.
[ "Helper", "to", "output", "an", "account", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L106-L131
11,173
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_vm
def output_vm(gandi, vm, datacenters, output_keys, justify=10): """ Helper to output a vm information.""" output_generic(gandi, vm, output_keys, justify) if 'datacenter' in output_keys: for dc in datacenters: if dc['id'] == vm['datacenter_id']: dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify) if 'ip' in output_keys: for iface in vm['ifaces']: gandi.separator_line() output_line(gandi, 'bandwidth', iface['bandwidth'], justify) for ip in iface['ips']: ip_addr = ip['ip'] output_line(gandi, 'ip%s' % ip['version'], ip_addr, justify)
python
def output_vm(gandi, vm, datacenters, output_keys, justify=10): """ Helper to output a vm information.""" output_generic(gandi, vm, output_keys, justify) if 'datacenter' in output_keys: for dc in datacenters: if dc['id'] == vm['datacenter_id']: dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify) if 'ip' in output_keys: for iface in vm['ifaces']: gandi.separator_line() output_line(gandi, 'bandwidth', iface['bandwidth'], justify) for ip in iface['ips']: ip_addr = ip['ip'] output_line(gandi, 'ip%s' % ip['version'], ip_addr, justify)
[ "def", "output_vm", "(", "gandi", ",", "vm", ",", "datacenters", ",", "output_keys", ",", "justify", "=", "10", ")", ":", "output_generic", "(", "gandi", ",", "vm", ",", "output_keys", ",", "justify", ")", "if", "'datacenter'", "in", "output_keys", ":", "for", "dc", "in", "datacenters", ":", "if", "dc", "[", "'id'", "]", "==", "vm", "[", "'datacenter_id'", "]", ":", "dc_name", "=", "dc", ".", "get", "(", "'dc_code'", ",", "dc", ".", "get", "(", "'iso'", ",", "''", ")", ")", "break", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")", "if", "'ip'", "in", "output_keys", ":", "for", "iface", "in", "vm", "[", "'ifaces'", "]", ":", "gandi", ".", "separator_line", "(", ")", "output_line", "(", "gandi", ",", "'bandwidth'", ",", "iface", "[", "'bandwidth'", "]", ",", "justify", ")", "for", "ip", "in", "iface", "[", "'ips'", "]", ":", "ip_addr", "=", "ip", "[", "'ip'", "]", "output_line", "(", "gandi", ",", "'ip%s'", "%", "ip", "[", "'version'", "]", ",", "ip_addr", ",", "justify", ")" ]
Helper to output a vm information.
[ "Helper", "to", "output", "a", "vm", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L134-L154
11,174
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_metric
def output_metric(gandi, metrics, key, justify=10): """ Helper to output metrics.""" for metric in metrics: key_name = metric[key].pop() values = [point.get('value', 0) for point in metric['points']] graph = sparks(values) if max(values) else '' # need to encode in utf-8 to work in python2.X if sys.version_info < (2, 8): graph = graph.encode('utf-8') output_line(gandi, key_name, graph, justify)
python
def output_metric(gandi, metrics, key, justify=10): """ Helper to output metrics.""" for metric in metrics: key_name = metric[key].pop() values = [point.get('value', 0) for point in metric['points']] graph = sparks(values) if max(values) else '' # need to encode in utf-8 to work in python2.X if sys.version_info < (2, 8): graph = graph.encode('utf-8') output_line(gandi, key_name, graph, justify)
[ "def", "output_metric", "(", "gandi", ",", "metrics", ",", "key", ",", "justify", "=", "10", ")", ":", "for", "metric", "in", "metrics", ":", "key_name", "=", "metric", "[", "key", "]", ".", "pop", "(", ")", "values", "=", "[", "point", ".", "get", "(", "'value'", ",", "0", ")", "for", "point", "in", "metric", "[", "'points'", "]", "]", "graph", "=", "sparks", "(", "values", ")", "if", "max", "(", "values", ")", "else", "''", "# need to encode in utf-8 to work in python2.X", "if", "sys", ".", "version_info", "<", "(", "2", ",", "8", ")", ":", "graph", "=", "graph", ".", "encode", "(", "'utf-8'", ")", "output_line", "(", "gandi", ",", "key_name", ",", "graph", ",", "justify", ")" ]
Helper to output metrics.
[ "Helper", "to", "output", "metrics", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L157-L166
11,175
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_vhost
def output_vhost(gandi, vhost, paas, output_keys, justify=14): """ Helper to output a vhost information.""" output_generic(gandi, vhost, output_keys, justify) if 'paas_name' in output_keys: output_line(gandi, 'paas_name', paas, justify)
python
def output_vhost(gandi, vhost, paas, output_keys, justify=14): """ Helper to output a vhost information.""" output_generic(gandi, vhost, output_keys, justify) if 'paas_name' in output_keys: output_line(gandi, 'paas_name', paas, justify)
[ "def", "output_vhost", "(", "gandi", ",", "vhost", ",", "paas", ",", "output_keys", ",", "justify", "=", "14", ")", ":", "output_generic", "(", "gandi", ",", "vhost", ",", "output_keys", ",", "justify", ")", "if", "'paas_name'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'paas_name'", ",", "paas", ",", "justify", ")" ]
Helper to output a vhost information.
[ "Helper", "to", "output", "a", "vhost", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L169-L174
11,176
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_paas
def output_paas(gandi, paas, datacenters, vhosts, output_keys, justify=11): """ Helper to output a paas information.""" output_generic(gandi, paas, output_keys, justify) if 'sftp_server' in output_keys: output_line(gandi, 'sftp_server', paas['ftp_server'], justify) if 'vhost' in output_keys: for entry in vhosts: output_line(gandi, 'vhost', entry, justify) if 'dc' in output_keys: dc_name = paas['datacenter'].get('dc_code', paas['datacenter'].get('iso', '')) output_line(gandi, 'datacenter', dc_name, justify) if 'df' in paas: df = paas['df'] total = df['free'] + df['used'] if total: disk_used = '%.1f%%' % (df['used'] * 100 / total) output_line(gandi, 'quota used', disk_used, justify) if 'snapshot' in output_keys: val = None if paas['snapshot_profile']: val = paas['snapshot_profile']['name'] output_line(gandi, 'snapshot', val, justify) if 'cache' in paas: cache = paas['cache'] total = cache['hit'] + cache['miss'] + cache['not'] + cache['pass'] if total: output_line(gandi, 'cache', None, justify) for key in sorted(cache): str_value = '%.1f%%' % (cache[key] * 100 / total) output_sub_line(gandi, key, str_value, 5)
python
def output_paas(gandi, paas, datacenters, vhosts, output_keys, justify=11): """ Helper to output a paas information.""" output_generic(gandi, paas, output_keys, justify) if 'sftp_server' in output_keys: output_line(gandi, 'sftp_server', paas['ftp_server'], justify) if 'vhost' in output_keys: for entry in vhosts: output_line(gandi, 'vhost', entry, justify) if 'dc' in output_keys: dc_name = paas['datacenter'].get('dc_code', paas['datacenter'].get('iso', '')) output_line(gandi, 'datacenter', dc_name, justify) if 'df' in paas: df = paas['df'] total = df['free'] + df['used'] if total: disk_used = '%.1f%%' % (df['used'] * 100 / total) output_line(gandi, 'quota used', disk_used, justify) if 'snapshot' in output_keys: val = None if paas['snapshot_profile']: val = paas['snapshot_profile']['name'] output_line(gandi, 'snapshot', val, justify) if 'cache' in paas: cache = paas['cache'] total = cache['hit'] + cache['miss'] + cache['not'] + cache['pass'] if total: output_line(gandi, 'cache', None, justify) for key in sorted(cache): str_value = '%.1f%%' % (cache[key] * 100 / total) output_sub_line(gandi, key, str_value, 5)
[ "def", "output_paas", "(", "gandi", ",", "paas", ",", "datacenters", ",", "vhosts", ",", "output_keys", ",", "justify", "=", "11", ")", ":", "output_generic", "(", "gandi", ",", "paas", ",", "output_keys", ",", "justify", ")", "if", "'sftp_server'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'sftp_server'", ",", "paas", "[", "'ftp_server'", "]", ",", "justify", ")", "if", "'vhost'", "in", "output_keys", ":", "for", "entry", "in", "vhosts", ":", "output_line", "(", "gandi", ",", "'vhost'", ",", "entry", ",", "justify", ")", "if", "'dc'", "in", "output_keys", ":", "dc_name", "=", "paas", "[", "'datacenter'", "]", ".", "get", "(", "'dc_code'", ",", "paas", "[", "'datacenter'", "]", ".", "get", "(", "'iso'", ",", "''", ")", ")", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")", "if", "'df'", "in", "paas", ":", "df", "=", "paas", "[", "'df'", "]", "total", "=", "df", "[", "'free'", "]", "+", "df", "[", "'used'", "]", "if", "total", ":", "disk_used", "=", "'%.1f%%'", "%", "(", "df", "[", "'used'", "]", "*", "100", "/", "total", ")", "output_line", "(", "gandi", ",", "'quota used'", ",", "disk_used", ",", "justify", ")", "if", "'snapshot'", "in", "output_keys", ":", "val", "=", "None", "if", "paas", "[", "'snapshot_profile'", "]", ":", "val", "=", "paas", "[", "'snapshot_profile'", "]", "[", "'name'", "]", "output_line", "(", "gandi", ",", "'snapshot'", ",", "val", ",", "justify", ")", "if", "'cache'", "in", "paas", ":", "cache", "=", "paas", "[", "'cache'", "]", "total", "=", "cache", "[", "'hit'", "]", "+", "cache", "[", "'miss'", "]", "+", "cache", "[", "'not'", "]", "+", "cache", "[", "'pass'", "]", "if", "total", ":", "output_line", "(", "gandi", ",", "'cache'", ",", "None", ",", "justify", ")", "for", "key", "in", "sorted", "(", "cache", ")", ":", "str_value", "=", "'%.1f%%'", "%", "(", "cache", "[", "key", "]", "*", "100", "/", "total", ")", "output_sub_line", "(", "gandi", ",", "key", ",", "str_value", ",", "5", ")" ]
Helper to output a paas information.
[ "Helper", "to", "output", "a", "paas", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L177-L213
11,177
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_image
def output_image(gandi, image, datacenters, output_keys, justify=14, warn_deprecated=True): """ Helper to output a disk image.""" for key in output_keys: if key in image: if (key == 'label' and image['visibility'] == 'deprecated' and warn_deprecated): image[key] = '%s /!\ DEPRECATED' % image[key] output_line(gandi, key, image[key], justify) dc_name = 'Nowhere' if 'dc' in output_keys: for dc in datacenters: if dc['id'] == image['datacenter_id']: dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify)
python
def output_image(gandi, image, datacenters, output_keys, justify=14, warn_deprecated=True): """ Helper to output a disk image.""" for key in output_keys: if key in image: if (key == 'label' and image['visibility'] == 'deprecated' and warn_deprecated): image[key] = '%s /!\ DEPRECATED' % image[key] output_line(gandi, key, image[key], justify) dc_name = 'Nowhere' if 'dc' in output_keys: for dc in datacenters: if dc['id'] == image['datacenter_id']: dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify)
[ "def", "output_image", "(", "gandi", ",", "image", ",", "datacenters", ",", "output_keys", ",", "justify", "=", "14", ",", "warn_deprecated", "=", "True", ")", ":", "for", "key", "in", "output_keys", ":", "if", "key", "in", "image", ":", "if", "(", "key", "==", "'label'", "and", "image", "[", "'visibility'", "]", "==", "'deprecated'", "and", "warn_deprecated", ")", ":", "image", "[", "key", "]", "=", "'%s /!\\ DEPRECATED'", "%", "image", "[", "key", "]", "output_line", "(", "gandi", ",", "key", ",", "image", "[", "key", "]", ",", "justify", ")", "dc_name", "=", "'Nowhere'", "if", "'dc'", "in", "output_keys", ":", "for", "dc", "in", "datacenters", ":", "if", "dc", "[", "'id'", "]", "==", "image", "[", "'datacenter_id'", "]", ":", "dc_name", "=", "dc", ".", "get", "(", "'dc_code'", ",", "dc", ".", "get", "(", "'iso'", ",", "''", ")", ")", "break", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")" ]
Helper to output a disk image.
[ "Helper", "to", "output", "a", "disk", "image", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L216-L236
11,178
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_kernels
def output_kernels(gandi, flavor, name_list, justify=14): """ Helper to output kernel flavor versions.""" output_line(gandi, 'flavor', flavor, justify) for name in name_list: output_line(gandi, 'version', name, justify)
python
def output_kernels(gandi, flavor, name_list, justify=14): """ Helper to output kernel flavor versions.""" output_line(gandi, 'flavor', flavor, justify) for name in name_list: output_line(gandi, 'version', name, justify)
[ "def", "output_kernels", "(", "gandi", ",", "flavor", ",", "name_list", ",", "justify", "=", "14", ")", ":", "output_line", "(", "gandi", ",", "'flavor'", ",", "flavor", ",", "justify", ")", "for", "name", "in", "name_list", ":", "output_line", "(", "gandi", ",", "'version'", ",", "name", ",", "justify", ")" ]
Helper to output kernel flavor versions.
[ "Helper", "to", "output", "kernel", "flavor", "versions", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L239-L243
11,179
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_datacenter
def output_datacenter(gandi, datacenter, output_keys, justify=14): """ Helper to output datacenter information.""" output_generic(gandi, datacenter, output_keys, justify) if 'dc_name' in output_keys: output_line(gandi, 'datacenter', datacenter['name'], justify) if 'status' in output_keys: deactivate_at = datacenter.get('deactivate_at') if deactivate_at: output_line(gandi, 'closing on', deactivate_at.strftime('%d/%m/%Y'), justify) closing = [] iaas_closed_for = datacenter.get('iaas_closed_for') if iaas_closed_for == 'ALL': closing.append('vm') paas_closed_for = datacenter.get('paas_closed_for') if paas_closed_for == 'ALL': closing.append('paas') if closing: output_line(gandi, 'closed for', ', '.join(closing), justify)
python
def output_datacenter(gandi, datacenter, output_keys, justify=14): """ Helper to output datacenter information.""" output_generic(gandi, datacenter, output_keys, justify) if 'dc_name' in output_keys: output_line(gandi, 'datacenter', datacenter['name'], justify) if 'status' in output_keys: deactivate_at = datacenter.get('deactivate_at') if deactivate_at: output_line(gandi, 'closing on', deactivate_at.strftime('%d/%m/%Y'), justify) closing = [] iaas_closed_for = datacenter.get('iaas_closed_for') if iaas_closed_for == 'ALL': closing.append('vm') paas_closed_for = datacenter.get('paas_closed_for') if paas_closed_for == 'ALL': closing.append('paas') if closing: output_line(gandi, 'closed for', ', '.join(closing), justify)
[ "def", "output_datacenter", "(", "gandi", ",", "datacenter", ",", "output_keys", ",", "justify", "=", "14", ")", ":", "output_generic", "(", "gandi", ",", "datacenter", ",", "output_keys", ",", "justify", ")", "if", "'dc_name'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'datacenter'", ",", "datacenter", "[", "'name'", "]", ",", "justify", ")", "if", "'status'", "in", "output_keys", ":", "deactivate_at", "=", "datacenter", ".", "get", "(", "'deactivate_at'", ")", "if", "deactivate_at", ":", "output_line", "(", "gandi", ",", "'closing on'", ",", "deactivate_at", ".", "strftime", "(", "'%d/%m/%Y'", ")", ",", "justify", ")", "closing", "=", "[", "]", "iaas_closed_for", "=", "datacenter", ".", "get", "(", "'iaas_closed_for'", ")", "if", "iaas_closed_for", "==", "'ALL'", ":", "closing", ".", "append", "(", "'vm'", ")", "paas_closed_for", "=", "datacenter", ".", "get", "(", "'paas_closed_for'", ")", "if", "paas_closed_for", "==", "'ALL'", ":", "closing", ".", "append", "(", "'paas'", ")", "if", "closing", ":", "output_line", "(", "gandi", ",", "'closed for'", ",", "', '", ".", "join", "(", "closing", ")", ",", "justify", ")" ]
Helper to output datacenter information.
[ "Helper", "to", "output", "datacenter", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L246-L269
11,180
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_disk
def output_disk(gandi, disk, datacenters, vms, profiles, output_keys, justify=10): """ Helper to output a disk.""" output_generic(gandi, disk, output_keys, justify) if 'kernel' in output_keys and disk.get('kernel_version'): output_line(gandi, 'kernel', disk['kernel_version'], justify) if 'cmdline' in output_keys and disk.get('kernel_cmdline'): output_cmdline(gandi, disk.get('kernel_cmdline'), justify) if 'dc' in output_keys: dc_name = None for dc in datacenters: if dc['id'] == disk['datacenter_id']: dc_name = dc.get('dc_code', dc.get('iso', '')) break if dc_name: output_line(gandi, 'datacenter', dc_name, justify) if 'vm' in output_keys: for vm_id in disk['vms_id']: vm_name = vms.get(vm_id, {}).get('hostname') if vm_name: output_line(gandi, 'vm', vm_name, justify) if 'profile' in output_keys and disk.get('snapshot_profile'): output_line(gandi, 'profile', disk['snapshot_profile']['name'], justify) elif 'profile' in output_keys and disk.get('snapshot_profile_id'): for profile in profiles: if profile['id'] == disk['snapshot_profile_id']: output_line(gandi, 'profile', profile['name'], justify) break
python
def output_disk(gandi, disk, datacenters, vms, profiles, output_keys, justify=10): """ Helper to output a disk.""" output_generic(gandi, disk, output_keys, justify) if 'kernel' in output_keys and disk.get('kernel_version'): output_line(gandi, 'kernel', disk['kernel_version'], justify) if 'cmdline' in output_keys and disk.get('kernel_cmdline'): output_cmdline(gandi, disk.get('kernel_cmdline'), justify) if 'dc' in output_keys: dc_name = None for dc in datacenters: if dc['id'] == disk['datacenter_id']: dc_name = dc.get('dc_code', dc.get('iso', '')) break if dc_name: output_line(gandi, 'datacenter', dc_name, justify) if 'vm' in output_keys: for vm_id in disk['vms_id']: vm_name = vms.get(vm_id, {}).get('hostname') if vm_name: output_line(gandi, 'vm', vm_name, justify) if 'profile' in output_keys and disk.get('snapshot_profile'): output_line(gandi, 'profile', disk['snapshot_profile']['name'], justify) elif 'profile' in output_keys and disk.get('snapshot_profile_id'): for profile in profiles: if profile['id'] == disk['snapshot_profile_id']: output_line(gandi, 'profile', profile['name'], justify) break
[ "def", "output_disk", "(", "gandi", ",", "disk", ",", "datacenters", ",", "vms", ",", "profiles", ",", "output_keys", ",", "justify", "=", "10", ")", ":", "output_generic", "(", "gandi", ",", "disk", ",", "output_keys", ",", "justify", ")", "if", "'kernel'", "in", "output_keys", "and", "disk", ".", "get", "(", "'kernel_version'", ")", ":", "output_line", "(", "gandi", ",", "'kernel'", ",", "disk", "[", "'kernel_version'", "]", ",", "justify", ")", "if", "'cmdline'", "in", "output_keys", "and", "disk", ".", "get", "(", "'kernel_cmdline'", ")", ":", "output_cmdline", "(", "gandi", ",", "disk", ".", "get", "(", "'kernel_cmdline'", ")", ",", "justify", ")", "if", "'dc'", "in", "output_keys", ":", "dc_name", "=", "None", "for", "dc", "in", "datacenters", ":", "if", "dc", "[", "'id'", "]", "==", "disk", "[", "'datacenter_id'", "]", ":", "dc_name", "=", "dc", ".", "get", "(", "'dc_code'", ",", "dc", ".", "get", "(", "'iso'", ",", "''", ")", ")", "break", "if", "dc_name", ":", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")", "if", "'vm'", "in", "output_keys", ":", "for", "vm_id", "in", "disk", "[", "'vms_id'", "]", ":", "vm_name", "=", "vms", ".", "get", "(", "vm_id", ",", "{", "}", ")", ".", "get", "(", "'hostname'", ")", "if", "vm_name", ":", "output_line", "(", "gandi", ",", "'vm'", ",", "vm_name", ",", "justify", ")", "if", "'profile'", "in", "output_keys", "and", "disk", ".", "get", "(", "'snapshot_profile'", ")", ":", "output_line", "(", "gandi", ",", "'profile'", ",", "disk", "[", "'snapshot_profile'", "]", "[", "'name'", "]", ",", "justify", ")", "elif", "'profile'", "in", "output_keys", "and", "disk", ".", "get", "(", "'snapshot_profile_id'", ")", ":", "for", "profile", "in", "profiles", ":", "if", "profile", "[", "'id'", "]", "==", "disk", "[", "'snapshot_profile_id'", "]", ":", "output_line", "(", "gandi", ",", "'profile'", ",", "profile", "[", "'name'", "]", ",", "justify", ")", "break" ]
Helper to output a disk.
[ "Helper", "to", "output", "a", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L282-L316
11,181
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_sshkey
def output_sshkey(gandi, sshkey, output_keys, justify=12): """ Helper to output an ssh key information.""" output_generic(gandi, sshkey, output_keys, justify)
python
def output_sshkey(gandi, sshkey, output_keys, justify=12): """ Helper to output an ssh key information.""" output_generic(gandi, sshkey, output_keys, justify)
[ "def", "output_sshkey", "(", "gandi", ",", "sshkey", ",", "output_keys", ",", "justify", "=", "12", ")", ":", "output_generic", "(", "gandi", ",", "sshkey", ",", "output_keys", ",", "justify", ")" ]
Helper to output an ssh key information.
[ "Helper", "to", "output", "an", "ssh", "key", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L319-L321
11,182
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_snapshot_profile
def output_snapshot_profile(gandi, profile, output_keys, justify=13): """ Helper to output a snapshot_profile.""" schedules = 'schedules' in output_keys if schedules: output_keys.remove('schedules') output_generic(gandi, profile, output_keys, justify) if schedules: schedule_keys = ['name', 'kept_version'] for schedule in profile['schedules']: gandi.separator_line() output_generic(gandi, schedule, schedule_keys, justify)
python
def output_snapshot_profile(gandi, profile, output_keys, justify=13): """ Helper to output a snapshot_profile.""" schedules = 'schedules' in output_keys if schedules: output_keys.remove('schedules') output_generic(gandi, profile, output_keys, justify) if schedules: schedule_keys = ['name', 'kept_version'] for schedule in profile['schedules']: gandi.separator_line() output_generic(gandi, schedule, schedule_keys, justify)
[ "def", "output_snapshot_profile", "(", "gandi", ",", "profile", ",", "output_keys", ",", "justify", "=", "13", ")", ":", "schedules", "=", "'schedules'", "in", "output_keys", "if", "schedules", ":", "output_keys", ".", "remove", "(", "'schedules'", ")", "output_generic", "(", "gandi", ",", "profile", ",", "output_keys", ",", "justify", ")", "if", "schedules", ":", "schedule_keys", "=", "[", "'name'", ",", "'kept_version'", "]", "for", "schedule", "in", "profile", "[", "'schedules'", "]", ":", "gandi", ".", "separator_line", "(", ")", "output_generic", "(", "gandi", ",", "schedule", ",", "schedule_keys", ",", "justify", ")" ]
Helper to output a snapshot_profile.
[ "Helper", "to", "output", "a", "snapshot_profile", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L324-L335
11,183
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_contact_info
def output_contact_info(gandi, data, output_keys, justify=10): """Helper to output chosen contacts info.""" for key in output_keys: if data[key]: output_line(gandi, key, data[key]['handle'], justify)
python
def output_contact_info(gandi, data, output_keys, justify=10): """Helper to output chosen contacts info.""" for key in output_keys: if data[key]: output_line(gandi, key, data[key]['handle'], justify)
[ "def", "output_contact_info", "(", "gandi", ",", "data", ",", "output_keys", ",", "justify", "=", "10", ")", ":", "for", "key", "in", "output_keys", ":", "if", "data", "[", "key", "]", ":", "output_line", "(", "gandi", ",", "key", ",", "data", "[", "key", "]", "[", "'handle'", "]", ",", "justify", ")" ]
Helper to output chosen contacts info.
[ "Helper", "to", "output", "chosen", "contacts", "info", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L338-L342
11,184
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_cert
def output_cert(gandi, cert, output_keys, justify=13): """Helper to output a certificate information.""" output = list(output_keys) display_altnames = False if 'altnames' in output: display_altnames = True output.remove('altnames') display_output = False if 'cert' in output: display_output = True output.remove('cert') output_generic(gandi, cert, output, justify) if display_output: crt = gandi.certificate.pretty_format_cert(cert) if crt: output_line(gandi, 'cert', '\n' + crt, justify) if display_altnames: for altname in cert['altnames']: output_line(gandi, 'altname', altname, justify)
python
def output_cert(gandi, cert, output_keys, justify=13): """Helper to output a certificate information.""" output = list(output_keys) display_altnames = False if 'altnames' in output: display_altnames = True output.remove('altnames') display_output = False if 'cert' in output: display_output = True output.remove('cert') output_generic(gandi, cert, output, justify) if display_output: crt = gandi.certificate.pretty_format_cert(cert) if crt: output_line(gandi, 'cert', '\n' + crt, justify) if display_altnames: for altname in cert['altnames']: output_line(gandi, 'altname', altname, justify)
[ "def", "output_cert", "(", "gandi", ",", "cert", ",", "output_keys", ",", "justify", "=", "13", ")", ":", "output", "=", "list", "(", "output_keys", ")", "display_altnames", "=", "False", "if", "'altnames'", "in", "output", ":", "display_altnames", "=", "True", "output", ".", "remove", "(", "'altnames'", ")", "display_output", "=", "False", "if", "'cert'", "in", "output", ":", "display_output", "=", "True", "output", ".", "remove", "(", "'cert'", ")", "output_generic", "(", "gandi", ",", "cert", ",", "output", ",", "justify", ")", "if", "display_output", ":", "crt", "=", "gandi", ".", "certificate", ".", "pretty_format_cert", "(", "cert", ")", "if", "crt", ":", "output_line", "(", "gandi", ",", "'cert'", ",", "'\\n'", "+", "crt", ",", "justify", ")", "if", "display_altnames", ":", "for", "altname", "in", "cert", "[", "'altnames'", "]", ":", "output_line", "(", "gandi", ",", "'altname'", ",", "altname", ",", "justify", ")" ]
Helper to output a certificate information.
[ "Helper", "to", "output", "a", "certificate", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L355-L378
11,185
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_vlan
def output_vlan(gandi, vlan, datacenters, output_keys, justify=10): """ Helper to output a vlan information.""" output_generic(gandi, vlan, output_keys, justify) if 'dc' in output_keys: for dc in datacenters: if dc['id'] == vlan.get('datacenter_id', vlan.get('datacenter', {}).get('id')): dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify)
python
def output_vlan(gandi, vlan, datacenters, output_keys, justify=10): """ Helper to output a vlan information.""" output_generic(gandi, vlan, output_keys, justify) if 'dc' in output_keys: for dc in datacenters: if dc['id'] == vlan.get('datacenter_id', vlan.get('datacenter', {}).get('id')): dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify)
[ "def", "output_vlan", "(", "gandi", ",", "vlan", ",", "datacenters", ",", "output_keys", ",", "justify", "=", "10", ")", ":", "output_generic", "(", "gandi", ",", "vlan", ",", "output_keys", ",", "justify", ")", "if", "'dc'", "in", "output_keys", ":", "for", "dc", "in", "datacenters", ":", "if", "dc", "[", "'id'", "]", "==", "vlan", ".", "get", "(", "'datacenter_id'", ",", "vlan", ".", "get", "(", "'datacenter'", ",", "{", "}", ")", ".", "get", "(", "'id'", ")", ")", ":", "dc_name", "=", "dc", ".", "get", "(", "'dc_code'", ",", "dc", ".", "get", "(", "'iso'", ",", "''", ")", ")", "break", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")" ]
Helper to output a vlan information.
[ "Helper", "to", "output", "a", "vlan", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L381-L392
11,186
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_iface
def output_iface(gandi, iface, datacenters, vms, output_keys, justify=10): """ Helper to output an iface information.""" output_generic(gandi, iface, output_keys, justify) if 'vm' in output_keys: vm_name = vms.get(iface['vm_id'], {}).get('hostname') if vm_name: output_line(gandi, 'vm', vm_name, justify) if 'dc' in output_keys: for dc in datacenters: if dc['id'] == iface.get('datacenter_id', iface.get('datacenter', {}).get('id')): dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify) if 'vlan_' in output_keys: vlan = iface.get('vlan') or {} output_line(gandi, 'vlan', vlan.get('name', '-'), justify)
python
def output_iface(gandi, iface, datacenters, vms, output_keys, justify=10): """ Helper to output an iface information.""" output_generic(gandi, iface, output_keys, justify) if 'vm' in output_keys: vm_name = vms.get(iface['vm_id'], {}).get('hostname') if vm_name: output_line(gandi, 'vm', vm_name, justify) if 'dc' in output_keys: for dc in datacenters: if dc['id'] == iface.get('datacenter_id', iface.get('datacenter', {}).get('id')): dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify) if 'vlan_' in output_keys: vlan = iface.get('vlan') or {} output_line(gandi, 'vlan', vlan.get('name', '-'), justify)
[ "def", "output_iface", "(", "gandi", ",", "iface", ",", "datacenters", ",", "vms", ",", "output_keys", ",", "justify", "=", "10", ")", ":", "output_generic", "(", "gandi", ",", "iface", ",", "output_keys", ",", "justify", ")", "if", "'vm'", "in", "output_keys", ":", "vm_name", "=", "vms", ".", "get", "(", "iface", "[", "'vm_id'", "]", ",", "{", "}", ")", ".", "get", "(", "'hostname'", ")", "if", "vm_name", ":", "output_line", "(", "gandi", ",", "'vm'", ",", "vm_name", ",", "justify", ")", "if", "'dc'", "in", "output_keys", ":", "for", "dc", "in", "datacenters", ":", "if", "dc", "[", "'id'", "]", "==", "iface", ".", "get", "(", "'datacenter_id'", ",", "iface", ".", "get", "(", "'datacenter'", ",", "{", "}", ")", ".", "get", "(", "'id'", ")", ")", ":", "dc_name", "=", "dc", ".", "get", "(", "'dc_code'", ",", "dc", ".", "get", "(", "'iso'", ",", "''", ")", ")", "break", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")", "if", "'vlan_'", "in", "output_keys", ":", "vlan", "=", "iface", ".", "get", "(", "'vlan'", ")", "or", "{", "}", "output_line", "(", "gandi", ",", "'vlan'", ",", "vlan", ".", "get", "(", "'name'", ",", "'-'", ")", ",", "justify", ")" ]
Helper to output an iface information.
[ "Helper", "to", "output", "an", "iface", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L395-L415
11,187
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_ip
def output_ip(gandi, ip, datacenters, vms, ifaces, output_keys, justify=11): """ Helper to output an ip information.""" output_generic(gandi, ip, output_keys, justify) if 'type' in output_keys: iface = ifaces.get(ip['iface_id']) type_ = 'private' if iface.get('vlan') else 'public' output_line(gandi, 'type', type_, justify) if type_ == 'private': output_line(gandi, 'vlan', iface['vlan']['name'], justify) if 'vm' in output_keys: iface = ifaces.get(ip['iface_id']) vm_id = iface.get('vm_id') if vm_id: vm_name = vms.get(vm_id, {}).get('hostname') if vm_name: output_line(gandi, 'vm', vm_name, justify) if 'dc' in output_keys: for dc in datacenters: if dc['id'] == ip.get('datacenter_id', ip.get('datacenter', {}).get('id')): dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify)
python
def output_ip(gandi, ip, datacenters, vms, ifaces, output_keys, justify=11): """ Helper to output an ip information.""" output_generic(gandi, ip, output_keys, justify) if 'type' in output_keys: iface = ifaces.get(ip['iface_id']) type_ = 'private' if iface.get('vlan') else 'public' output_line(gandi, 'type', type_, justify) if type_ == 'private': output_line(gandi, 'vlan', iface['vlan']['name'], justify) if 'vm' in output_keys: iface = ifaces.get(ip['iface_id']) vm_id = iface.get('vm_id') if vm_id: vm_name = vms.get(vm_id, {}).get('hostname') if vm_name: output_line(gandi, 'vm', vm_name, justify) if 'dc' in output_keys: for dc in datacenters: if dc['id'] == ip.get('datacenter_id', ip.get('datacenter', {}).get('id')): dc_name = dc.get('dc_code', dc.get('iso', '')) break output_line(gandi, 'datacenter', dc_name, justify)
[ "def", "output_ip", "(", "gandi", ",", "ip", ",", "datacenters", ",", "vms", ",", "ifaces", ",", "output_keys", ",", "justify", "=", "11", ")", ":", "output_generic", "(", "gandi", ",", "ip", ",", "output_keys", ",", "justify", ")", "if", "'type'", "in", "output_keys", ":", "iface", "=", "ifaces", ".", "get", "(", "ip", "[", "'iface_id'", "]", ")", "type_", "=", "'private'", "if", "iface", ".", "get", "(", "'vlan'", ")", "else", "'public'", "output_line", "(", "gandi", ",", "'type'", ",", "type_", ",", "justify", ")", "if", "type_", "==", "'private'", ":", "output_line", "(", "gandi", ",", "'vlan'", ",", "iface", "[", "'vlan'", "]", "[", "'name'", "]", ",", "justify", ")", "if", "'vm'", "in", "output_keys", ":", "iface", "=", "ifaces", ".", "get", "(", "ip", "[", "'iface_id'", "]", ")", "vm_id", "=", "iface", ".", "get", "(", "'vm_id'", ")", "if", "vm_id", ":", "vm_name", "=", "vms", ".", "get", "(", "vm_id", ",", "{", "}", ")", ".", "get", "(", "'hostname'", ")", "if", "vm_name", ":", "output_line", "(", "gandi", ",", "'vm'", ",", "vm_name", ",", "justify", ")", "if", "'dc'", "in", "output_keys", ":", "for", "dc", "in", "datacenters", ":", "if", "dc", "[", "'id'", "]", "==", "ip", ".", "get", "(", "'datacenter_id'", ",", "ip", ".", "get", "(", "'datacenter'", ",", "{", "}", ")", ".", "get", "(", "'id'", ")", ")", ":", "dc_name", "=", "dc", ".", "get", "(", "'dc_code'", ",", "dc", ".", "get", "(", "'iso'", ",", "''", ")", ")", "break", "output_line", "(", "gandi", ",", "'datacenter'", ",", "dc_name", ",", "justify", ")" ]
Helper to output an ip information.
[ "Helper", "to", "output", "an", "ip", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L418-L444
11,188
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_json
def output_json(gandi, format, value): """ Helper to show json output """ if format == 'json': gandi.echo(json.dumps(value, default=date_handler, sort_keys=True)) elif format == 'pretty-json': gandi.echo(json.dumps(value, default=date_handler, sort_keys=True, indent=2, separators=(',', ': ')))
python
def output_json(gandi, format, value): """ Helper to show json output """ if format == 'json': gandi.echo(json.dumps(value, default=date_handler, sort_keys=True)) elif format == 'pretty-json': gandi.echo(json.dumps(value, default=date_handler, sort_keys=True, indent=2, separators=(',', ': ')))
[ "def", "output_json", "(", "gandi", ",", "format", ",", "value", ")", ":", "if", "format", "==", "'json'", ":", "gandi", ".", "echo", "(", "json", ".", "dumps", "(", "value", ",", "default", "=", "date_handler", ",", "sort_keys", "=", "True", ")", ")", "elif", "format", "==", "'pretty-json'", ":", "gandi", ".", "echo", "(", "json", ".", "dumps", "(", "value", ",", "default", "=", "date_handler", ",", "sort_keys", "=", "True", ",", "indent", "=", "2", ",", "separators", "=", "(", "','", ",", "': '", ")", ")", ")" ]
Helper to show json output
[ "Helper", "to", "show", "json", "output" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L465-L471
11,189
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_service
def output_service(gandi, service, status, justify=10): """ Helper to output a status service information.""" output_line(gandi, service, status, justify)
python
def output_service(gandi, service, status, justify=10): """ Helper to output a status service information.""" output_line(gandi, service, status, justify)
[ "def", "output_service", "(", "gandi", ",", "service", ",", "status", ",", "justify", "=", "10", ")", ":", "output_line", "(", "gandi", ",", "service", ",", "status", ",", "justify", ")" ]
Helper to output a status service information.
[ "Helper", "to", "output", "a", "status", "service", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L487-L489
11,190
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_domain
def output_domain(gandi, domain, output_keys, justify=12): """ Helper to output a domain information.""" if 'nameservers' in domain: domain['nameservers'] = format_list(domain['nameservers']) if 'services' in domain: domain['services'] = format_list(domain['services']) if 'tags' in domain: domain['tags'] = format_list(domain['tags']) output_generic(gandi, domain, output_keys, justify) if 'created' in output_keys: output_line(gandi, 'created', domain['date_created'], justify) if 'expires' in output_keys: date_end = domain.get('date_registry_end') if date_end: days_left = (date_end - datetime.now()).days output_line(gandi, 'expires', '%s (in %d days)' % (date_end, days_left), justify) if 'updated' in output_keys: output_line(gandi, 'updated', domain['date_updated'], justify)
python
def output_domain(gandi, domain, output_keys, justify=12): """ Helper to output a domain information.""" if 'nameservers' in domain: domain['nameservers'] = format_list(domain['nameservers']) if 'services' in domain: domain['services'] = format_list(domain['services']) if 'tags' in domain: domain['tags'] = format_list(domain['tags']) output_generic(gandi, domain, output_keys, justify) if 'created' in output_keys: output_line(gandi, 'created', domain['date_created'], justify) if 'expires' in output_keys: date_end = domain.get('date_registry_end') if date_end: days_left = (date_end - datetime.now()).days output_line(gandi, 'expires', '%s (in %d days)' % (date_end, days_left), justify) if 'updated' in output_keys: output_line(gandi, 'updated', domain['date_updated'], justify)
[ "def", "output_domain", "(", "gandi", ",", "domain", ",", "output_keys", ",", "justify", "=", "12", ")", ":", "if", "'nameservers'", "in", "domain", ":", "domain", "[", "'nameservers'", "]", "=", "format_list", "(", "domain", "[", "'nameservers'", "]", ")", "if", "'services'", "in", "domain", ":", "domain", "[", "'services'", "]", "=", "format_list", "(", "domain", "[", "'services'", "]", ")", "if", "'tags'", "in", "domain", ":", "domain", "[", "'tags'", "]", "=", "format_list", "(", "domain", "[", "'tags'", "]", ")", "output_generic", "(", "gandi", ",", "domain", ",", "output_keys", ",", "justify", ")", "if", "'created'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'created'", ",", "domain", "[", "'date_created'", "]", ",", "justify", ")", "if", "'expires'", "in", "output_keys", ":", "date_end", "=", "domain", ".", "get", "(", "'date_registry_end'", ")", "if", "date_end", ":", "days_left", "=", "(", "date_end", "-", "datetime", ".", "now", "(", ")", ")", ".", "days", "output_line", "(", "gandi", ",", "'expires'", ",", "'%s (in %d days)'", "%", "(", "date_end", ",", "days_left", ")", ",", "justify", ")", "if", "'updated'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'updated'", ",", "domain", "[", "'date_updated'", "]", ",", "justify", ")" ]
Helper to output a domain information.
[ "Helper", "to", "output", "a", "domain", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L517-L542
11,191
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_mailbox
def output_mailbox(gandi, mailbox, output_keys, justify=16): """ Helper to output a mailbox information.""" quota = 'quota' in output_keys responder = 'responder' in output_keys if quota: output_keys.pop(output_keys.index('quota')) if responder: output_keys.pop(output_keys.index('responder')) if 'aliases' in output_keys: mailbox['aliases'] = sorted(mailbox['aliases']) output_generic(gandi, mailbox, output_keys, justify) if 'fallback' in output_keys: output_line(gandi, 'fallback email', mailbox['fallback_email'], justify) if quota: granted = mailbox['quota']['granted'] if mailbox['quota']['granted'] == 0: granted = 'unlimited' output_line(gandi, 'quota usage', '%s KiB / %s' % (mailbox['quota']['used'], granted), justify) if responder: responder_status = 'yes' if mailbox['responder']['active'] else 'no' output_line(gandi, 'responder active', responder_status, justify) output_line(gandi, 'responder text', mailbox['responder']['text'], justify)
python
def output_mailbox(gandi, mailbox, output_keys, justify=16): """ Helper to output a mailbox information.""" quota = 'quota' in output_keys responder = 'responder' in output_keys if quota: output_keys.pop(output_keys.index('quota')) if responder: output_keys.pop(output_keys.index('responder')) if 'aliases' in output_keys: mailbox['aliases'] = sorted(mailbox['aliases']) output_generic(gandi, mailbox, output_keys, justify) if 'fallback' in output_keys: output_line(gandi, 'fallback email', mailbox['fallback_email'], justify) if quota: granted = mailbox['quota']['granted'] if mailbox['quota']['granted'] == 0: granted = 'unlimited' output_line(gandi, 'quota usage', '%s KiB / %s' % (mailbox['quota']['used'], granted), justify) if responder: responder_status = 'yes' if mailbox['responder']['active'] else 'no' output_line(gandi, 'responder active', responder_status, justify) output_line(gandi, 'responder text', mailbox['responder']['text'], justify)
[ "def", "output_mailbox", "(", "gandi", ",", "mailbox", ",", "output_keys", ",", "justify", "=", "16", ")", ":", "quota", "=", "'quota'", "in", "output_keys", "responder", "=", "'responder'", "in", "output_keys", "if", "quota", ":", "output_keys", ".", "pop", "(", "output_keys", ".", "index", "(", "'quota'", ")", ")", "if", "responder", ":", "output_keys", ".", "pop", "(", "output_keys", ".", "index", "(", "'responder'", ")", ")", "if", "'aliases'", "in", "output_keys", ":", "mailbox", "[", "'aliases'", "]", "=", "sorted", "(", "mailbox", "[", "'aliases'", "]", ")", "output_generic", "(", "gandi", ",", "mailbox", ",", "output_keys", ",", "justify", ")", "if", "'fallback'", "in", "output_keys", ":", "output_line", "(", "gandi", ",", "'fallback email'", ",", "mailbox", "[", "'fallback_email'", "]", ",", "justify", ")", "if", "quota", ":", "granted", "=", "mailbox", "[", "'quota'", "]", "[", "'granted'", "]", "if", "mailbox", "[", "'quota'", "]", "[", "'granted'", "]", "==", "0", ":", "granted", "=", "'unlimited'", "output_line", "(", "gandi", ",", "'quota usage'", ",", "'%s KiB / %s'", "%", "(", "mailbox", "[", "'quota'", "]", "[", "'used'", "]", ",", "granted", ")", ",", "justify", ")", "if", "responder", ":", "responder_status", "=", "'yes'", "if", "mailbox", "[", "'responder'", "]", "[", "'active'", "]", "else", "'no'", "output_line", "(", "gandi", ",", "'responder active'", ",", "responder_status", ",", "justify", ")", "output_line", "(", "gandi", ",", "'responder text'", ",", "mailbox", "[", "'responder'", "]", "[", "'text'", "]", ",", "justify", ")" ]
Helper to output a mailbox information.
[ "Helper", "to", "output", "a", "mailbox", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L545-L577
11,192
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_forward
def output_forward(gandi, domain, forward, justify=14): """ Helper to output a mail forward information.""" for dest in forward['destinations']: output_line(gandi, forward['source'], dest, justify)
python
def output_forward(gandi, domain, forward, justify=14): """ Helper to output a mail forward information.""" for dest in forward['destinations']: output_line(gandi, forward['source'], dest, justify)
[ "def", "output_forward", "(", "gandi", ",", "domain", ",", "forward", ",", "justify", "=", "14", ")", ":", "for", "dest", "in", "forward", "[", "'destinations'", "]", ":", "output_line", "(", "gandi", ",", "forward", "[", "'source'", "]", ",", "dest", ",", "justify", ")" ]
Helper to output a mail forward information.
[ "Helper", "to", "output", "a", "mail", "forward", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L580-L583
11,193
Gandi/gandi.cli
gandi/cli/core/utils/__init__.py
output_dns_records
def output_dns_records(gandi, records, output_keys, justify=12): """ Helper to output a dns records information.""" for key in output_keys: real_key = 'rrset_%s' % key if real_key in records: val = records[real_key] if key == 'values': val = format_list(records[real_key]) output_line(gandi, key, val, justify)
python
def output_dns_records(gandi, records, output_keys, justify=12): """ Helper to output a dns records information.""" for key in output_keys: real_key = 'rrset_%s' % key if real_key in records: val = records[real_key] if key == 'values': val = format_list(records[real_key]) output_line(gandi, key, val, justify)
[ "def", "output_dns_records", "(", "gandi", ",", "records", ",", "output_keys", ",", "justify", "=", "12", ")", ":", "for", "key", "in", "output_keys", ":", "real_key", "=", "'rrset_%s'", "%", "key", "if", "real_key", "in", "records", ":", "val", "=", "records", "[", "real_key", "]", "if", "key", "==", "'values'", ":", "val", "=", "format_list", "(", "records", "[", "real_key", "]", ")", "output_line", "(", "gandi", ",", "key", ",", "val", ",", "justify", ")" ]
Helper to output a dns records information.
[ "Helper", "to", "output", "a", "dns", "records", "information", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/utils/__init__.py#L586-L594
11,194
Gandi/gandi.cli
gandi/cli/commands/ip.py
list
def list(gandi, datacenter, type, id, attached, detached, version, reverse, vm, vlan): """List ips.""" if attached and detached: gandi.echo("You can't set --attached and --detached at the same time.") return output_keys = ['ip', 'state', 'dc', 'type'] if id: output_keys.append('id') if version: output_keys.append('version') if vm: output_keys.append('vm') if reverse: output_keys.append('reverse') options = {} opt_dc = {} if datacenter: datacenter_id = int(gandi.datacenter.usable_id(datacenter)) options['datacenter_id'] = datacenter_id opt_dc = {'datacenter_id': datacenter_id} iface_options = {} if type: iface_options['type'] = type if vlan: iface_options['vlan'] = vlan if attached: iface_options['state'] = 'used' elif detached: iface_options['state'] = 'free' if iface_options: ifaces = gandi.iface.list(iface_options) options['iface_id'] = [iface['id'] for iface in ifaces] iface_options.update(opt_dc) datacenters = gandi.datacenter.list() ips = gandi.ip.list(options) ifaces = dict([(iface['id'], iface) for iface in gandi.iface.list(iface_options)]) vms = dict([(vm_['id'], vm_) for vm_ in gandi.iaas.list(opt_dc)]) for num, ip_ in enumerate(ips): if num: gandi.separator_line() output_ip(gandi, ip_, datacenters, vms, ifaces, output_keys) return ips
python
def list(gandi, datacenter, type, id, attached, detached, version, reverse, vm, vlan): """List ips.""" if attached and detached: gandi.echo("You can't set --attached and --detached at the same time.") return output_keys = ['ip', 'state', 'dc', 'type'] if id: output_keys.append('id') if version: output_keys.append('version') if vm: output_keys.append('vm') if reverse: output_keys.append('reverse') options = {} opt_dc = {} if datacenter: datacenter_id = int(gandi.datacenter.usable_id(datacenter)) options['datacenter_id'] = datacenter_id opt_dc = {'datacenter_id': datacenter_id} iface_options = {} if type: iface_options['type'] = type if vlan: iface_options['vlan'] = vlan if attached: iface_options['state'] = 'used' elif detached: iface_options['state'] = 'free' if iface_options: ifaces = gandi.iface.list(iface_options) options['iface_id'] = [iface['id'] for iface in ifaces] iface_options.update(opt_dc) datacenters = gandi.datacenter.list() ips = gandi.ip.list(options) ifaces = dict([(iface['id'], iface) for iface in gandi.iface.list(iface_options)]) vms = dict([(vm_['id'], vm_) for vm_ in gandi.iaas.list(opt_dc)]) for num, ip_ in enumerate(ips): if num: gandi.separator_line() output_ip(gandi, ip_, datacenters, vms, ifaces, output_keys) return ips
[ "def", "list", "(", "gandi", ",", "datacenter", ",", "type", ",", "id", ",", "attached", ",", "detached", ",", "version", ",", "reverse", ",", "vm", ",", "vlan", ")", ":", "if", "attached", "and", "detached", ":", "gandi", ".", "echo", "(", "\"You can't set --attached and --detached at the same time.\"", ")", "return", "output_keys", "=", "[", "'ip'", ",", "'state'", ",", "'dc'", ",", "'type'", "]", "if", "id", ":", "output_keys", ".", "append", "(", "'id'", ")", "if", "version", ":", "output_keys", ".", "append", "(", "'version'", ")", "if", "vm", ":", "output_keys", ".", "append", "(", "'vm'", ")", "if", "reverse", ":", "output_keys", ".", "append", "(", "'reverse'", ")", "options", "=", "{", "}", "opt_dc", "=", "{", "}", "if", "datacenter", ":", "datacenter_id", "=", "int", "(", "gandi", ".", "datacenter", ".", "usable_id", "(", "datacenter", ")", ")", "options", "[", "'datacenter_id'", "]", "=", "datacenter_id", "opt_dc", "=", "{", "'datacenter_id'", ":", "datacenter_id", "}", "iface_options", "=", "{", "}", "if", "type", ":", "iface_options", "[", "'type'", "]", "=", "type", "if", "vlan", ":", "iface_options", "[", "'vlan'", "]", "=", "vlan", "if", "attached", ":", "iface_options", "[", "'state'", "]", "=", "'used'", "elif", "detached", ":", "iface_options", "[", "'state'", "]", "=", "'free'", "if", "iface_options", ":", "ifaces", "=", "gandi", ".", "iface", ".", "list", "(", "iface_options", ")", "options", "[", "'iface_id'", "]", "=", "[", "iface", "[", "'id'", "]", "for", "iface", "in", "ifaces", "]", "iface_options", ".", "update", "(", "opt_dc", ")", "datacenters", "=", "gandi", ".", "datacenter", ".", "list", "(", ")", "ips", "=", "gandi", ".", "ip", ".", "list", "(", "options", ")", "ifaces", "=", "dict", "(", "[", "(", "iface", "[", "'id'", "]", ",", "iface", ")", "for", "iface", "in", "gandi", ".", "iface", ".", "list", "(", "iface_options", ")", "]", ")", "vms", "=", "dict", "(", "[", "(", "vm_", "[", "'id'", "]", ",", "vm_", ")", "for", "vm_", "in", "gandi", ".", "iaas", ".", "list", "(", "opt_dc", ")", "]", ")", "for", "num", ",", "ip_", "in", "enumerate", "(", "ips", ")", ":", "if", "num", ":", "gandi", ".", "separator_line", "(", ")", "output_ip", "(", "gandi", ",", "ip_", ",", "datacenters", ",", "vms", ",", "ifaces", ",", "output_keys", ")", "return", "ips" ]
List ips.
[ "List", "ips", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L33-L85
11,195
Gandi/gandi.cli
gandi/cli/commands/ip.py
info
def info(gandi, resource): """Display information about an ip. Resource can be an ip or id. """ output_keys = ['ip', 'state', 'dc', 'type', 'vm', 'reverse'] datacenters = gandi.datacenter.list() ip = gandi.ip.info(resource) iface = gandi.iface.info(ip['iface_id']) vms = None if iface.get('vm_id'): vm = gandi.iaas.info(iface['vm_id']) vms = {vm['id']: vm} output_ip(gandi, ip, datacenters, vms, {iface['id']: iface}, output_keys) return ip
python
def info(gandi, resource): """Display information about an ip. Resource can be an ip or id. """ output_keys = ['ip', 'state', 'dc', 'type', 'vm', 'reverse'] datacenters = gandi.datacenter.list() ip = gandi.ip.info(resource) iface = gandi.iface.info(ip['iface_id']) vms = None if iface.get('vm_id'): vm = gandi.iaas.info(iface['vm_id']) vms = {vm['id']: vm} output_ip(gandi, ip, datacenters, vms, {iface['id']: iface}, output_keys) return ip
[ "def", "info", "(", "gandi", ",", "resource", ")", ":", "output_keys", "=", "[", "'ip'", ",", "'state'", ",", "'dc'", ",", "'type'", ",", "'vm'", ",", "'reverse'", "]", "datacenters", "=", "gandi", ".", "datacenter", ".", "list", "(", ")", "ip", "=", "gandi", ".", "ip", ".", "info", "(", "resource", ")", "iface", "=", "gandi", ".", "iface", ".", "info", "(", "ip", "[", "'iface_id'", "]", ")", "vms", "=", "None", "if", "iface", ".", "get", "(", "'vm_id'", ")", ":", "vm", "=", "gandi", ".", "iaas", ".", "info", "(", "iface", "[", "'vm_id'", "]", ")", "vms", "=", "{", "vm", "[", "'id'", "]", ":", "vm", "}", "output_ip", "(", "gandi", ",", "ip", ",", "datacenters", ",", "vms", ",", "{", "iface", "[", "'id'", "]", ":", "iface", "}", ",", "output_keys", ")", "return", "ip" ]
Display information about an ip. Resource can be an ip or id.
[ "Display", "information", "about", "an", "ip", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L91-L110
11,196
Gandi/gandi.cli
gandi/cli/commands/ip.py
update
def update(gandi, ip, reverse, background): """Update an ip.""" if not reverse: return return gandi.ip.update(ip, {'reverse': reverse}, background)
python
def update(gandi, ip, reverse, background): """Update an ip.""" if not reverse: return return gandi.ip.update(ip, {'reverse': reverse}, background)
[ "def", "update", "(", "gandi", ",", "ip", ",", "reverse", ",", "background", ")", ":", "if", "not", "reverse", ":", "return", "return", "gandi", ".", "ip", ".", "update", "(", "ip", ",", "{", "'reverse'", ":", "reverse", "}", ",", "background", ")" ]
Update an ip.
[ "Update", "an", "ip", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L119-L123
11,197
Gandi/gandi.cli
gandi/cli/commands/ip.py
attach
def attach(gandi, ip, vm, background, force): """Attach an ip to a vm. ip can be an ip id or ip vm can be a vm id or name. """ try: ip_ = gandi.ip.info(ip) vm_ = gandi.iaas.info(vm) except UsageError: gandi.error("Can't find this ip %s" % ip) iface = gandi.iface.info(ip_['iface_id']) if iface.get('vm_id'): if vm_ and iface['vm_id'] == vm_.get('id'): gandi.echo('This ip is already attached to this vm.') return if not force: proceed = click.confirm('Are you sure you want to detach' ' %s from vm %s' % (ip_['ip'], iface['vm_id'])) if not proceed: return return gandi.ip.attach(ip, vm, background, force)
python
def attach(gandi, ip, vm, background, force): """Attach an ip to a vm. ip can be an ip id or ip vm can be a vm id or name. """ try: ip_ = gandi.ip.info(ip) vm_ = gandi.iaas.info(vm) except UsageError: gandi.error("Can't find this ip %s" % ip) iface = gandi.iface.info(ip_['iface_id']) if iface.get('vm_id'): if vm_ and iface['vm_id'] == vm_.get('id'): gandi.echo('This ip is already attached to this vm.') return if not force: proceed = click.confirm('Are you sure you want to detach' ' %s from vm %s' % (ip_['ip'], iface['vm_id'])) if not proceed: return return gandi.ip.attach(ip, vm, background, force)
[ "def", "attach", "(", "gandi", ",", "ip", ",", "vm", ",", "background", ",", "force", ")", ":", "try", ":", "ip_", "=", "gandi", ".", "ip", ".", "info", "(", "ip", ")", "vm_", "=", "gandi", ".", "iaas", ".", "info", "(", "vm", ")", "except", "UsageError", ":", "gandi", ".", "error", "(", "\"Can't find this ip %s\"", "%", "ip", ")", "iface", "=", "gandi", ".", "iface", ".", "info", "(", "ip_", "[", "'iface_id'", "]", ")", "if", "iface", ".", "get", "(", "'vm_id'", ")", ":", "if", "vm_", "and", "iface", "[", "'vm_id'", "]", "==", "vm_", ".", "get", "(", "'id'", ")", ":", "gandi", ".", "echo", "(", "'This ip is already attached to this vm.'", ")", "return", "if", "not", "force", ":", "proceed", "=", "click", ".", "confirm", "(", "'Are you sure you want to detach'", "' %s from vm %s'", "%", "(", "ip_", "[", "'ip'", "]", ",", "iface", "[", "'vm_id'", "]", ")", ")", "if", "not", "proceed", ":", "return", "return", "gandi", ".", "ip", ".", "attach", "(", "ip", ",", "vm", ",", "background", ",", "force", ")" ]
Attach an ip to a vm. ip can be an ip id or ip vm can be a vm id or name.
[ "Attach", "an", "ip", "to", "a", "vm", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L135-L160
11,198
Gandi/gandi.cli
gandi/cli/commands/ip.py
create
def create(gandi, datacenter, bandwidth, ip_version, vlan, ip, attach, background): """Create a public or private ip """ if ip_version != 4 and vlan: gandi.echo('You must have an --ip-version to 4 when having a vlan.') return if ip and not vlan: gandi.echo('You must have a --vlan when giving an --ip.') return vm_ = gandi.iaas.info(attach) if attach else None if datacenter and vm_: dc_id = gandi.datacenter.usable_id(datacenter) if dc_id != vm_['datacenter_id']: gandi.echo('The datacenter you provided does not match the ' 'datacenter of the vm you want to attach to.') return if not datacenter: datacenter = vm_['datacenter_id'] if vm_ else 'LU' try: gandi.datacenter.is_opened(datacenter, 'iaas') except DatacenterLimited as exc: gandi.echo('/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % (datacenter, exc.date)) return gandi.ip.create(ip_version, datacenter, bandwidth, attach, vlan, ip, background)
python
def create(gandi, datacenter, bandwidth, ip_version, vlan, ip, attach, background): """Create a public or private ip """ if ip_version != 4 and vlan: gandi.echo('You must have an --ip-version to 4 when having a vlan.') return if ip and not vlan: gandi.echo('You must have a --vlan when giving an --ip.') return vm_ = gandi.iaas.info(attach) if attach else None if datacenter and vm_: dc_id = gandi.datacenter.usable_id(datacenter) if dc_id != vm_['datacenter_id']: gandi.echo('The datacenter you provided does not match the ' 'datacenter of the vm you want to attach to.') return if not datacenter: datacenter = vm_['datacenter_id'] if vm_ else 'LU' try: gandi.datacenter.is_opened(datacenter, 'iaas') except DatacenterLimited as exc: gandi.echo('/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % (datacenter, exc.date)) return gandi.ip.create(ip_version, datacenter, bandwidth, attach, vlan, ip, background)
[ "def", "create", "(", "gandi", ",", "datacenter", ",", "bandwidth", ",", "ip_version", ",", "vlan", ",", "ip", ",", "attach", ",", "background", ")", ":", "if", "ip_version", "!=", "4", "and", "vlan", ":", "gandi", ".", "echo", "(", "'You must have an --ip-version to 4 when having a vlan.'", ")", "return", "if", "ip", "and", "not", "vlan", ":", "gandi", ".", "echo", "(", "'You must have a --vlan when giving an --ip.'", ")", "return", "vm_", "=", "gandi", ".", "iaas", ".", "info", "(", "attach", ")", "if", "attach", "else", "None", "if", "datacenter", "and", "vm_", ":", "dc_id", "=", "gandi", ".", "datacenter", ".", "usable_id", "(", "datacenter", ")", "if", "dc_id", "!=", "vm_", "[", "'datacenter_id'", "]", ":", "gandi", ".", "echo", "(", "'The datacenter you provided does not match the '", "'datacenter of the vm you want to attach to.'", ")", "return", "if", "not", "datacenter", ":", "datacenter", "=", "vm_", "[", "'datacenter_id'", "]", "if", "vm_", "else", "'LU'", "try", ":", "gandi", ".", "datacenter", ".", "is_opened", "(", "datacenter", ",", "'iaas'", ")", "except", "DatacenterLimited", "as", "exc", ":", "gandi", ".", "echo", "(", "'/!\\ Datacenter %s will be closed on %s, '", "'please consider using another datacenter.'", "%", "(", "datacenter", ",", "exc", ".", "date", ")", ")", "return", "gandi", ".", "ip", ".", "create", "(", "ip_version", ",", "datacenter", ",", "bandwidth", ",", "attach", ",", "vlan", ",", "ip", ",", "background", ")" ]
Create a public or private ip
[ "Create", "a", "public", "or", "private", "ip" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L177-L209
11,199
Gandi/gandi.cli
gandi/cli/commands/ip.py
detach
def detach(gandi, resource, background, force): """Detach an ip from it's currently attached vm. resource can be an ip id or ip. """ if not force: proceed = click.confirm('Are you sure you want to detach ip %s?' % resource) if not proceed: return return gandi.ip.detach(resource, background, force)
python
def detach(gandi, resource, background, force): """Detach an ip from it's currently attached vm. resource can be an ip id or ip. """ if not force: proceed = click.confirm('Are you sure you want to detach ip %s?' % resource) if not proceed: return return gandi.ip.detach(resource, background, force)
[ "def", "detach", "(", "gandi", ",", "resource", ",", "background", ",", "force", ")", ":", "if", "not", "force", ":", "proceed", "=", "click", ".", "confirm", "(", "'Are you sure you want to detach ip %s?'", "%", "resource", ")", "if", "not", "proceed", ":", "return", "return", "gandi", ".", "ip", ".", "detach", "(", "resource", ",", "background", ",", "force", ")" ]
Detach an ip from it's currently attached vm. resource can be an ip id or ip.
[ "Detach", "an", "ip", "from", "it", "s", "currently", "attached", "vm", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L220-L231