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
partition
stringclasses
1 value
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", "[",...
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
train
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
train
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
train
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
train
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...
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
train
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",...
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
train
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'", ")", "...
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
train
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", ".", "re...
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
train
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 w...
List vhosts.
[ "List", "vhosts", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/vhost.py#L22-L45
train
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_i...
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
train
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
train
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
train
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", "...
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
train
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", ...
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
train
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...
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
train
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...
Convert value to int.
[ "Convert", "value", "to", "int", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/core/params.py#L198-L202
train
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 foun...
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
train
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", "...
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
train
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 che...
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
train
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", "backgr...
Create a domain.
[ "Create", "a", "domain", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/domain.py#L30-L77
train
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
train
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'", ":", "li...
List disks.
[ "List", "disks", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L38-L85
train
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", "=", ...
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
train
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", "(", ...
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
train
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'\"", "\"...
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
train
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", ...
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
train
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", ...
Delete a disk.
[ "Delete", "a", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L240-L258
train
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'", ")", ...
Create a new disk.
[ "Create", "a", "new", "disk", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/disk.py#L280-L309
train
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", "=", "s...
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
train
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", ":",...
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
train
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", ...
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
train
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", ":", ...
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
train
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",...
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
train
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", ":", ...
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
train
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", ...
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
train
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", "(", "ke...
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
train
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", "(", "gan...
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
train
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", ":", "ou...
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
train
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", "'kerne...
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
train
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
train
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'", ")", "outpu...
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
train
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", "[", "...
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
train
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", "=", "T...
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
train
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", ":", "f...
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
train
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...
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
train
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...
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
train
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", ")", ")...
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
train
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
train
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'", "]", ")"...
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
train
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",...
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
train
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", ...
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
train
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", "=", "re...
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
train
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 ca...
List ips.
[ "List", "ips", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/ip.py#L33-L85
train
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", "=",...
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
train
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
train
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", ...
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
train
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 --...
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
train
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", ":",...
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
train
Gandi/gandi.cli
gandi/cli/commands/config.py
get
def get(gandi, g, key): """Display value of a given config key.""" val = gandi.get(key=key, global_=g) if not val: gandi.echo("No value found.") sys.exit(1) gandi.echo(val)
python
def get(gandi, g, key): """Display value of a given config key.""" val = gandi.get(key=key, global_=g) if not val: gandi.echo("No value found.") sys.exit(1) gandi.echo(val)
[ "def", "get", "(", "gandi", ",", "g", ",", "key", ")", ":", "val", "=", "gandi", ".", "get", "(", "key", "=", "key", ",", "global_", "=", "g", ")", "if", "not", "val", ":", "gandi", ".", "echo", "(", "\"No value found.\"", ")", "sys", ".", "exi...
Display value of a given config key.
[ "Display", "value", "of", "a", "given", "config", "key", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/config.py#L26-L32
train
Gandi/gandi.cli
gandi/cli/commands/config.py
edit
def edit(gandi, g): """Edit config file with prefered text editor""" config_file = gandi.home_config if g else gandi.local_config path = os.path.expanduser(config_file) editor = gandi.get('editor') if not editor: try: editor = click.prompt("Please enter the path of your prefered " "editor. eg: '/usr/bin/vi' or 'vi'") except Abort: gandi.echo(""" Warning: editor is not configured. You can use both 'gandi config set [-g] editor <value>' or the $EDITOR environment variable to configure it.""") sys.exit(1) subprocess.call([editor, path])
python
def edit(gandi, g): """Edit config file with prefered text editor""" config_file = gandi.home_config if g else gandi.local_config path = os.path.expanduser(config_file) editor = gandi.get('editor') if not editor: try: editor = click.prompt("Please enter the path of your prefered " "editor. eg: '/usr/bin/vi' or 'vi'") except Abort: gandi.echo(""" Warning: editor is not configured. You can use both 'gandi config set [-g] editor <value>' or the $EDITOR environment variable to configure it.""") sys.exit(1) subprocess.call([editor, path])
[ "def", "edit", "(", "gandi", ",", "g", ")", ":", "config_file", "=", "gandi", ".", "home_config", "if", "g", "else", "gandi", ".", "local_config", "path", "=", "os", ".", "path", ".", "expanduser", "(", "config_file", ")", "editor", "=", "gandi", ".", ...
Edit config file with prefered text editor
[ "Edit", "config", "file", "with", "prefered", "text", "editor" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/config.py#L50-L66
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.delete
def delete(cls, name): """ Delete a webaccelerator """ result = cls.call('hosting.rproxy.delete', cls.usable_id(name)) cls.echo('Deleting your webaccelerator named %s' % name) cls.display_progress(result) cls.echo('Webaccelerator have been deleted') return result
python
def delete(cls, name): """ Delete a webaccelerator """ result = cls.call('hosting.rproxy.delete', cls.usable_id(name)) cls.echo('Deleting your webaccelerator named %s' % name) cls.display_progress(result) cls.echo('Webaccelerator have been deleted') return result
[ "def", "delete", "(", "cls", ",", "name", ")", ":", "result", "=", "cls", ".", "call", "(", "'hosting.rproxy.delete'", ",", "cls", ".", "usable_id", "(", "name", ")", ")", "cls", ".", "echo", "(", "'Deleting your webaccelerator named %s'", "%", "name", ")"...
Delete a webaccelerator
[ "Delete", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L104-L110
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.backend_add
def backend_add(cls, name, backend): """ Add a backend into a webaccelerator """ oper = cls.call( 'hosting.rproxy.server.create', cls.usable_id(name), backend) cls.echo('Adding backend %s:%s into webaccelerator' % (backend['ip'], backend['port'])) cls.display_progress(oper) cls.echo('Backend added') return oper
python
def backend_add(cls, name, backend): """ Add a backend into a webaccelerator """ oper = cls.call( 'hosting.rproxy.server.create', cls.usable_id(name), backend) cls.echo('Adding backend %s:%s into webaccelerator' % (backend['ip'], backend['port'])) cls.display_progress(oper) cls.echo('Backend added') return oper
[ "def", "backend_add", "(", "cls", ",", "name", ",", "backend", ")", ":", "oper", "=", "cls", ".", "call", "(", "'hosting.rproxy.server.create'", ",", "cls", ".", "usable_id", "(", "name", ")", ",", "backend", ")", "cls", ".", "echo", "(", "'Adding backen...
Add a backend into a webaccelerator
[ "Add", "a", "backend", "into", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L118-L126
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.backend_disable
def backend_disable(cls, backend): """ Disable a backend for a server """ server = cls.backend_list(backend) oper = cls.call('hosting.rproxy.server.disable', server[0]['id']) cls.echo('Desactivating backend on server %s' % server[0]['ip']) cls.display_progress(oper) cls.echo('Backend desactivated') return oper
python
def backend_disable(cls, backend): """ Disable a backend for a server """ server = cls.backend_list(backend) oper = cls.call('hosting.rproxy.server.disable', server[0]['id']) cls.echo('Desactivating backend on server %s' % server[0]['ip']) cls.display_progress(oper) cls.echo('Backend desactivated') return oper
[ "def", "backend_disable", "(", "cls", ",", "backend", ")", ":", "server", "=", "cls", ".", "backend_list", "(", "backend", ")", "oper", "=", "cls", ".", "call", "(", "'hosting.rproxy.server.disable'", ",", "server", "[", "0", "]", "[", "'id'", "]", ")", ...
Disable a backend for a server
[ "Disable", "a", "backend", "for", "a", "server" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L156-L165
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.vhost_add
def vhost_add(cls, resource, params): """ Add a vhost into a webaccelerator """ try: oper = cls.call( 'hosting.rproxy.vhost.create', cls.usable_id(resource), params) cls.echo('Adding your virtual host (%s) into %s' % (params['vhost'], resource)) cls.display_progress(oper) cls.echo('Your virtual host habe been added') return oper except Exception as err: if err.code == 580142: dc = cls.info(resource) dns_entry = cls.call('hosting.rproxy.vhost.get_dns_entries', {'datacenter': dc['datacenter']['id'], 'vhost': params['vhost']}) txt_record = "%s 3600 IN TXT \"%s=%s\"" % (dns_entry['key'], dns_entry['key'], dns_entry['txt']) cname_record = "%s 3600 IN CNAME %s" % (dns_entry['key'], dns_entry['cname']) cls.echo('The domain don\'t use Gandi DNS or you have not' ' sufficient right to alter the zone file. ' 'Edit your zone file adding this TXT and CNAME ' 'record and try again :') cls.echo(txt_record) cls.echo(cname_record) cls.echo('\nOr add a file containing %s at :\n' 'http://%s/%s.txt\n' % (dns_entry['txt'], dns_entry['domain'], dns_entry['txt'])) else: cls.echo(err)
python
def vhost_add(cls, resource, params): """ Add a vhost into a webaccelerator """ try: oper = cls.call( 'hosting.rproxy.vhost.create', cls.usable_id(resource), params) cls.echo('Adding your virtual host (%s) into %s' % (params['vhost'], resource)) cls.display_progress(oper) cls.echo('Your virtual host habe been added') return oper except Exception as err: if err.code == 580142: dc = cls.info(resource) dns_entry = cls.call('hosting.rproxy.vhost.get_dns_entries', {'datacenter': dc['datacenter']['id'], 'vhost': params['vhost']}) txt_record = "%s 3600 IN TXT \"%s=%s\"" % (dns_entry['key'], dns_entry['key'], dns_entry['txt']) cname_record = "%s 3600 IN CNAME %s" % (dns_entry['key'], dns_entry['cname']) cls.echo('The domain don\'t use Gandi DNS or you have not' ' sufficient right to alter the zone file. ' 'Edit your zone file adding this TXT and CNAME ' 'record and try again :') cls.echo(txt_record) cls.echo(cname_record) cls.echo('\nOr add a file containing %s at :\n' 'http://%s/%s.txt\n' % (dns_entry['txt'], dns_entry['domain'], dns_entry['txt'])) else: cls.echo(err)
[ "def", "vhost_add", "(", "cls", ",", "resource", ",", "params", ")", ":", "try", ":", "oper", "=", "cls", ".", "call", "(", "'hosting.rproxy.vhost.create'", ",", "cls", ".", "usable_id", "(", "resource", ")", ",", "params", ")", "cls", ".", "echo", "("...
Add a vhost into a webaccelerator
[ "Add", "a", "vhost", "into", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L173-L208
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.vhost_remove
def vhost_remove(cls, name): """ Delete a vhost in a webaccelerator """ oper = cls.call('hosting.rproxy.vhost.delete', name) cls.echo('Deleting your virtual host %s' % name) cls.display_progress(oper) cls.echo('Your virtual host have been removed') return oper
python
def vhost_remove(cls, name): """ Delete a vhost in a webaccelerator """ oper = cls.call('hosting.rproxy.vhost.delete', name) cls.echo('Deleting your virtual host %s' % name) cls.display_progress(oper) cls.echo('Your virtual host have been removed') return oper
[ "def", "vhost_remove", "(", "cls", ",", "name", ")", ":", "oper", "=", "cls", ".", "call", "(", "'hosting.rproxy.vhost.delete'", ",", "name", ")", "cls", ".", "echo", "(", "'Deleting your virtual host %s'", "%", "name", ")", "cls", ".", "display_progress", "...
Delete a vhost in a webaccelerator
[ "Delete", "a", "vhost", "in", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L211-L217
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.probe
def probe(cls, resource, enable, disable, test, host, interval, http_method, http_response, threshold, timeout, url, window): """ Set a probe for a webaccelerator """ params = { 'host': host, 'interval': interval, 'method': http_method, 'response': http_response, 'threshold': threshold, 'timeout': timeout, 'url': url, 'window': window } if enable: params['enable'] = True elif disable: params['enable'] = False if test: result = cls.call( 'hosting.rproxy.probe.test', cls.usable_id(resource), params) else: result = cls.call( 'hosting.rproxy.probe.update', cls.usable_id(resource), params) cls.display_progress(result) return result
python
def probe(cls, resource, enable, disable, test, host, interval, http_method, http_response, threshold, timeout, url, window): """ Set a probe for a webaccelerator """ params = { 'host': host, 'interval': interval, 'method': http_method, 'response': http_response, 'threshold': threshold, 'timeout': timeout, 'url': url, 'window': window } if enable: params['enable'] = True elif disable: params['enable'] = False if test: result = cls.call( 'hosting.rproxy.probe.test', cls.usable_id(resource), params) else: result = cls.call( 'hosting.rproxy.probe.update', cls.usable_id(resource), params) cls.display_progress(result) return result
[ "def", "probe", "(", "cls", ",", "resource", ",", "enable", ",", "disable", ",", "test", ",", "host", ",", "interval", ",", "http_method", ",", "http_response", ",", "threshold", ",", "timeout", ",", "url", ",", "window", ")", ":", "params", "=", "{", ...
Set a probe for a webaccelerator
[ "Set", "a", "probe", "for", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L220-L244
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.probe_enable
def probe_enable(cls, resource): """ Activate a probe on a webaccelerator """ oper = cls.call('hosting.rproxy.probe.enable', cls.usable_id(resource)) cls.echo('Activating probe on %s' % resource) cls.display_progress(oper) cls.echo('The probe have been activated') return oper
python
def probe_enable(cls, resource): """ Activate a probe on a webaccelerator """ oper = cls.call('hosting.rproxy.probe.enable', cls.usable_id(resource)) cls.echo('Activating probe on %s' % resource) cls.display_progress(oper) cls.echo('The probe have been activated') return oper
[ "def", "probe_enable", "(", "cls", ",", "resource", ")", ":", "oper", "=", "cls", ".", "call", "(", "'hosting.rproxy.probe.enable'", ",", "cls", ".", "usable_id", "(", "resource", ")", ")", "cls", ".", "echo", "(", "'Activating probe on %s'", "%", "resource"...
Activate a probe on a webaccelerator
[ "Activate", "a", "probe", "on", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L247-L253
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.probe_disable
def probe_disable(cls, resource): """ Disable a probe on a webaccelerator """ oper = cls.call('hosting.rproxy.probe.disable', cls.usable_id(resource)) cls.echo('Desactivating probe on %s' % resource) cls.display_progress(oper) cls.echo('The probe have been desactivated') return oper
python
def probe_disable(cls, resource): """ Disable a probe on a webaccelerator """ oper = cls.call('hosting.rproxy.probe.disable', cls.usable_id(resource)) cls.echo('Desactivating probe on %s' % resource) cls.display_progress(oper) cls.echo('The probe have been desactivated') return oper
[ "def", "probe_disable", "(", "cls", ",", "resource", ")", ":", "oper", "=", "cls", ".", "call", "(", "'hosting.rproxy.probe.disable'", ",", "cls", ".", "usable_id", "(", "resource", ")", ")", "cls", ".", "echo", "(", "'Desactivating probe on %s'", "%", "reso...
Disable a probe on a webaccelerator
[ "Disable", "a", "probe", "on", "a", "webaccelerator" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L256-L263
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.usable_id
def usable_id(cls, id): """ Retrieve id from input which can be hostname, vhost, id. """ try: # id is maybe a hostname qry_id = cls.from_name(id) if not qry_id: # id is maybe an ip qry_id = cls.from_ip(id) if not qry_id: qry_id = cls.from_vhost(id) except Exception: qry_id = None if not qry_id: msg = 'unknown identifier %s' % id cls.error(msg) return qry_id
python
def usable_id(cls, id): """ Retrieve id from input which can be hostname, vhost, id. """ try: # id is maybe a hostname qry_id = cls.from_name(id) if not qry_id: # id is maybe an ip qry_id = cls.from_ip(id) if not qry_id: qry_id = cls.from_vhost(id) except Exception: qry_id = None if not qry_id: msg = 'unknown identifier %s' % id cls.error(msg) return qry_id
[ "def", "usable_id", "(", "cls", ",", "id", ")", ":", "try", ":", "# id is maybe a hostname", "qry_id", "=", "cls", ".", "from_name", "(", "id", ")", "if", "not", "qry_id", ":", "# id is maybe an ip", "qry_id", "=", "cls", ".", "from_ip", "(", "id", ")", ...
Retrieve id from input which can be hostname, vhost, id.
[ "Retrieve", "id", "from", "input", "which", "can", "be", "hostname", "vhost", "id", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L266-L283
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.from_name
def from_name(cls, name): """Retrieve webacc id associated to a webacc name.""" result = cls.list({'items_per_page': 500}) webaccs = {} for webacc in result: webaccs[webacc['name']] = webacc['id'] return webaccs.get(name)
python
def from_name(cls, name): """Retrieve webacc id associated to a webacc name.""" result = cls.list({'items_per_page': 500}) webaccs = {} for webacc in result: webaccs[webacc['name']] = webacc['id'] return webaccs.get(name)
[ "def", "from_name", "(", "cls", ",", "name", ")", ":", "result", "=", "cls", ".", "list", "(", "{", "'items_per_page'", ":", "500", "}", ")", "webaccs", "=", "{", "}", "for", "webacc", "in", "result", ":", "webaccs", "[", "webacc", "[", "'name'", "...
Retrieve webacc id associated to a webacc name.
[ "Retrieve", "webacc", "id", "associated", "to", "a", "webacc", "name", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L286-L292
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.from_ip
def from_ip(cls, ip): """Retrieve webacc id associated to a webacc ip""" result = cls.list({'items_per_page': 500}) webaccs = {} for webacc in result: for server in webacc['servers']: webaccs[server['ip']] = webacc['id'] return webaccs.get(ip)
python
def from_ip(cls, ip): """Retrieve webacc id associated to a webacc ip""" result = cls.list({'items_per_page': 500}) webaccs = {} for webacc in result: for server in webacc['servers']: webaccs[server['ip']] = webacc['id'] return webaccs.get(ip)
[ "def", "from_ip", "(", "cls", ",", "ip", ")", ":", "result", "=", "cls", ".", "list", "(", "{", "'items_per_page'", ":", "500", "}", ")", "webaccs", "=", "{", "}", "for", "webacc", "in", "result", ":", "for", "server", "in", "webacc", "[", "'server...
Retrieve webacc id associated to a webacc ip
[ "Retrieve", "webacc", "id", "associated", "to", "a", "webacc", "ip" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L295-L302
train
Gandi/gandi.cli
gandi/cli/modules/webacc.py
Webacc.from_vhost
def from_vhost(cls, vhost): """Retrieve webbacc id associated to a webacc vhost""" result = cls.list({'items_per_page': 500}) webaccs = {} for webacc in result: for vhost in webacc['vhosts']: webaccs[vhost['name']] = webacc['id'] return webaccs.get(vhost)
python
def from_vhost(cls, vhost): """Retrieve webbacc id associated to a webacc vhost""" result = cls.list({'items_per_page': 500}) webaccs = {} for webacc in result: for vhost in webacc['vhosts']: webaccs[vhost['name']] = webacc['id'] return webaccs.get(vhost)
[ "def", "from_vhost", "(", "cls", ",", "vhost", ")", ":", "result", "=", "cls", ".", "list", "(", "{", "'items_per_page'", ":", "500", "}", ")", "webaccs", "=", "{", "}", "for", "webacc", "in", "result", ":", "for", "vhost", "in", "webacc", "[", "'v...
Retrieve webbacc id associated to a webacc vhost
[ "Retrieve", "webbacc", "id", "associated", "to", "a", "webacc", "vhost" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/webacc.py#L305-L312
train
Gandi/gandi.cli
gandi/cli/modules/status.py
Status.descriptions
def descriptions(cls): """ Retrieve status descriptions from status.gandi.net. """ schema = cls.json_get('%s/status/schema' % cls.api_url, empty_key=True, send_key=False) descs = {} for val in schema['fields']['status']['value']: descs.update(val) return descs
python
def descriptions(cls): """ Retrieve status descriptions from status.gandi.net. """ schema = cls.json_get('%s/status/schema' % cls.api_url, empty_key=True, send_key=False) descs = {} for val in schema['fields']['status']['value']: descs.update(val) return descs
[ "def", "descriptions", "(", "cls", ")", ":", "schema", "=", "cls", ".", "json_get", "(", "'%s/status/schema'", "%", "cls", ".", "api_url", ",", "empty_key", "=", "True", ",", "send_key", "=", "False", ")", "descs", "=", "{", "}", "for", "val", "in", ...
Retrieve status descriptions from status.gandi.net.
[ "Retrieve", "status", "descriptions", "from", "status", ".", "gandi", ".", "net", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/status.py#L23-L30
train
Gandi/gandi.cli
gandi/cli/modules/status.py
Status.services
def services(cls): """Retrieve services statuses from status.gandi.net.""" return cls.json_get('%s/services' % cls.api_url, empty_key=True, send_key=False)
python
def services(cls): """Retrieve services statuses from status.gandi.net.""" return cls.json_get('%s/services' % cls.api_url, empty_key=True, send_key=False)
[ "def", "services", "(", "cls", ")", ":", "return", "cls", ".", "json_get", "(", "'%s/services'", "%", "cls", ".", "api_url", ",", "empty_key", "=", "True", ",", "send_key", "=", "False", ")" ]
Retrieve services statuses from status.gandi.net.
[ "Retrieve", "services", "statuses", "from", "status", ".", "gandi", ".", "net", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/status.py#L33-L36
train
Gandi/gandi.cli
gandi/cli/modules/status.py
Status.status
def status(cls): """Retrieve global status from status.gandi.net.""" return cls.json_get('%s/status' % cls.api_url, empty_key=True, send_key=False)
python
def status(cls): """Retrieve global status from status.gandi.net.""" return cls.json_get('%s/status' % cls.api_url, empty_key=True, send_key=False)
[ "def", "status", "(", "cls", ")", ":", "return", "cls", ".", "json_get", "(", "'%s/status'", "%", "cls", ".", "api_url", ",", "empty_key", "=", "True", ",", "send_key", "=", "False", ")" ]
Retrieve global status from status.gandi.net.
[ "Retrieve", "global", "status", "from", "status", ".", "gandi", ".", "net", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/status.py#L39-L42
train
Gandi/gandi.cli
gandi/cli/modules/status.py
Status.events
def events(cls, filters): """Retrieve events details from status.gandi.net.""" current = filters.pop('current', False) current_params = [] if current: current_params = [('current', 'true')] filter_url = uparse.urlencode(sorted(list(filters.items())) + current_params) # noqa events = cls.json_get('%s/events?%s' % (cls.api_url, filter_url), empty_key=True, send_key=False) return events
python
def events(cls, filters): """Retrieve events details from status.gandi.net.""" current = filters.pop('current', False) current_params = [] if current: current_params = [('current', 'true')] filter_url = uparse.urlencode(sorted(list(filters.items())) + current_params) # noqa events = cls.json_get('%s/events?%s' % (cls.api_url, filter_url), empty_key=True, send_key=False) return events
[ "def", "events", "(", "cls", ",", "filters", ")", ":", "current", "=", "filters", ".", "pop", "(", "'current'", ",", "False", ")", "current_params", "=", "[", "]", "if", "current", ":", "current_params", "=", "[", "(", "'current'", ",", "'true'", ")", ...
Retrieve events details from status.gandi.net.
[ "Retrieve", "events", "details", "from", "status", ".", "gandi", ".", "net", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/status.py#L45-L55
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
list
def list(gandi, state, id, vhosts, type, limit): """List PaaS instances.""" options = { 'items_per_page': limit, } if state: options['state'] = state output_keys = ['name', 'state'] if id: output_keys.append('id') if vhosts: output_keys.append('vhost') if type: output_keys.append('type') paas_hosts = {} result = gandi.paas.list(options) for num, paas in enumerate(result): paas_hosts[paas['id']] = [] if vhosts: list_vhost = gandi.vhost.list({'paas_id': paas['id']}) for host in list_vhost: paas_hosts[paas['id']].append(host['name']) if num: gandi.separator_line() output_paas(gandi, paas, [], paas_hosts[paas['id']], output_keys) return result
python
def list(gandi, state, id, vhosts, type, limit): """List PaaS instances.""" options = { 'items_per_page': limit, } if state: options['state'] = state output_keys = ['name', 'state'] if id: output_keys.append('id') if vhosts: output_keys.append('vhost') if type: output_keys.append('type') paas_hosts = {} result = gandi.paas.list(options) for num, paas in enumerate(result): paas_hosts[paas['id']] = [] if vhosts: list_vhost = gandi.vhost.list({'paas_id': paas['id']}) for host in list_vhost: paas_hosts[paas['id']].append(host['name']) if num: gandi.separator_line() output_paas(gandi, paas, [], paas_hosts[paas['id']], output_keys) return result
[ "def", "list", "(", "gandi", ",", "state", ",", "id", ",", "vhosts", ",", "type", ",", "limit", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", ",", "}", "if", "state", ":", "options", "[", "'state'", "]", "=", "state", "output_keys"...
List PaaS instances.
[ "List", "PaaS", "instances", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L30-L60
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
info
def info(gandi, resource, stat): """Display information about a PaaS instance. Resource can be a vhost, a hostname, or an ID Cache statistics are based on 24 hours data. """ output_keys = ['name', 'type', 'size', 'memory', 'console', 'vhost', 'dc', 'sftp_server', 'git_server', 'snapshot'] paas = gandi.paas.info(resource) paas_hosts = [] list_vhost = gandi.vhost.list({'paas_id': paas['id']}) df = gandi.paas.quota(paas['id']) paas.update({'df': df}) if stat: cache = gandi.paas.cache(paas['id']) paas.update({'cache': cache}) for host in list_vhost: paas_hosts.append(host['name']) output_paas(gandi, paas, [], paas_hosts, output_keys) return paas
python
def info(gandi, resource, stat): """Display information about a PaaS instance. Resource can be a vhost, a hostname, or an ID Cache statistics are based on 24 hours data. """ output_keys = ['name', 'type', 'size', 'memory', 'console', 'vhost', 'dc', 'sftp_server', 'git_server', 'snapshot'] paas = gandi.paas.info(resource) paas_hosts = [] list_vhost = gandi.vhost.list({'paas_id': paas['id']}) df = gandi.paas.quota(paas['id']) paas.update({'df': df}) if stat: cache = gandi.paas.cache(paas['id']) paas.update({'cache': cache}) for host in list_vhost: paas_hosts.append(host['name']) output_paas(gandi, paas, [], paas_hosts, output_keys) return paas
[ "def", "info", "(", "gandi", ",", "resource", ",", "stat", ")", ":", "output_keys", "=", "[", "'name'", ",", "'type'", ",", "'size'", ",", "'memory'", ",", "'console'", ",", "'vhost'", ",", "'dc'", ",", "'sftp_server'", ",", "'git_server'", ",", "'snapsh...
Display information about a PaaS instance. Resource can be a vhost, a hostname, or an ID Cache statistics are based on 24 hours data.
[ "Display", "information", "about", "a", "PaaS", "instance", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L68-L93
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
clone
def clone(gandi, name, vhost, directory, origin): """Clone a remote vhost in a local git repository.""" if vhost != 'default': directory = vhost else: directory = name if not directory else directory return gandi.paas.clone(name, vhost, directory, origin)
python
def clone(gandi, name, vhost, directory, origin): """Clone a remote vhost in a local git repository.""" if vhost != 'default': directory = vhost else: directory = name if not directory else directory return gandi.paas.clone(name, vhost, directory, origin)
[ "def", "clone", "(", "gandi", ",", "name", ",", "vhost", ",", "directory", ",", "origin", ")", ":", "if", "vhost", "!=", "'default'", ":", "directory", "=", "vhost", "else", ":", "directory", "=", "name", "if", "not", "directory", "else", "directory", ...
Clone a remote vhost in a local git repository.
[ "Clone", "a", "remote", "vhost", "in", "a", "local", "git", "repository", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L102-L109
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
attach
def attach(gandi, name, vhost, remote): """Add remote for an instance's default vhost to the local git repository. """ return gandi.paas.attach(name, vhost, remote)
python
def attach(gandi, name, vhost, remote): """Add remote for an instance's default vhost to the local git repository. """ return gandi.paas.attach(name, vhost, remote)
[ "def", "attach", "(", "gandi", ",", "name", ",", "vhost", ",", "remote", ")", ":", "return", "gandi", ".", "paas", ".", "attach", "(", "name", ",", "vhost", ",", "remote", ")" ]
Add remote for an instance's default vhost to the local git repository.
[ "Add", "remote", "for", "an", "instance", "s", "default", "vhost", "to", "the", "local", "git", "repository", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L119-L122
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
create
def create(gandi, name, size, type, quantity, duration, datacenter, vhosts, password, snapshotprofile, background, sshkey, ssl, private_key, poll_cert): """Create a new PaaS instance and initialize associated git repository. you can specify a configuration entry named 'sshkey' containing path to your sshkey file $ gandi config set [-g] sshkey ~/.ssh/id_rsa.pub or getting the sshkey "my_key" from your gandi ssh keyring $ gandi config set [-g] sshkey my_key to know which PaaS instance type to use as type $ gandi paas types """ try: gandi.datacenter.is_opened(datacenter, 'paas') except DatacenterLimited as exc: gandi.echo('/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % (datacenter, exc.date)) if not password: password = click.prompt('password', hide_input=True, confirmation_prompt=True) if not name: name = randomstring('paas') if vhosts and not gandi.hostedcert.activate_ssl(vhosts, ssl, private_key, poll_cert): return result = gandi.paas.create(name, size, type, quantity, duration, datacenter, vhosts, password, snapshotprofile, background, sshkey) return result
python
def create(gandi, name, size, type, quantity, duration, datacenter, vhosts, password, snapshotprofile, background, sshkey, ssl, private_key, poll_cert): """Create a new PaaS instance and initialize associated git repository. you can specify a configuration entry named 'sshkey' containing path to your sshkey file $ gandi config set [-g] sshkey ~/.ssh/id_rsa.pub or getting the sshkey "my_key" from your gandi ssh keyring $ gandi config set [-g] sshkey my_key to know which PaaS instance type to use as type $ gandi paas types """ try: gandi.datacenter.is_opened(datacenter, 'paas') except DatacenterLimited as exc: gandi.echo('/!\ Datacenter %s will be closed on %s, ' 'please consider using another datacenter.' % (datacenter, exc.date)) if not password: password = click.prompt('password', hide_input=True, confirmation_prompt=True) if not name: name = randomstring('paas') if vhosts and not gandi.hostedcert.activate_ssl(vhosts, ssl, private_key, poll_cert): return result = gandi.paas.create(name, size, type, quantity, duration, datacenter, vhosts, password, snapshotprofile, background, sshkey) return result
[ "def", "create", "(", "gandi", ",", "name", ",", "size", ",", "type", ",", "quantity", ",", "duration", ",", "datacenter", ",", "vhosts", ",", "password", ",", "snapshotprofile", ",", "background", ",", "sshkey", ",", "ssl", ",", "private_key", ",", "pol...
Create a new PaaS instance and initialize associated git repository. you can specify a configuration entry named 'sshkey' containing path to your sshkey file $ gandi config set [-g] sshkey ~/.ssh/id_rsa.pub or getting the sshkey "my_key" from your gandi ssh keyring $ gandi config set [-g] sshkey my_key to know which PaaS instance type to use as type $ gandi paas types
[ "Create", "a", "new", "PaaS", "instance", "and", "initialize", "associated", "git", "repository", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L207-L249
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
restart
def restart(gandi, resource, background, force): """Restart a PaaS instance. Resource can be a vhost, a hostname, or an ID """ output_keys = ['id', 'type', 'step'] possible_resources = gandi.paas.resource_list() for item in resource: if item not in possible_resources: gandi.echo('Sorry PaaS instance %s does not exist' % item) gandi.echo('Please use one of the following: %s' % possible_resources) return if not force: instance_info = "'%s'" % ', '.join(resource) proceed = click.confirm("Are you sure to restart PaaS instance %s?" % instance_info) if not proceed: return opers = gandi.paas.restart(resource, background) if background: for oper in opers: output_generic(gandi, oper, output_keys) return opers
python
def restart(gandi, resource, background, force): """Restart a PaaS instance. Resource can be a vhost, a hostname, or an ID """ output_keys = ['id', 'type', 'step'] possible_resources = gandi.paas.resource_list() for item in resource: if item not in possible_resources: gandi.echo('Sorry PaaS instance %s does not exist' % item) gandi.echo('Please use one of the following: %s' % possible_resources) return if not force: instance_info = "'%s'" % ', '.join(resource) proceed = click.confirm("Are you sure to restart PaaS instance %s?" % instance_info) if not proceed: return opers = gandi.paas.restart(resource, background) if background: for oper in opers: output_generic(gandi, oper, output_keys) return opers
[ "def", "restart", "(", "gandi", ",", "resource", ",", "background", ",", "force", ")", ":", "output_keys", "=", "[", "'id'", ",", "'type'", ",", "'step'", "]", "possible_resources", "=", "gandi", ".", "paas", ".", "resource_list", "(", ")", "for", "item"...
Restart a PaaS instance. Resource can be a vhost, a hostname, or an ID
[ "Restart", "a", "PaaS", "instance", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L315-L343
train
Gandi/gandi.cli
gandi/cli/commands/paas.py
types
def types(gandi): """List types PaaS instances.""" options = {} types = gandi.paas.type_list(options) for type_ in types: gandi.echo(type_['name']) return types
python
def types(gandi): """List types PaaS instances.""" options = {} types = gandi.paas.type_list(options) for type_ in types: gandi.echo(type_['name']) return types
[ "def", "types", "(", "gandi", ")", ":", "options", "=", "{", "}", "types", "=", "gandi", ".", "paas", ".", "type_list", "(", "options", ")", "for", "type_", "in", "types", ":", "gandi", ".", "echo", "(", "type_", "[", "'name'", "]", ")", "return", ...
List types PaaS instances.
[ "List", "types", "PaaS", "instances", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/paas.py#L348-L355
train
Gandi/gandi.cli
gandi/cli/commands/sshkey.py
info
def info(gandi, resource, id, value): """Display information about an SSH key. Resource can be a name or an ID """ output_keys = ['name', 'fingerprint'] if id: output_keys.append('id') if value: output_keys.append('value') ret = [] for item in resource: sshkey = gandi.sshkey.info(item) ret.append(output_sshkey(gandi, sshkey, output_keys)) return ret
python
def info(gandi, resource, id, value): """Display information about an SSH key. Resource can be a name or an ID """ output_keys = ['name', 'fingerprint'] if id: output_keys.append('id') if value: output_keys.append('value') ret = [] for item in resource: sshkey = gandi.sshkey.info(item) ret.append(output_sshkey(gandi, sshkey, output_keys)) return ret
[ "def", "info", "(", "gandi", ",", "resource", ",", "id", ",", "value", ")", ":", "output_keys", "=", "[", "'name'", ",", "'fingerprint'", "]", "if", "id", ":", "output_keys", ".", "append", "(", "'id'", ")", "if", "value", ":", "output_keys", ".", "a...
Display information about an SSH key. Resource can be a name or an ID
[ "Display", "information", "about", "an", "SSH", "key", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/sshkey.py#L47-L64
train
Gandi/gandi.cli
gandi/cli/commands/sshkey.py
create
def create(gandi, name, value=None, filename=None): """ Create a new SSH key. """ if not value and not filename: raise UsageError('You must set value OR filename.') if value and filename: raise UsageError('You must not set value AND filename.') if filename: value = filename.read() ret = gandi.sshkey.create(name, value) output_keys = ['id', 'name', 'fingerprint'] return output_sshkey(gandi, ret, output_keys)
python
def create(gandi, name, value=None, filename=None): """ Create a new SSH key. """ if not value and not filename: raise UsageError('You must set value OR filename.') if value and filename: raise UsageError('You must not set value AND filename.') if filename: value = filename.read() ret = gandi.sshkey.create(name, value) output_keys = ['id', 'name', 'fingerprint'] return output_sshkey(gandi, ret, output_keys)
[ "def", "create", "(", "gandi", ",", "name", ",", "value", "=", "None", ",", "filename", "=", "None", ")", ":", "if", "not", "value", "and", "not", "filename", ":", "raise", "UsageError", "(", "'You must set value OR filename.'", ")", "if", "value", "and", ...
Create a new SSH key.
[ "Create", "a", "new", "SSH", "key", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/sshkey.py#L72-L86
train
Gandi/gandi.cli
gandi/cli/modules/account.py
Account.creditusage
def creditusage(cls): """Get credit usage per hour""" rating = cls.call('hosting.rating.list') if not rating: return 0 rating = rating.pop() usage = [sum(resource.values()) for resource in rating.values() if isinstance(resource, dict)] return sum(usage)
python
def creditusage(cls): """Get credit usage per hour""" rating = cls.call('hosting.rating.list') if not rating: return 0 rating = rating.pop() usage = [sum(resource.values()) for resource in rating.values() if isinstance(resource, dict)] return sum(usage)
[ "def", "creditusage", "(", "cls", ")", ":", "rating", "=", "cls", ".", "call", "(", "'hosting.rating.list'", ")", "if", "not", "rating", ":", "return", "0", "rating", "=", "rating", ".", "pop", "(", ")", "usage", "=", "[", "sum", "(", "resource", "."...
Get credit usage per hour
[ "Get", "credit", "usage", "per", "hour" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/account.py#L20-L30
train
Gandi/gandi.cli
gandi/cli/modules/account.py
Account.all
def all(cls): """ Get all informations about this account """ account = cls.info() creditusage = cls.creditusage() if not creditusage: return account left = account['credits'] / creditusage years, hours = divmod(left, 365 * 24) months, hours = divmod(hours, 31 * 24) days, hours = divmod(hours, 24) account.update({'credit_usage': creditusage, 'left': (years, months, days, hours)}) return account
python
def all(cls): """ Get all informations about this account """ account = cls.info() creditusage = cls.creditusage() if not creditusage: return account left = account['credits'] / creditusage years, hours = divmod(left, 365 * 24) months, hours = divmod(hours, 31 * 24) days, hours = divmod(hours, 24) account.update({'credit_usage': creditusage, 'left': (years, months, days, hours)}) return account
[ "def", "all", "(", "cls", ")", ":", "account", "=", "cls", ".", "info", "(", ")", "creditusage", "=", "cls", ".", "creditusage", "(", ")", "if", "not", "creditusage", ":", "return", "account", "left", "=", "account", "[", "'credits'", "]", "/", "cred...
Get all informations about this account
[ "Get", "all", "informations", "about", "this", "account" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/modules/account.py#L33-L49
train
Gandi/gandi.cli
gandi/cli/commands/snapshotprofile.py
list
def list(gandi, only_paas, only_vm): """ List snapshot profiles. """ target = None if only_paas and not only_vm: target = 'paas' if only_vm and not only_paas: target = 'vm' output_keys = ['id', 'name', 'kept_total', 'target'] result = gandi.snapshotprofile.list({}, target=target) for num, profile in enumerate(result): if num: gandi.separator_line() output_snapshot_profile(gandi, profile, output_keys) return result
python
def list(gandi, only_paas, only_vm): """ List snapshot profiles. """ target = None if only_paas and not only_vm: target = 'paas' if only_vm and not only_paas: target = 'vm' output_keys = ['id', 'name', 'kept_total', 'target'] result = gandi.snapshotprofile.list({}, target=target) for num, profile in enumerate(result): if num: gandi.separator_line() output_snapshot_profile(gandi, profile, output_keys) return result
[ "def", "list", "(", "gandi", ",", "only_paas", ",", "only_vm", ")", ":", "target", "=", "None", "if", "only_paas", "and", "not", "only_vm", ":", "target", "=", "'paas'", "if", "only_vm", "and", "not", "only_paas", ":", "target", "=", "'vm'", "output_keys...
List snapshot profiles.
[ "List", "snapshot", "profiles", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/snapshotprofile.py#L20-L36
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
list
def list(gandi, id, altnames, csr, cert, all_status, status, dates, limit): """ List certificates. """ options = {'items_per_page': limit} if not all_status: options['status'] = ['valid', 'pending'] output_keys = ['cn', 'plan'] if id: output_keys.append('id') if status: output_keys.append('status') if dates: output_keys.extend(['date_created', 'date_end']) if altnames: output_keys.append('altnames') if csr: output_keys.append('csr') if cert: output_keys.append('cert') result = gandi.certificate.list(options) for num, cert in enumerate(result): if num: gandi.separator_line() cert['plan'] = package_desc(gandi, cert['package']) output_cert(gandi, cert, output_keys) return result
python
def list(gandi, id, altnames, csr, cert, all_status, status, dates, limit): """ List certificates. """ options = {'items_per_page': limit} if not all_status: options['status'] = ['valid', 'pending'] output_keys = ['cn', 'plan'] if id: output_keys.append('id') if status: output_keys.append('status') if dates: output_keys.extend(['date_created', 'date_end']) if altnames: output_keys.append('altnames') if csr: output_keys.append('csr') if cert: output_keys.append('cert') result = gandi.certificate.list(options) for num, cert in enumerate(result): if num: gandi.separator_line() cert['plan'] = package_desc(gandi, cert['package']) output_cert(gandi, cert, output_keys) return result
[ "def", "list", "(", "gandi", ",", "id", ",", "altnames", ",", "csr", ",", "cert", ",", "all_status", ",", "status", ",", "dates", ",", "limit", ")", ":", "options", "=", "{", "'items_per_page'", ":", "limit", "}", "if", "not", "all_status", ":", "opt...
List certificates.
[ "List", "certificates", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L114-L148
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
info
def info(gandi, resource, id, altnames, csr, cert, all_status): """ Display information about a certificate. Resource can be a CN or an ID """ output_keys = ['cn', 'date_created', 'date_end', 'plan', 'status'] if id: output_keys.append('id') if altnames: output_keys.append('altnames') if csr: output_keys.append('csr') if cert: output_keys.append('cert') ids = [] for res in resource: ids.extend(gandi.certificate.usable_ids(res)) result = [] for num, id_ in enumerate(set(ids)): cert = gandi.certificate.info(id_) if not all_status and cert['status'] not in ['valid', 'pending']: continue if num: gandi.separator_line() cert['plan'] = package_desc(gandi, cert['package']) output_cert(gandi, cert, output_keys) result.append(cert) return result
python
def info(gandi, resource, id, altnames, csr, cert, all_status): """ Display information about a certificate. Resource can be a CN or an ID """ output_keys = ['cn', 'date_created', 'date_end', 'plan', 'status'] if id: output_keys.append('id') if altnames: output_keys.append('altnames') if csr: output_keys.append('csr') if cert: output_keys.append('cert') ids = [] for res in resource: ids.extend(gandi.certificate.usable_ids(res)) result = [] for num, id_ in enumerate(set(ids)): cert = gandi.certificate.info(id_) if not all_status and cert['status'] not in ['valid', 'pending']: continue if num: gandi.separator_line() cert['plan'] = package_desc(gandi, cert['package']) output_cert(gandi, cert, output_keys) result.append(cert) return result
[ "def", "info", "(", "gandi", ",", "resource", ",", "id", ",", "altnames", ",", "csr", ",", "cert", ",", "all_status", ")", ":", "output_keys", "=", "[", "'cn'", ",", "'date_created'", ",", "'date_end'", ",", "'plan'", ",", "'status'", "]", "if", "id", ...
Display information about a certificate. Resource can be a CN or an ID
[ "Display", "information", "about", "a", "certificate", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L159-L193
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
update
def update(gandi, resource, csr, private_key, country, state, city, organisation, branch, altnames, dcv_method): """ Update a certificate CSR. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not update, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return id_ = ids[0] result = gandi.certificate.update(id_, csr, private_key, country, state, city, organisation, branch, altnames, dcv_method) gandi.echo('The certificate update operation is %s' % result['id']) gandi.echo('You can follow it with:') gandi.echo('$ gandi certificate follow %s' % result['id']) gandi.echo('When the operation is DONE, you can retrieve the .crt' ' with:') gandi.echo('$ gandi certificate export "%s"' % resource) return result
python
def update(gandi, resource, csr, private_key, country, state, city, organisation, branch, altnames, dcv_method): """ Update a certificate CSR. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not update, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return id_ = ids[0] result = gandi.certificate.update(id_, csr, private_key, country, state, city, organisation, branch, altnames, dcv_method) gandi.echo('The certificate update operation is %s' % result['id']) gandi.echo('You can follow it with:') gandi.echo('$ gandi certificate follow %s' % result['id']) gandi.echo('When the operation is DONE, you can retrieve the .crt' ' with:') gandi.echo('$ gandi certificate export "%s"' % resource) return result
[ "def", "update", "(", "gandi", ",", "resource", ",", "csr", ",", "private_key", ",", "country", ",", "state", ",", "city", ",", "organisation", ",", "branch", ",", "altnames", ",", "dcv_method", ")", ":", "ids", "=", "gandi", ".", "certificate", ".", "...
Update a certificate CSR. Resource can be a CN or an ID
[ "Update", "a", "certificate", "CSR", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L389-L416
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
follow
def follow(gandi, resource): """ Get the operation status Resource is an operation ID """ oper = gandi.oper.info(int(resource)) assert(oper['type'].startswith('certificate_')) output_cert_oper(gandi, oper) return oper
python
def follow(gandi, resource): """ Get the operation status Resource is an operation ID """ oper = gandi.oper.info(int(resource)) assert(oper['type'].startswith('certificate_')) output_cert_oper(gandi, oper) return oper
[ "def", "follow", "(", "gandi", ",", "resource", ")", ":", "oper", "=", "gandi", ".", "oper", ".", "info", "(", "int", "(", "resource", ")", ")", "assert", "(", "oper", "[", "'type'", "]", ".", "startswith", "(", "'certificate_'", ")", ")", "output_ce...
Get the operation status Resource is an operation ID
[ "Get", "the", "operation", "status" ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L422-L430
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
change_dcv
def change_dcv(gandi, resource, dcv_method): """ Change the DCV for a running certificate operation. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not update, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return id_ = ids[0] opers = gandi.oper.list({'cert_id': id_}) if not opers: gandi.echo('Can not find any operation for this certificate.') return oper = opers[0] if (oper['step'] != 'RUN' and oper['params']['inner_step'] != 'comodo_oper_updated'): gandi.echo('This certificate operation is not in the good step to ' 'update the DCV method.') return gandi.certificate.change_dcv(oper['id'], dcv_method) cert = gandi.certificate.info(id_) csr = oper['params']['csr'] package = cert['package'] altnames = oper['params'].get('altnames') gandi.certificate.advice_dcv_method(csr, package, altnames, dcv_method, cert_id=id_)
python
def change_dcv(gandi, resource, dcv_method): """ Change the DCV for a running certificate operation. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not update, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return id_ = ids[0] opers = gandi.oper.list({'cert_id': id_}) if not opers: gandi.echo('Can not find any operation for this certificate.') return oper = opers[0] if (oper['step'] != 'RUN' and oper['params']['inner_step'] != 'comodo_oper_updated'): gandi.echo('This certificate operation is not in the good step to ' 'update the DCV method.') return gandi.certificate.change_dcv(oper['id'], dcv_method) cert = gandi.certificate.info(id_) csr = oper['params']['csr'] package = cert['package'] altnames = oper['params'].get('altnames') gandi.certificate.advice_dcv_method(csr, package, altnames, dcv_method, cert_id=id_)
[ "def", "change_dcv", "(", "gandi", ",", "resource", ",", "dcv_method", ")", ":", "ids", "=", "gandi", ".", "certificate", ".", "usable_ids", "(", "resource", ")", "if", "len", "(", "ids", ")", ">", "1", ":", "gandi", ".", "echo", "(", "'Will not update...
Change the DCV for a running certificate operation. Resource can be a CN or an ID
[ "Change", "the", "DCV", "for", "a", "running", "certificate", "operation", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L438-L472
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
resend_dcv
def resend_dcv(gandi, resource): """ Resend the DCV mail. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not update, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return id_ = ids[0] opers = gandi.oper.list({'cert_id': id_}) if not opers: gandi.echo('Can not find any operation for this certificate.') return oper = opers[0] if (oper['step'] != 'RUN' and oper['params']['inner_step'] != 'comodo_oper_updated'): gandi.echo('This certificate operation is not in the good step to ' 'resend the DCV.') return if oper['params']['dcv_method'] != 'email': gandi.echo('This certificate operation is not in email DCV.') return gandi.certificate.resend_dcv(oper['id'])
python
def resend_dcv(gandi, resource): """ Resend the DCV mail. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not update, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return id_ = ids[0] opers = gandi.oper.list({'cert_id': id_}) if not opers: gandi.echo('Can not find any operation for this certificate.') return oper = opers[0] if (oper['step'] != 'RUN' and oper['params']['inner_step'] != 'comodo_oper_updated'): gandi.echo('This certificate operation is not in the good step to ' 'resend the DCV.') return if oper['params']['dcv_method'] != 'email': gandi.echo('This certificate operation is not in email DCV.') return gandi.certificate.resend_dcv(oper['id'])
[ "def", "resend_dcv", "(", "gandi", ",", "resource", ")", ":", "ids", "=", "gandi", ".", "certificate", ".", "usable_ids", "(", "resource", ")", "if", "len", "(", "ids", ")", ">", "1", ":", "gandi", ".", "echo", "(", "'Will not update, %s is not precise eno...
Resend the DCV mail. Resource can be a CN or an ID
[ "Resend", "the", "DCV", "mail", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L478-L509
train
Gandi/gandi.cli
gandi/cli/commands/certificate.py
delete
def delete(gandi, resource, background, force): """ Revoke the certificate. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not delete, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return if not force: proceed = click.confirm("Are you sure to delete the certificate %s?" % resource) if not proceed: return result = gandi.certificate.delete(ids[0], background) return result
python
def delete(gandi, resource, background, force): """ Revoke the certificate. Resource can be a CN or an ID """ ids = gandi.certificate.usable_ids(resource) if len(ids) > 1: gandi.echo('Will not delete, %s is not precise enough.' % resource) gandi.echo(' * cert : ' + '\n * cert : '.join([str(id_) for id_ in ids])) return if not force: proceed = click.confirm("Are you sure to delete the certificate %s?" % resource) if not proceed: return result = gandi.certificate.delete(ids[0], background) return result
[ "def", "delete", "(", "gandi", ",", "resource", ",", "background", ",", "force", ")", ":", "ids", "=", "gandi", ".", "certificate", ".", "usable_ids", "(", "resource", ")", "if", "len", "(", "ids", ")", ">", "1", ":", "gandi", ".", "echo", "(", "'W...
Revoke the certificate. Resource can be a CN or an ID
[ "Revoke", "the", "certificate", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certificate.py#L520-L540
train
Gandi/gandi.cli
gandi/cli/commands/certstore.py
list
def list(gandi, id, vhosts, dates, fqdns, limit): """ List hosted certificates. """ justify = 10 options = {'items_per_page': limit, 'state': 'created'} output_keys = [] if id: output_keys.append('id') output_keys.append('subject') if dates: output_keys.extend(['date_created', 'date_expire']) justify = 12 if fqdns: output_keys.append('fqdns') if vhosts: output_keys.append('vhosts') result = gandi.hostedcert.list(options) for num, hcert in enumerate(result): if num: gandi.separator_line() if fqdns or vhosts: hcert = gandi.hostedcert.info(hcert['id']) output_hostedcert(gandi, hcert, output_keys, justify) return result
python
def list(gandi, id, vhosts, dates, fqdns, limit): """ List hosted certificates. """ justify = 10 options = {'items_per_page': limit, 'state': 'created'} output_keys = [] if id: output_keys.append('id') output_keys.append('subject') if dates: output_keys.extend(['date_created', 'date_expire']) justify = 12 if fqdns: output_keys.append('fqdns') if vhosts: output_keys.append('vhosts') result = gandi.hostedcert.list(options) for num, hcert in enumerate(result): if num: gandi.separator_line() if fqdns or vhosts: hcert = gandi.hostedcert.info(hcert['id']) output_hostedcert(gandi, hcert, output_keys, justify) return result
[ "def", "list", "(", "gandi", ",", "id", ",", "vhosts", ",", "dates", ",", "fqdns", ",", "limit", ")", ":", "justify", "=", "10", "options", "=", "{", "'items_per_page'", ":", "limit", ",", "'state'", ":", "'created'", "}", "output_keys", "=", "[", "]...
List hosted certificates.
[ "List", "hosted", "certificates", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certstore.py#L33-L66
train
Gandi/gandi.cli
gandi/cli/commands/certstore.py
info
def info(gandi, resource): """ Display information about a hosted certificate. Resource can be a FQDN or an ID """ output_keys = ['id', 'subject', 'date_created', 'date_expire', 'fqdns', 'vhosts'] result = gandi.hostedcert.infos(resource) for num, hcert in enumerate(result): if num: gandi.separator_line() output_hostedcert(gandi, hcert, output_keys) return result
python
def info(gandi, resource): """ Display information about a hosted certificate. Resource can be a FQDN or an ID """ output_keys = ['id', 'subject', 'date_created', 'date_expire', 'fqdns', 'vhosts'] result = gandi.hostedcert.infos(resource) for num, hcert in enumerate(result): if num: gandi.separator_line() output_hostedcert(gandi, hcert, output_keys) return result
[ "def", "info", "(", "gandi", ",", "resource", ")", ":", "output_keys", "=", "[", "'id'", ",", "'subject'", ",", "'date_created'", ",", "'date_expire'", ",", "'fqdns'", ",", "'vhosts'", "]", "result", "=", "gandi", ".", "hostedcert", ".", "infos", "(", "r...
Display information about a hosted certificate. Resource can be a FQDN or an ID
[ "Display", "information", "about", "a", "hosted", "certificate", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certstore.py#L72-L86
train
Gandi/gandi.cli
gandi/cli/commands/certstore.py
create
def create(gandi, private_key, certificate, certificate_id): """ Create a new hosted certificate. """ if not certificate and not certificate_id: gandi.echo('One of --certificate or --certificate-id is needed.') return if certificate and certificate_id: gandi.echo('Only one of --certificate or --certificate-id is needed.') if os.path.isfile(private_key): with open(private_key) as fhandle: private_key = fhandle.read() if certificate: if os.path.isfile(certificate): with open(certificate) as fhandle: certificate = fhandle.read() else: cert = gandi.certificate.info(certificate_id) certificate = gandi.certificate.pretty_format_cert(cert) result = gandi.hostedcert.create(private_key, certificate) output_keys = ['id', 'subject', 'date_created', 'date_expire', 'fqdns', 'vhosts'] output_hostedcert(gandi, result, output_keys) return result
python
def create(gandi, private_key, certificate, certificate_id): """ Create a new hosted certificate. """ if not certificate and not certificate_id: gandi.echo('One of --certificate or --certificate-id is needed.') return if certificate and certificate_id: gandi.echo('Only one of --certificate or --certificate-id is needed.') if os.path.isfile(private_key): with open(private_key) as fhandle: private_key = fhandle.read() if certificate: if os.path.isfile(certificate): with open(certificate) as fhandle: certificate = fhandle.read() else: cert = gandi.certificate.info(certificate_id) certificate = gandi.certificate.pretty_format_cert(cert) result = gandi.hostedcert.create(private_key, certificate) output_keys = ['id', 'subject', 'date_created', 'date_expire', 'fqdns', 'vhosts'] output_hostedcert(gandi, result, output_keys) return result
[ "def", "create", "(", "gandi", ",", "private_key", ",", "certificate", ",", "certificate_id", ")", ":", "if", "not", "certificate", "and", "not", "certificate_id", ":", "gandi", ".", "echo", "(", "'One of --certificate or --certificate-id is needed.'", ")", "return"...
Create a new hosted certificate.
[ "Create", "a", "new", "hosted", "certificate", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certstore.py#L97-L124
train
Gandi/gandi.cli
gandi/cli/commands/certstore.py
delete
def delete(gandi, resource, force): """ Delete a hosted certificate. Resource can be a FQDN or an ID """ infos = gandi.hostedcert.infos(resource) if not infos: return if not force: proceed = click.confirm('Are you sure to delete the following hosted ' 'certificates ?\n' + '\n'.join(['%s: %s' % (res['id'], res['subject']) for res in infos]) + '\n') if not proceed: return for res in infos: gandi.hostedcert.delete(res['id'])
python
def delete(gandi, resource, force): """ Delete a hosted certificate. Resource can be a FQDN or an ID """ infos = gandi.hostedcert.infos(resource) if not infos: return if not force: proceed = click.confirm('Are you sure to delete the following hosted ' 'certificates ?\n' + '\n'.join(['%s: %s' % (res['id'], res['subject']) for res in infos]) + '\n') if not proceed: return for res in infos: gandi.hostedcert.delete(res['id'])
[ "def", "delete", "(", "gandi", ",", "resource", ",", "force", ")", ":", "infos", "=", "gandi", ".", "hostedcert", ".", "infos", "(", "resource", ")", "if", "not", "infos", ":", "return", "if", "not", "force", ":", "proceed", "=", "click", ".", "confi...
Delete a hosted certificate. Resource can be a FQDN or an ID
[ "Delete", "a", "hosted", "certificate", "." ]
6ee5b8fc8ec44b0a6c232043ca610606ad8f693d
https://github.com/Gandi/gandi.cli/blob/6ee5b8fc8ec44b0a6c232043ca610606ad8f693d/gandi/cli/commands/certstore.py#L133-L152
train
aykut/django-bulk-update
django_bulk_update/helper.py
flatten
def flatten(l, types=(list, float)): """ Flat nested list of lists into a single list. """ l = [item if isinstance(item, types) else [item] for item in l] return [item for sublist in l for item in sublist]
python
def flatten(l, types=(list, float)): """ Flat nested list of lists into a single list. """ l = [item if isinstance(item, types) else [item] for item in l] return [item for sublist in l for item in sublist]
[ "def", "flatten", "(", "l", ",", "types", "=", "(", "list", ",", "float", ")", ")", ":", "l", "=", "[", "item", "if", "isinstance", "(", "item", ",", "types", ")", "else", "[", "item", "]", "for", "item", "in", "l", "]", "return", "[", "item", ...
Flat nested list of lists into a single list.
[ "Flat", "nested", "list", "of", "lists", "into", "a", "single", "list", "." ]
399e64d820133a79f910682c1cf247938c5c4784
https://github.com/aykut/django-bulk-update/blob/399e64d820133a79f910682c1cf247938c5c4784/django_bulk_update/helper.py#L41-L46
train