desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Detach a block device'
| def volume_detach(self, name, timeout=300):
| try:
volume = self.volume_show(name)
except KeyError as exc:
raise SaltCloudSystemExit('Unable to find {0} volume: {1}'.format(name, exc))
if (not volume['attachments']):
return True
response = self.compute_conn.volumes.delete_server_volume(volume['attachments'][0]['server_id'], volume['attachments'][0]['id'])
trycount = 0
start = time.time()
while True:
trycount += 1
try:
response = self._volume_get(volume['id'])
if (response['status'] == 'available'):
return response
except Exception as exc:
log.debug('Volume is detaching: {0}'.format(name))
time.sleep(1)
if ((time.time() - start) > timeout):
log.error('Timed out after {0} seconds while waiting for data'.format(timeout))
return False
log.debug('Retrying volume_show() (try {0})'.format(trycount))
|
'Attach a block device'
| def volume_attach(self, name, server_name, device='/dev/xvdb', timeout=300):
| try:
volume = self.volume_show(name)
except KeyError as exc:
raise SaltCloudSystemExit('Unable to find {0} volume: {1}'.format(name, exc))
server = self.server_by_name(server_name)
response = self.compute_conn.volumes.create_server_volume(server.id, volume['id'], device=device)
trycount = 0
start = time.time()
while True:
trycount += 1
try:
response = self._volume_get(volume['id'])
if (response['status'] == 'in-use'):
return response
except Exception as exc:
log.debug('Volume is attaching: {0}'.format(name))
time.sleep(1)
if ((time.time() - start) > timeout):
log.error('Timed out after {0} seconds while waiting for data'.format(timeout))
return False
log.debug('Retrying volume_show() (try {0})'.format(trycount))
|
'Suspend a server'
| def suspend(self, instance_id):
| nt_ks = self.compute_conn
response = nt_ks.servers.suspend(instance_id)
return True
|
'Resume a server'
| def resume(self, instance_id):
| nt_ks = self.compute_conn
response = nt_ks.servers.resume(instance_id)
return True
|
'Lock an instance'
| def lock(self, instance_id):
| nt_ks = self.compute_conn
response = nt_ks.servers.lock(instance_id)
return True
|
'Delete a server'
| def delete(self, instance_id):
| nt_ks = self.compute_conn
response = nt_ks.servers.delete(instance_id)
return True
|
'Return a list of available flavors (nova flavor-list)'
| def flavor_list(self):
| nt_ks = self.compute_conn
ret = {}
for flavor in nt_ks.flavors.list():
links = {}
for link in flavor.links:
links[link['rel']] = link['href']
ret[flavor.name] = {'disk': flavor.disk, 'id': flavor.id, 'name': flavor.name, 'ram': flavor.ram, 'swap': flavor.swap, 'vcpus': flavor.vcpus, 'links': links}
if hasattr(flavor, 'rxtx_factor'):
ret[flavor.name]['rxtx_factor'] = flavor.rxtx_factor
return ret
|
'Create a flavor'
| def flavor_create(self, name, flavor_id=0, ram=0, disk=0, vcpus=1):
| nt_ks = self.compute_conn
nt_ks.flavors.create(name=name, flavorid=flavor_id, ram=ram, disk=disk, vcpus=vcpus)
return {'name': name, 'id': flavor_id, 'ram': ram, 'disk': disk, 'vcpus': vcpus}
|
'Delete a flavor'
| def flavor_delete(self, flavor_id):
| nt_ks = self.compute_conn
nt_ks.flavors.delete(flavor_id)
return 'Flavor deleted: {0}'.format(flavor_id)
|
'List keypairs'
| def keypair_list(self):
| nt_ks = self.compute_conn
ret = {}
for keypair in nt_ks.keypairs.list():
ret[keypair.name] = {'name': keypair.name, 'fingerprint': keypair.fingerprint, 'public_key': keypair.public_key}
return ret
|
'Add a keypair'
| def keypair_add(self, name, pubfile=None, pubkey=None):
| nt_ks = self.compute_conn
if pubfile:
with salt.utils.files.fopen(pubfile, 'r') as fp_:
pubkey = fp_.read()
if (not pubkey):
return False
nt_ks.keypairs.create(name, public_key=pubkey)
ret = {'name': name, 'pubkey': pubkey}
return ret
|
'Delete a keypair'
| def keypair_delete(self, name):
| nt_ks = self.compute_conn
nt_ks.keypairs.delete(name)
return 'Keypair deleted: {0}'.format(name)
|
'Show image details and metadata'
| def image_show(self, image_id):
| nt_ks = self.compute_conn
image = nt_ks.images.get(image_id)
links = {}
for link in image.links:
links[link['rel']] = link['href']
ret = {'name': image.name, 'id': image.id, 'status': image.status, 'progress': image.progress, 'created': image.created, 'updated': image.updated, 'metadata': image.metadata, 'links': links}
if hasattr(image, 'minDisk'):
ret['minDisk'] = image.minDisk
if hasattr(image, 'minRam'):
ret['minRam'] = image.minRam
return ret
|
'List server images'
| def image_list(self, name=None):
| nt_ks = self.compute_conn
ret = {}
for image in nt_ks.images.list():
links = {}
for link in image.links:
links[link['rel']] = link['href']
ret[image.name] = {'name': image.name, 'id': image.id, 'status': image.status, 'progress': image.progress, 'created': image.created, 'updated': image.updated, 'metadata': image.metadata, 'links': links}
if hasattr(image, 'minDisk'):
ret[image.name]['minDisk'] = image.minDisk
if hasattr(image, 'minRam'):
ret[image.name]['minRam'] = image.minRam
if name:
return {name: ret[name]}
return ret
|
'Set image metadata'
| def image_meta_set(self, image_id=None, name=None, **kwargs):
| nt_ks = self.compute_conn
if name:
for image in nt_ks.images.list():
if (image.name == name):
image_id = image.id
if (not image_id):
return {'Error': 'A valid image name or id was not specified'}
nt_ks.images.set_meta(image_id, kwargs)
return {image_id: kwargs}
|
'Delete image metadata'
| def image_meta_delete(self, image_id=None, name=None, keys=None):
| nt_ks = self.compute_conn
if name:
for image in nt_ks.images.list():
if (image.name == name):
image_id = image.id
pairs = keys.split(',')
if (not image_id):
return {'Error': 'A valid image name or id was not specified'}
nt_ks.images.delete_meta(image_id, pairs)
return {image_id: 'Deleted: {0}'.format(pairs)}
|
'List servers'
| def server_list(self):
| nt_ks = self.compute_conn
ret = {}
for item in nt_ks.servers.list():
try:
ret[item.name] = {'id': item.id, 'name': item.name, 'state': item.status, 'accessIPv4': item.accessIPv4, 'accessIPv6': item.accessIPv6, 'flavor': {'id': item.flavor['id'], 'links': item.flavor['links']}, 'image': {'id': (item.image['id'] if item.image else 'Boot From Volume'), 'links': (item.image['links'] if item.image else '')}}
except TypeError:
pass
return ret
|
'List minimal information about servers'
| def server_list_min(self):
| nt_ks = self.compute_conn
ret = {}
for item in nt_ks.servers.list(detailed=False):
try:
ret[item.name] = {'id': item.id, 'status': 'Running'}
except TypeError:
pass
return ret
|
'Detailed list of servers'
| def server_list_detailed(self):
| nt_ks = self.compute_conn
ret = {}
for item in nt_ks.servers.list():
try:
ret[item.name] = {'OS-EXT-SRV-ATTR': {}, 'OS-EXT-STS': {}, 'accessIPv4': item.accessIPv4, 'accessIPv6': item.accessIPv6, 'addresses': item.addresses, 'created': item.created, 'flavor': {'id': item.flavor['id'], 'links': item.flavor['links']}, 'hostId': item.hostId, 'id': item.id, 'image': {'id': (item.image['id'] if item.image else 'Boot From Volume'), 'links': (item.image['links'] if item.image else '')}, 'key_name': item.key_name, 'links': item.links, 'metadata': item.metadata, 'name': item.name, 'state': item.status, 'tenant_id': item.tenant_id, 'updated': item.updated, 'user_id': item.user_id}
except TypeError:
continue
ret[item.name]['progress'] = getattr(item, 'progress', '0')
if hasattr(item.__dict__, 'OS-DCF:diskConfig'):
ret[item.name]['OS-DCF'] = {'diskConfig': item.__dict__['OS-DCF:diskConfig']}
if hasattr(item.__dict__, 'OS-EXT-SRV-ATTR:host'):
ret[item.name]['OS-EXT-SRV-ATTR']['host'] = item.__dict__['OS-EXT-SRV-ATTR:host']
if hasattr(item.__dict__, 'OS-EXT-SRV-ATTR:hypervisor_hostname'):
ret[item.name]['OS-EXT-SRV-ATTR']['hypervisor_hostname'] = item.__dict__['OS-EXT-SRV-ATTR:hypervisor_hostname']
if hasattr(item.__dict__, 'OS-EXT-SRV-ATTR:instance_name'):
ret[item.name]['OS-EXT-SRV-ATTR']['instance_name'] = item.__dict__['OS-EXT-SRV-ATTR:instance_name']
if hasattr(item.__dict__, 'OS-EXT-STS:power_state'):
ret[item.name]['OS-EXT-STS']['power_state'] = item.__dict__['OS-EXT-STS:power_state']
if hasattr(item.__dict__, 'OS-EXT-STS:task_state'):
ret[item.name]['OS-EXT-STS']['task_state'] = item.__dict__['OS-EXT-STS:task_state']
if hasattr(item.__dict__, 'OS-EXT-STS:vm_state'):
ret[item.name]['OS-EXT-STS']['vm_state'] = item.__dict__['OS-EXT-STS:vm_state']
if hasattr(item.__dict__, 'security_groups'):
ret[item.name]['security_groups'] = item.__dict__['security_groups']
return ret
|
'Show details of one server'
| def server_show(self, server_id):
| ret = {}
try:
servers = self.server_list_detailed()
except AttributeError:
raise SaltCloudSystemExit('Corrupt server in server_list_detailed. Remove corrupt servers.')
for (server_name, server) in six.iteritems(servers):
if (str(server['id']) == server_id):
ret[server_name] = server
return ret
|
'Create a security group'
| def secgroup_create(self, name, description):
| nt_ks = self.compute_conn
nt_ks.security_groups.create(name, description)
ret = {'name': name, 'description': description}
return ret
|
'Delete a security group'
| def secgroup_delete(self, name):
| nt_ks = self.compute_conn
for item in nt_ks.security_groups.list():
if (item.name == name):
nt_ks.security_groups.delete(item.id)
return {name: 'Deleted security group: {0}'.format(name)}
return 'Security group not found: {0}'.format(name)
|
'List security groups'
| def secgroup_list(self):
| nt_ks = self.compute_conn
ret = {}
for item in nt_ks.security_groups.list():
ret[item.name] = {'name': item.name, 'description': item.description, 'id': item.id, 'tenant_id': item.tenant_id, 'rules': item.rules}
return ret
|
'List items'
| def _item_list(self):
| nt_ks = self.compute_conn
ret = []
for item in nt_ks.items.list():
ret.append(item.__dict__)
return ret
|
'Parse the returned network list'
| def _network_show(self, name, network_lst):
| for net in network_lst:
if (net.label == name):
return net.__dict__
return {}
|
'Show network information'
| def network_show(self, name):
| nt_ks = self.compute_conn
net_list = nt_ks.networks.list()
return self._network_show(name, net_list)
|
'List extra private networks'
| def network_list(self):
| nt_ks = self.compute_conn
return [network.__dict__ for network in nt_ks.networks.list()]
|
'Sanatize novaclient network parameters'
| def _sanatize_network_params(self, kwargs):
| params = ['label', 'bridge', 'bridge_interface', 'cidr', 'cidr_v6', 'dns1', 'dns2', 'fixed_cidr', 'gateway', 'gateway_v6', 'multi_host', 'priority', 'project_id', 'vlan_start', 'vpn_start']
for variable in six.iterkeys(kwargs):
if (variable not in params):
del kwargs[variable]
return kwargs
|
'Create extra private network'
| def network_create(self, name, **kwargs):
| nt_ks = self.compute_conn
kwargs['label'] = name
kwargs = self._sanatize_network_params(kwargs)
net = nt_ks.networks.create(**kwargs)
return net.__dict__
|
'Get server uuid from name'
| def _server_uuid_from_name(self, name):
| return self.server_list().get(name, {}).get('id', '')
|
'Get virtual interfaces on slice'
| def virtual_interface_list(self, name):
| nt_ks = self.compute_conn
nets = nt_ks.virtual_interfaces.list(self._server_uuid_from_name(name))
return [network.__dict__ for network in nets]
|
'Add an interfaces to a slice'
| def virtual_interface_create(self, name, net_name):
| nt_ks = self.compute_conn
serverid = self._server_uuid_from_name(name)
networkid = self.network_show(net_name).get('id', None)
if (networkid is None):
return {net_name: False}
nets = nt_ks.virtual_interfaces.create(networkid, serverid)
return nets
|
'List all floating IP pools
.. versionadded:: 2016.3.0'
| def floating_ip_pool_list(self):
| nt_ks = self.compute_conn
pools = nt_ks.floating_ip_pools.list()
response = {}
for pool in pools:
response[pool.name] = {'name': pool.name}
return response
|
'List floating IPs
.. versionadded:: 2016.3.0'
| def floating_ip_list(self):
| nt_ks = self.compute_conn
floating_ips = nt_ks.floating_ips.list()
response = {}
for floating_ip in floating_ips:
response[floating_ip.ip] = {'ip': floating_ip.ip, 'fixed_ip': floating_ip.fixed_ip, 'id': floating_ip.id, 'instance_id': floating_ip.instance_id, 'pool': floating_ip.pool}
return response
|
'Show info on specific floating IP
.. versionadded:: 2016.3.0'
| def floating_ip_show(self, ip):
| nt_ks = self.compute_conn
floating_ips = nt_ks.floating_ips.list()
for floating_ip in floating_ips:
if (floating_ip.ip == ip):
response = {'ip': floating_ip.ip, 'fixed_ip': floating_ip.fixed_ip, 'id': floating_ip.id, 'instance_id': floating_ip.instance_id, 'pool': floating_ip.pool}
return response
return {}
|
'Allocate a floating IP
.. versionadded:: 2016.3.0'
| def floating_ip_create(self, pool=None):
| nt_ks = self.compute_conn
floating_ip = nt_ks.floating_ips.create(pool)
response = {'ip': floating_ip.ip, 'fixed_ip': floating_ip.fixed_ip, 'id': floating_ip.id, 'instance_id': floating_ip.instance_id, 'pool': floating_ip.pool}
return response
|
'De-allocate a floating IP
.. versionadded:: 2016.3.0'
| def floating_ip_delete(self, floating_ip):
| ip = self.floating_ip_show(floating_ip)
nt_ks = self.compute_conn
return nt_ks.floating_ips.delete(ip)
|
'Associate floating IP address to server
.. versionadded:: 2016.3.0'
| def floating_ip_associate(self, server_name, floating_ip):
| nt_ks = self.compute_conn
server_ = self.server_by_name(server_name)
server = nt_ks.servers.get(server_.__dict__['id'])
server.add_floating_ip(floating_ip)
return self.floating_ip_list()[floating_ip]
|
'Disassociate a floating IP from server
.. versionadded:: 2016.3.0'
| def floating_ip_disassociate(self, server_name, floating_ip):
| nt_ks = self.compute_conn
server_ = self.server_by_name(server_name)
server = nt_ks.servers.get(server_.__dict__['id'])
server.remove_floating_ip(floating_ip)
return self.floating_ip_list()[floating_ip]
|
'Set up openstack credentials'
| def __init__(self, user, tenant_name, auth_url, password=None, auth_version=2, **kwargs):
| if (not HAS_SWIFT):
log.error('Error:: unable to find swiftclient. Try installing it from the appropriate repository.')
return None
self.kwargs = kwargs.copy()
self.kwargs['user'] = user
self.kwargs['password'] = password
self.kwargs['tenant_name'] = tenant_name
self.kwargs['authurl'] = auth_url
self.kwargs['auth_version'] = auth_version
if ('key' not in self.kwargs):
self.kwargs['key'] = password
self.kwargs = _sanitize(self.kwargs)
self.conn = client.Connection(**self.kwargs)
|
'List Swift containers'
| def get_account(self):
| try:
listing = self.conn.get_account()
return listing
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'List files in a Swift container'
| def get_container(self, cont):
| try:
listing = self.conn.get_container(cont)
return listing
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'Create a new Swift container'
| def put_container(self, cont):
| try:
self.conn.put_container(cont)
return True
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'Delete a Swift container'
| def delete_container(self, cont):
| try:
self.conn.delete_container(cont)
return True
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'Update container metadata'
| def post_container(self, cont, metadata=None):
| pass
|
'Get container metadata'
| def head_container(self, cont):
| pass
|
'Retrieve a file from Swift'
| def get_object(self, cont, obj, local_file=None, return_bin=False):
| try:
if ((local_file is None) and (return_bin is False)):
return False
(headers, body) = self.conn.get_object(cont, obj, resp_chunk_size=65536)
if (return_bin is True):
fp = sys.stdout
else:
dirpath = dirname(local_file)
if (dirpath and (not isdir(dirpath))):
mkdirs(dirpath)
fp = salt.utils.files.fopen(local_file, 'wb')
read_length = 0
for chunk in body:
read_length += len(chunk)
fp.write(chunk)
fp.close()
return True
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'Upload a file to Swift'
| def put_object(self, cont, obj, local_file):
| try:
with salt.utils.files.fopen(local_file, 'rb') as fp_:
self.conn.put_object(cont, obj, fp_)
return True
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'Delete a file from Swift'
| def delete_object(self, cont, obj):
| try:
self.conn.delete_object(cont, obj)
return True
except Exception as exc:
log.error('There was an error::')
if (hasattr(exc, 'code') and hasattr(exc, 'msg')):
log.error(' Code: {0}: {1}'.format(exc.code, exc.msg))
log.error(' Content: \n{0}'.format(getattr(exc, 'read', (lambda : str(exc)))()))
return False
|
'Get object metadata'
| def head_object(self, cont, obj):
| pass
|
'Update object metadata'
| def post_object(self, cont, obj, metadata):
| pass
|
'Create RackSpace Queue.'
| def create(self, qname):
| try:
if self.exists(qname):
log.error('Queues "{0}" already exists. Nothing done.'.format(qname))
return True
self.conn.create(qname)
return True
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during creation: {0}'.format(err_msg))
return False
|
'Delete an existings RackSpace Queue.'
| def delete(self, qname):
| try:
q = self.exists(qname)
if (not q):
return False
queue = self.show(qname)
if queue:
queue.delete()
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during deletion: {0}'.format(err_msg))
return False
return True
|
'Check to see if a Queue exists.'
| def exists(self, qname):
| try:
if self.conn.queue_exists(qname):
return True
return False
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during existing queue check: {0}'.format(err_msg))
return False
|
'Show information about Queue'
| def show(self, qname):
| try:
if (not self.conn.queue_exists(qname)):
return {}
for queue in self.conn.list():
if (queue.name == qname):
return queue
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during existing queue check: {0}'.format(err_msg))
return {}
|
'Set up neutron credentials'
| def __init__(self, username, tenant_name, auth_url, password=None, region_name=None, service_type='network', os_auth_plugin=None, use_keystoneauth=False, **kwargs):
| if (not HAS_NEUTRON):
return None
elif all([use_keystoneauth, HAS_KEYSTONEAUTH]):
self._new_init(username=username, project_name=tenant_name, auth_url=auth_url, region_name=region_name, service_type=service_type, os_auth_plugin=os_auth_plugin, password=password, **kwargs)
else:
self._old_init(username=username, tenant_name=tenant_name, auth_url=auth_url, region_name=region_name, service_type=service_type, os_auth_plugin=os_auth_plugin, password=password, **kwargs)
|
'Fetches tenant info in server\'s context
for following quota operation'
| def get_quotas_tenant(self):
| return self.get_quotas_tenant()
|
'Fetches all tenants quotas'
| def list_quotas(self):
| return self.network_conn.list_quotas()
|
'Fetches information of a certain tenant\'s quotas'
| def show_quota(self, tenant_id):
| return self.network_conn.show_quota(tenant_id=tenant_id)
|
'Update a tenant\'s quota'
| def update_quota(self, tenant_id, subnet=None, router=None, network=None, floatingip=None, port=None, sec_grp=None, sec_grp_rule=None):
| body = {}
if subnet:
body['subnet'] = subnet
if router:
body['router'] = router
if network:
body['network'] = network
if floatingip:
body['floatingip'] = floatingip
if port:
body['port'] = port
if sec_grp:
body['security_group'] = sec_grp
if sec_grp_rule:
body['security_group_rule'] = sec_grp_rule
return self.network_conn.update_quota(tenant_id=tenant_id, body={'quota': body})
|
'Delete the specified tenant\'s quota value'
| def delete_quota(self, tenant_id):
| ret = self.network_conn.delete_quota(tenant_id=tenant_id)
return (ret if ret else True)
|
'Fetches a list of all extensions on server side'
| def list_extensions(self):
| return self.network_conn.list_extensions()
|
'Fetches a list of all ports for a tenant'
| def list_ports(self):
| return self.network_conn.list_ports()
|
'Fetches information of a certain port'
| def show_port(self, port):
| return self._fetch_port(port)
|
'Creates a new port'
| def create_port(self, name, network, device_id=None, admin_state_up=True):
| net_id = self._find_network_id(network)
body = {'admin_state_up': admin_state_up, 'name': name, 'network_id': net_id}
if device_id:
body['device_id'] = device_id
return self.network_conn.create_port(body={'port': body})
|
'Updates a port'
| def update_port(self, port, name, admin_state_up=True):
| port_id = self._find_port_id(port)
body = {'name': name, 'admin_state_up': admin_state_up}
return self.network_conn.update_port(port=port_id, body={'port': body})
|
'Deletes the specified port'
| def delete_port(self, port):
| port_id = self._find_port_id(port)
ret = self.network_conn.delete_port(port=port_id)
return (ret if ret else True)
|
'Fetches a list of all networks for a tenant'
| def list_networks(self):
| return self.network_conn.list_networks()
|
'Fetches information of a certain network'
| def show_network(self, network):
| return self._fetch_network(network)
|
'Creates a new network'
| def create_network(self, name, admin_state_up=True, router_ext=None, network_type=None, physical_network=None, segmentation_id=None, shared=None, vlan_transparent=None):
| body = {'name': name, 'admin_state_up': admin_state_up}
if router_ext:
body['router:external'] = router_ext
if network_type:
body['provider:network_type'] = network_type
if physical_network:
body['provider:physical_network'] = physical_network
if segmentation_id:
body['provider:segmentation_id'] = segmentation_id
if shared:
body['shared'] = shared
if vlan_transparent:
body['vlan_transparent'] = vlan_transparent
return self.network_conn.create_network(body={'network': body})
|
'Updates a network'
| def update_network(self, network, name):
| net_id = self._find_network_id(network)
return self.network_conn.update_network(network=net_id, body={'network': {'name': name}})
|
'Deletes the specified network'
| def delete_network(self, network):
| net_id = self._find_network_id(network)
ret = self.network_conn.delete_network(network=net_id)
return (ret if ret else True)
|
'Fetches a list of all networks for a tenant'
| def list_subnets(self):
| return self.network_conn.list_subnets()
|
'Fetches information of a certain subnet'
| def show_subnet(self, subnet):
| return self._fetch_subnet(subnet)
|
'Creates a new subnet'
| def create_subnet(self, network, cidr, name=None, ip_version=4):
| net_id = self._find_network_id(network)
body = {'cidr': cidr, 'ip_version': ip_version, 'network_id': net_id, 'name': name}
return self.network_conn.create_subnet(body={'subnet': body})
|
'Updates a subnet'
| def update_subnet(self, subnet, name=None):
| subnet_id = self._find_subnet_id(subnet)
return self.network_conn.update_subnet(subnet=subnet_id, body={'subnet': {'name': name}})
|
'Deletes the specified subnet'
| def delete_subnet(self, subnet):
| subnet_id = self._find_subnet_id(subnet)
ret = self.network_conn.delete_subnet(subnet=subnet_id)
return (ret if ret else True)
|
'Fetches a list of all routers for a tenant'
| def list_routers(self):
| return self.network_conn.list_routers()
|
'Fetches information of a certain router'
| def show_router(self, router):
| return self._fetch_router(router)
|
'Creates a new router'
| def create_router(self, name, ext_network=None, admin_state_up=True):
| body = {'name': name, 'admin_state_up': admin_state_up}
if ext_network:
net_id = self._find_network_id(ext_network)
body['external_gateway_info'] = {'network_id': net_id}
return self.network_conn.create_router(body={'router': body})
|
'Updates a router'
| def update_router(self, router, name=None, admin_state_up=None, **kwargs):
| router_id = self._find_router_id(router)
body = {}
if ('ext_network' in kwargs):
if (kwargs.get('ext_network') is None):
body['external_gateway_info'] = None
else:
net_id = self._find_network_id(kwargs.get('ext_network'))
body['external_gateway_info'] = {'network_id': net_id}
if (name is not None):
body['name'] = name
if (admin_state_up is not None):
body['admin_state_up'] = admin_state_up
return self.network_conn.update_router(router=router_id, body={'router': body})
|
'Delete the specified router'
| def delete_router(self, router):
| router_id = self._find_router_id(router)
ret = self.network_conn.delete_router(router=router_id)
return (ret if ret else True)
|
'Adds an internal network interface to the specified router'
| def add_interface_router(self, router, subnet):
| router_id = self._find_router_id(router)
subnet_id = self._find_subnet_id(subnet)
return self.network_conn.add_interface_router(router=router_id, body={'subnet_id': subnet_id})
|
'Removes an internal network interface from the specified router'
| def remove_interface_router(self, router, subnet):
| router_id = self._find_router_id(router)
subnet_id = self._find_subnet_id(subnet)
return self.network_conn.remove_interface_router(router=router_id, body={'subnet_id': subnet_id})
|
'Adds an external network gateway to the specified router'
| def add_gateway_router(self, router, network):
| router_id = self._find_router_id(router)
net_id = self._find_network_id(network)
return self.network_conn.add_gateway_router(router=router_id, body={'network_id': net_id})
|
'Removes an external network gateway from the specified router'
| def remove_gateway_router(self, router):
| router_id = self._find_router_id(router)
return self.network_conn.remove_gateway_router(router=router_id)
|
'Fetch a list of all floatingips for a tenant'
| def list_floatingips(self):
| return self.network_conn.list_floatingips()
|
'Fetches information of a certain floatingip'
| def show_floatingip(self, floatingip_id):
| return self.network_conn.show_floatingip(floatingip_id)
|
'Creates a new floatingip'
| def create_floatingip(self, floating_network, port=None):
| net_id = self._find_network_id(floating_network)
body = {'floating_network_id': net_id}
if port:
port_id = self._find_port_id(port)
body['port_id'] = port_id
return self.network_conn.create_floatingip(body={'floatingip': body})
|
'Updates a floatingip, disassociates the floating ip if
port is set to `None`'
| def update_floatingip(self, floatingip_id, port=None):
| if (port is None):
body = {'floatingip': {}}
else:
port_id = self._find_port_id(port)
body = {'floatingip': {'port_id': port_id}}
return self.network_conn.update_floatingip(floatingip=floatingip_id, body=body)
|
'Deletes the specified floatingip'
| def delete_floatingip(self, floatingip_id):
| ret = self.network_conn.delete_floatingip(floatingip_id)
return (ret if ret else True)
|
'Fetches a list of all security groups for a tenant'
| def list_security_groups(self):
| return self.network_conn.list_security_groups()
|
'Fetches information of a certain security group'
| def show_security_group(self, sec_grp):
| return self._fetch_security_group(sec_grp)
|
'Creates a new security group'
| def create_security_group(self, name, desc=None):
| body = {'security_group': {'name': name, 'description': desc}}
return self.network_conn.create_security_group(body=body)
|
'Updates a security group'
| def update_security_group(self, sec_grp, name=None, desc=None):
| sec_grp_id = self._find_security_group_id(sec_grp)
body = {'security_group': {}}
if name:
body['security_group']['name'] = name
if desc:
body['security_group']['description'] = desc
return self.network_conn.update_security_group(sec_grp_id, body=body)
|
'Deletes the specified security group'
| def delete_security_group(self, sec_grp):
| sec_grp_id = self._find_security_group_id(sec_grp)
ret = self.network_conn.delete_security_group(sec_grp_id)
return (ret if ret else True)
|
'Fetches a list of all security group rules for a tenant'
| def list_security_group_rules(self):
| return self.network_conn.list_security_group_rules()
|
'Fetches information of a certain security group rule'
| def show_security_group_rule(self, sec_grp_rule_id):
| return self.network_conn.show_security_group_rule(sec_grp_rule_id)['security_group_rule']
|
'Creates a new security group rule'
| def create_security_group_rule(self, sec_grp, remote_grp_id=None, direction='ingress', protocol=None, port_range_min=None, port_range_max=None, ether=None):
| sec_grp_id = self._find_security_group_id(sec_grp)
body = {'security_group_id': sec_grp_id, 'remote_group_id': remote_grp_id, 'direction': direction, 'protocol': protocol, 'port_range_min': port_range_min, 'port_range_max': port_range_max, 'ethertype': ether}
return self.network_conn.create_security_group_rule(body={'security_group_rule': body})
|
'Deletes the specified security group rule'
| def delete_security_group_rule(self, sec_grp_rule_id):
| ret = self.network_conn.delete_security_group_rule(security_group_rule=sec_grp_rule_id)
return (ret if ret else True)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.