Search is not available for this dataset
text stringlengths 75 104k |
|---|
def detect_protocol(cls, data, default=None):
""" TODO: support fbthrift, finagle-thrift, finagle-mux, CORBA """
if cls.is_compact_protocol(data):
return TCompactProtocol
elif cls.is_binary_protocol(data):
return TBinaryProtocol
elif cls.is_json_protocol(data):
... |
def pop(self, nbytes):
""" pops packets with _at least_ nbytes of payload """
size = 0
popped = []
with self._lock_packets:
while size < nbytes:
try:
packet = self._packets.pop(0)
size += len(packet.data.data)
... |
def pop_data(self, nbytes):
""" similar to pop, but returns payload + last timestamp """
last_timestamp = 0
data = []
for packet in self.pop(nbytes):
last_timestamp = packet.timestamp
data.append(packet.data.data)
return ''.join(data), last_timestamp |
def push(self, ip_packet):
""" push the packet into the queue """
data_len = len(ip_packet.data.data)
seq_id = ip_packet.data.seq
if data_len == 0:
self._next_seq_id = seq_id
return False
# have we seen this packet?
if self._next_seq_id != -1 an... |
def run(self, *args, **kwargs):
""" Deal with the incoming packets """
while True:
try:
timestamp, ip_p = self._queue.popleft()
src_ip = get_ip(ip_p, ip_p.src)
dst_ip = get_ip(ip_p, ip_p.dst)
src = intern('%s:%s' % (src_ip, ip... |
def getLogin(filename, user, passwd):
'''
write user/passwd to login file or get them from file.
This method is not Py3 safe (byte vs. str)
'''
if filename is None:
return (user, passwd)
isPy2 = sys.version_info[0] == 2
if os.path.exists(filename):
print("Using file {} for Lo... |
def wait_for_requests(pbclient, request_ids=None,
timeout=0, initial_wait=5, scaleup=10):
'''
Waits for a list of requests to finish until timeout.
timeout==0 is interpreted as infinite wait time.
Returns a dict of request_id -> result.
result is a tuple (return code, request s... |
def get_disk_image_by_name(pbclient, location, image_name):
"""
Returns all disk images within a location with a given image name.
The name must match exactly.
The list may be empty.
"""
all_images = pbclient.list_images()
matching = [i for i in all_images['items'] if
i['prop... |
def main(argv=None):
'''Command line options.'''
if argv is None:
argv = sys.argv
else:
sys.argv.extend(argv)
program_name = os.path.basename(sys.argv[0])
program_version = "v%s" % __version__
program_build_date = str(__updated__)
program_version_message = '%%(prog)s %s (%s... |
def _nsattr(self, attr, ns=None):
''' returns an attribute name w/ namespace prefix'''
if ns is None:
return attr
return '{' + self._ns[ns] + '}' + attr |
def _read_config(self, filename=None):
"""
Read the user configuration
"""
if filename:
self._config_filename = filename
else:
try:
import appdirs
except ImportError:
raise Exception("Missing dependency for deter... |
def _save_config(self, filename=None):
"""
Save the given user configuration.
"""
if filename is None:
filename = self._config_filename
parent_path = os.path.dirname(filename)
if not os.path.isdir(parent_path):
os.makedirs(parent_path)
with... |
def _get_username(self, username=None, use_config=True, config_filename=None):
"""Determine the username
If a username is given, this name is used. Otherwise the configuration
file will be consulted if `use_config` is set to True. The user is asked
for the username if the username is no... |
def _get_password(self, password, use_config=True, config_filename=None,
use_keyring=HAS_KEYRING):
"""
Determine the user password
If the password is given, this password is used. Otherwise
this function will try to get the password from the user's keyring
... |
def get_datacenter(self, datacenter_id, depth=1):
"""
Retrieves a data center by its ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param depth: The depth of the response data.
:type depth: ``int``
... |
def get_datacenter_by_name(self, name, depth=1):
"""
Retrieves a data center by its name.
Either returns the data center response or raises an Exception
if no or more than one data center was found with the name.
The search for the name is done in this relaxing way:
- e... |
def delete_datacenter(self, datacenter_id):
"""
Removes the data center and all its components such as servers, NICs,
load balancers, volumes.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
"""
response = self._pe... |
def create_datacenter(self, datacenter):
"""
Creates a data center -- both simple and complex are supported.
"""
server_items = []
volume_items = []
lan_items = []
loadbalancer_items = []
entities = dict()
properties = {
"name": data... |
def get_firewall_rule(self, datacenter_id,
server_id, nic_id, firewall_rule_id):
"""
Retrieves a single firewall rule by ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The uniq... |
def delete_firewall_rule(self, datacenter_id, server_id,
nic_id, firewall_rule_id):
"""
Removes a firewall rule from the NIC.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The ... |
def create_firewall_rule(self, datacenter_id, server_id,
nic_id, firewall_rule):
"""
Creates a firewall rule on the specified NIC and server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param ... |
def update_firewall_rule(self, datacenter_id, server_id,
nic_id, firewall_rule_id, **kwargs):
"""
Updates a firewall rule.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The uni... |
def delete_image(self, image_id):
"""
Removes only user created images.
:param image_id: The unique ID of the image.
:type image_id: ``str``
"""
response = self._perform_request(url='/images/' + image_id,
method='DELET... |
def update_image(self, image_id, **kwargs):
"""
Replace all properties of an image.
"""
data = {}
for attr, value in kwargs.items():
data[self._underscore_to_camelcase(attr)] = value
response = self._perform_request(url='/images/' + image_id,
... |
def delete_ipblock(self, ipblock_id):
"""
Removes a single IP block from your account.
:param ipblock_id: The unique ID of the IP block.
:type ipblock_id: ``str``
"""
response = self._perform_request(
url='/ipblocks/' + ipblock_id, method='DELETE'... |
def reserve_ipblock(self, ipblock):
"""
Reserves an IP block within your account.
"""
properties = {
"name": ipblock.name
}
if ipblock.location:
properties['location'] = ipblock.location
if ipblock.size:
properties['size'] = ... |
def get_lan(self, datacenter_id, lan_id, depth=1):
"""
Retrieves a single LAN by ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param lan_id: The unique ID of the LAN.
:type lan_id: ``str``
:param... |
def list_lans(self, datacenter_id, depth=1):
"""
Retrieves a list of LANs available in the account.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param depth: The depth of the response data.
:type depth: ``in... |
def delete_lan(self, datacenter_id, lan_id):
"""
Removes a LAN from the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param lan_id: The unique ID of the LAN.
:type lan_id: ``str``
"""
... |
def create_lan(self, datacenter_id, lan):
"""
Creates a LAN in the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param lan: The LAN object to be created.
:type lan: ``dict``
"""
... |
def update_lan(self, datacenter_id, lan_id, name=None,
public=None, ip_failover=None):
"""
Updates a LAN
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param lan_id: The unique ID of the LAN.
:typ... |
def get_lan_members(self, datacenter_id, lan_id, depth=1):
"""
Retrieves the list of NICs that are part of the LAN.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param lan_id: The unique ID of the LAN.
:type ... |
def get_loadbalancer(self, datacenter_id, loadbalancer_id):
"""
Retrieves a single load balancer by ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer_id: The unique ID of the load balancer.
:type... |
def list_loadbalancers(self, datacenter_id, depth=1):
"""
Retrieves a list of load balancers in the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param depth: The depth of the response data.
:type ... |
def delete_loadbalancer(self, datacenter_id, loadbalancer_id):
"""
Removes the load balancer from the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer_id: The unique ID of the load balancer.
... |
def create_loadbalancer(self, datacenter_id, loadbalancer):
"""
Creates a load balancer within the specified data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer: The load balancer object to be cre... |
def update_loadbalancer(self, datacenter_id,
loadbalancer_id, **kwargs):
"""
Updates a load balancer
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer_id: The unique ID of the loa... |
def get_loadbalancer_members(self, datacenter_id, loadbalancer_id,
depth=1):
"""
Retrieves the list of NICs that are associated with a load balancer.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
... |
def add_loadbalanced_nics(self, datacenter_id,
loadbalancer_id, nic_id):
"""
Associates a NIC with the given load balancer.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer_id:... |
def get_loadbalanced_nic(self, datacenter_id,
loadbalancer_id, nic_id, depth=1):
"""
Gets the properties of a load balanced NIC.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer... |
def remove_loadbalanced_nic(self, datacenter_id,
loadbalancer_id, nic_id):
"""
Removes a NIC from the load balancer.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param loadbalancer_id: The ... |
def get_location(self, location_id, depth=0):
"""
Retrieves a single location by ID.
:param location_id: The unique ID of the location.
:type location_id: ``str``
"""
response = self._perform_request('/locations/%s?depth=%s' % (location_id, depth))
re... |
def get_nic(self, datacenter_id, server_id, nic_id, depth=1):
"""
Retrieves a NIC by its ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str`... |
def list_nics(self, datacenter_id, server_id, depth=1):
"""
Retrieves a list of all NICs bound to the specified server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:t... |
def delete_nic(self, datacenter_id, server_id, nic_id):
"""
Removes a NIC from the server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str``
... |
def create_nic(self, datacenter_id, server_id, nic):
"""
Creates a NIC on the specified server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``s... |
def update_nic(self, datacenter_id, server_id,
nic_id, **kwargs):
"""
Updates a NIC with the parameters provided.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the serve... |
def get_request(self, request_id, status=False):
"""
Retrieves a single request by ID.
:param request_id: The unique ID of the request.
:type request_id: ``str``
:param status: Retreive the full status of the request.
:type status: ``bool``
... |
def get_server(self, datacenter_id, server_id, depth=1):
"""
Retrieves a server by its ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str``
... |
def list_servers(self, datacenter_id, depth=1):
"""
Retrieves a list of all servers bound to the specified data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param depth: The depth of the response data.
:ty... |
def delete_server(self, datacenter_id, server_id):
"""
Removes the server from your data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``... |
def create_server(self, datacenter_id, server):
"""
Creates a server within the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server: A dict of the server to be created.
:type server: ``dic... |
def update_server(self, datacenter_id, server_id, **kwargs):
"""
Updates a server with the parameters provided.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type ... |
def get_attached_volumes(self, datacenter_id, server_id, depth=1):
"""
Retrieves a list of volumes attached to the server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
... |
def get_attached_volume(self, datacenter_id, server_id, volume_id):
"""
Retrieves volume information.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_i... |
def attach_volume(self, datacenter_id, server_id, volume_id):
"""
Attaches a volume to a server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``... |
def detach_volume(self, datacenter_id, server_id, volume_id):
"""
Detaches a volume from a server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ... |
def get_attached_cdroms(self, datacenter_id, server_id, depth=1):
"""
Retrieves a list of CDROMs attached to the server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:... |
def get_attached_cdrom(self, datacenter_id, server_id, cdrom_id):
"""
Retrieves an attached CDROM.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ... |
def attach_cdrom(self, datacenter_id, server_id, cdrom_id):
"""
Attaches a CDROM to a server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str... |
def detach_cdrom(self, datacenter_id, server_id, cdrom_id):
"""
Detaches a volume from a server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``... |
def start_server(self, datacenter_id, server_id):
"""
Starts the server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str``
"""
... |
def stop_server(self, datacenter_id, server_id):
"""
Stops the server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str``
"""
... |
def reboot_server(self, datacenter_id, server_id):
"""
Reboots the server.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param server_id: The unique ID of the server.
:type server_id: ``str``
"""
... |
def delete_snapshot(self, snapshot_id):
"""
Removes a snapshot from your account.
:param snapshot_id: The unique ID of the snapshot.
:type snapshot_id: ``str``
"""
response = self._perform_request(
url='/snapshots/' + snapshot_id, method='DELETE')... |
def update_snapshot(self, snapshot_id, **kwargs):
"""
Removes a snapshot from your account.
:param snapshot_id: The unique ID of the snapshot.
:type snapshot_id: ``str``
"""
data = {}
for attr, value in kwargs.items():
data[self._underscor... |
def create_snapshot(self, datacenter_id, volume_id,
name=None, description=None):
"""
Creates a snapshot of the specified volume.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param volume_id: The u... |
def restore_snapshot(self, datacenter_id, volume_id, snapshot_id):
"""
Restores a snapshot to the specified volume.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param volume_id: The unique ID of the volume.
:type ... |
def remove_snapshot(self, snapshot_id):
"""
Removes a snapshot.
:param snapshot_id: The ID of the snapshot
you wish to remove.
:type snapshot_id: ``str``
"""
response = self._perform_request(
url='/snapshots/' + sn... |
def get_group(self, group_id, depth=1):
"""
Retrieves a single group by ID.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param depth: The depth of the response data.
:type depth: ``int``
"""
response = self... |
def create_group(self, group):
"""
Creates a new group and set group privileges.
:param group: The group object to be created.
:type group: ``dict``
"""
data = json.dumps(self._create_group_dict(group))
response = self._perform_request(
u... |
def update_group(self, group_id, **kwargs):
"""
Updates a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
"""
properties = {}
# make the key camel-case transformable
if 'create_datacenter' in kwargs:
kw... |
def delete_group(self, group_id):
"""
Removes a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
"""
response = self._perform_request(
url='/um/groups/%s' % group_id,
method='DELETE')
return response |
def list_shares(self, group_id, depth=1):
"""
Retrieves a list of all shares though a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param depth: The depth of the response data.
:type depth: ``int``
"""
... |
def get_share(self, group_id, resource_id, depth=1):
"""
Retrieves a specific resource share available to a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param resource_id: The unique ID of the resource.
:type resourc... |
def add_share(self, group_id, resource_id, **kwargs):
"""
Shares a resource through a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param resource_id: The unique ID of the resource.
:type resource_id: ``str``
... |
def delete_share(self, group_id, resource_id):
"""
Removes a resource share from a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param resource_id: The unique ID of the resource.
:type resource_id: ``str``
""... |
def get_user(self, user_id, depth=1):
"""
Retrieves a single user by ID.
:param user_id: The unique ID of the user.
:type user_id: ``str``
:param depth: The depth of the response data.
:type depth: ``int``
"""
response = self._perf... |
def create_user(self, user):
"""
Creates a new user.
:param user: The user object to be created.
:type user: ``dict``
"""
data = self._create_user_dict(user=user)
response = self._perform_request(
url='/um/users',
method='POST... |
def update_user(self, user_id, **kwargs):
"""
Updates a user.
:param user_id: The unique ID of the user.
:type user_id: ``str``
"""
properties = {}
for attr, value in kwargs.items():
properties[self._underscore_to_camelcase(attr)] = value... |
def delete_user(self, user_id):
"""
Removes a user.
:param user_id: The unique ID of the user.
:type user_id: ``str``
"""
response = self._perform_request(
url='/um/users/%s' % user_id,
method='DELETE')
return response |
def list_group_users(self, group_id, depth=1):
"""
Retrieves a list of all users that are members of a particular group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param depth: The depth of the response data.
:type depth:... |
def add_group_user(self, group_id, user_id):
"""
Adds an existing user to a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param user_id: The unique ID of the user.
:type user_id: ``str``
"""
data = {
... |
def remove_group_user(self, group_id, user_id):
"""
Removes a user from a group.
:param group_id: The unique ID of the group.
:type group_id: ``str``
:param user_id: The unique ID of the user.
:type user_id: ``str``
"""
response = ... |
def list_resources(self, resource_type=None, depth=1):
"""
Retrieves a list of all resources.
:param resource_type: The resource type: datacenter, image,
snapshot or ipblock. Default is None,
i.e., all resources are list... |
def get_resource(self, resource_type, resource_id, depth=1):
"""
Retrieves a single resource of a particular type.
:param resource_type: The resource type: datacenter, image,
snapshot or ipblock.
:type resource_type: ``str``
:param ... |
def get_volume(self, datacenter_id, volume_id):
"""
Retrieves a single volume by ID.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param volume_id: The unique ID of the volume.
:type volume_id: ``str``
... |
def list_volumes(self, datacenter_id, depth=1):
"""
Retrieves a list of volumes in the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param depth: The depth of the response data.
:type depth: ``in... |
def delete_volume(self, datacenter_id, volume_id):
"""
Removes a volume from the data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param volume_id: The unique ID of the volume.
:type volume_id: ``str... |
def create_volume(self, datacenter_id, volume):
"""
Creates a volume within the specified data center.
:param datacenter_id: The unique ID of the data center.
:type datacenter_id: ``str``
:param volume: A volume dict.
:type volume: ``dict``
... |
def wait_for_completion(self, response, timeout=3600, initial_wait=5, scaleup=10):
"""
Poll resource request status until resource is provisioned.
:param response: A response dict, which needs to have a 'requestId' item.
:type response: ``dict``
:param timeout: ... |
def _b(s, encoding='utf-8'):
"""
Returns the given string as a string of bytes. That means in
Python2 as a str object, and in Python3 as a bytes object.
Raises a TypeError, if it cannot be converted.
"""
if six.PY2:
# This is Python2
if isinstance(... |
def _underscore_to_camelcase(value):
"""
Convert Python snake case back to mixed case.
"""
def camelcase():
yield str.lower
while True:
yield str.capitalize
c = camelcase()
return "".join(next(c)(x) if x else '_' for x in value.spl... |
def ask(question, options, default):
"""
Ask the user a question with a list of allowed answers (like yes or no).
The user is presented with a question and asked to select an answer from
the given options list. The default will be returned if the user enters
nothing. The user is asked to repeat his... |
def find_item_by_name(list_, namegetter, name):
"""
Find a item a given list by a matching name.
The search for the name is done in this relaxing way:
- exact name match
- case-insentive name match
- attribute starts with the name
- attribute starts with the name (case insensitive)
- n... |
def create_datacenter_dict(pbclient, datacenter):
"""
Creates a Datacenter dict -- both simple and complex are supported.
This is copied from createDatacenter() and uses private methods.
"""
# pylint: disable=protected-access
server_items = []
volume_items = []
lan_items = []
loadba... |
def main(argv=None):
'''Parse command line options and create a server/volume composite.'''
if argv is None:
argv = sys.argv
else:
sys.argv.extend(argv)
program_name = os.path.basename(sys.argv[0])
program_version = "v%s" % __version__
program_build_date = str(__updated__)
... |
def getServerInfo(pbclient=None, dc_id=None):
''' gets info of servers of a data center'''
if pbclient is None:
raise ValueError("argument 'pbclient' must not be None")
if dc_id is None:
raise ValueError("argument 'dc_id' must not be None")
# list of all found server's info
server_in... |
def getServerStates(pbclient=None, dc_id=None, serverid=None, servername=None):
''' gets states of a server'''
if pbclient is None:
raise ValueError("argument 'pbclient' must not be None")
if dc_id is None:
raise ValueError("argument 'dc_id' must not be None")
server = None
if server... |
def wait_for_server(pbclient=None, dc_id=None, serverid=None,
indicator='state', state='AVAILABLE', timeout=300):
'''
wait for a server/VM to reach a defined state for a specified time
indicator := {state|vmstate} specifies if server or VM stat is tested
state specifies the status th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.