signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def gauss_fit(X, Y): | X = np.asarray(X)<EOL>Y = np.asarray(Y)<EOL>Y[Y < <NUM_LIT:0>] = <NUM_LIT:0><EOL>def gauss(x, a, x0, sigma):<EOL><INDENT>return a * np.exp(-(x - x0)**<NUM_LIT:2> / (<NUM_LIT:2> * sigma**<NUM_LIT:2>))<EOL><DEDENT>mean = (X * Y).sum() / Y.sum()<EOL>sigma = np.sqrt((Y * ((X - mean)**<NUM_LIT:2>)).sum() / Y.sum())<EOL>heig... | Fit the function to a gaussian.
Parameters
----------
X: 1d array
X values
Y: 1d array
Y values
Returns
-------
(The return from scipy.optimize.curve_fit)
popt : array
Optimal values for the parameters
pcov : 2d array
The estimated covariance of popt.
Notes
-----
/!\ This uses a slow curve_fit functi... | f2052:m16 |
def gauss_fit_log(X, Y): | X = np.asarray(X)<EOL>Y = np.asarray(Y)<EOL>Data = np.log(Y)<EOL>D = [(Data * X**i).sum() for i in range(<NUM_LIT:3>)]<EOL>X = [(X**i).sum() for i in range(<NUM_LIT:5>)]<EOL>num = (D[<NUM_LIT:0>] * (X[<NUM_LIT:1>] * X[<NUM_LIT:4>] - X[<NUM_LIT:2>] * X[<NUM_LIT:3>]) +<EOL>D[<NUM_LIT:1>] * (X[<NUM_LIT:2>]**<NUM_LIT:2> - ... | Fit the log of the input to the log of a gaussian.
Parameters
----------
X: 1d array
X values
Y: 1d array
Y values
Returns
-------
mean: number
The mean of the gaussian curve
var: number
The variance of the gaussian curve
Notes
-----
The least square method is used.
As this is a log, make sure the am... | f2052:m17 |
def center_of_mass(X, Y): | X = np.asarray(X)<EOL>Y = np.asarray(Y)<EOL>return (X * Y).sum() / Y.sum()<EOL> | Get center of mass
Parameters
----------
X: 1d array
X values
Y: 1d array
Y values
Returns
-------
res: number
The position of the center of mass in X
Notes
-----
Uses least squares | f2052:m18 |
def get_peak_pos(im, wrap=False): | im = np.asarray(im)<EOL>im[np.logical_not(np.isfinite(im))] = <NUM_LIT:0><EOL>im = im - im.mean()<EOL>argmax = im.argmax()<EOL>dsize = im.size<EOL>cut = <NUM_LIT> * im[argmax]<EOL>peak = im > cut<EOL>peak, __ = label(peak)<EOL>if wrap and peak[<NUM_LIT:0>] != <NUM_LIT:0> and peak[-<NUM_LIT:1>] != <NUM_LIT:0> and peak[<... | Get the peak position with subpixel precision
Parameters
----------
im: 2d array
The image containing a peak
wrap: boolean, defaults False
True if the image reoresents a torric world
Returns
-------
[y,x]: 2 numbers
The position of the highest peak with subpixel pre... | f2052:m19 |
def get_extent(origin, shape): | return [origin[<NUM_LIT:1>], origin[<NUM_LIT:1>] + shape[<NUM_LIT:1>], origin[<NUM_LIT:0>] + shape[<NUM_LIT:0>], origin[<NUM_LIT:0>]]<EOL> | Computes the extent for imshow() (see matplotlib doc)
Parameters
----------
origin: 2 numbers
The origin of the second image in the first image coordiantes
shape: 2 numbers
The shape of the image
Returns
-------
extent: 2 numbers
The extent | f2052:m20 |
def centered_mag_sq_ccs(im): | im = np.asarray(im)<EOL>im = cv2.mulSpectrums(im, im, flags=<NUM_LIT:0>, conjB=True)<EOL>ys = im.shape[<NUM_LIT:0>]<EOL>xs = im.shape[<NUM_LIT:1>]<EOL>ret = np.zeros((ys, xs // <NUM_LIT:2> + <NUM_LIT:1>))<EOL>ret[ys // <NUM_LIT:2>, <NUM_LIT:0>] = im[<NUM_LIT:0>, <NUM_LIT:0>]<EOL>ret[ys // <NUM_LIT:2> + <NUM_LIT:1>:, <N... | return centered squared magnitude
Parameters
----------
im: 2d array
A CCS DFT image
Returns
-------
im: 2d array
A centered image of the magnitude of the DFT
Notes
-----
Check doc Intel* Image Processing Library
https://www.comp.nus.edu.sg/~cs4243/doc/ipl.pdf
... | f2052:m21 |
def is_overexposed(ims): | if len(np.shape(ims)) == <NUM_LIT:3>:<EOL><INDENT>return [is_overexposed(im) for im in ims]<EOL><DEDENT>ims = np.array(ims, int)<EOL>diffbincount = np.diff(np.bincount(np.ravel(ims)))<EOL>overexposed = diffbincount[-<NUM_LIT:1>] > np.std(diffbincount)<EOL>return overexposed<EOL> | Simple test to check if image is overexposed
Parameters
----------
im: 2d array integer
the image
Returns
-------
overexposed: Bool
Is the image overexposed | f2052:m22 |
def channel_width(im, chanangle=None, *, chanapproxangle=None,<EOL>isccsedge=False): | <EOL>im = np.asarray(im)<EOL>if not isccsedge:<EOL><INDENT>im = reg.dft_optsize(np.float32(edge(im)))<EOL><DEDENT>truesize = im.shape<EOL>im = reg.centered_mag_sq_ccs(im)<EOL>if chanangle is None:<EOL><INDENT>chanangle = channel_angle(im, isshiftdftedge=True,<EOL>chanapproxangle=chanapproxangle,<EOL>truesize=truesize)<... | Get an estimation of the channel width.
Parameters:
-----------
im: 2d array
The channel image
chanangle: number, optional
The angle of the channel (None if unknown)
chanapproxangle: number, optional
If chanangle is None, the approximate channel angle
isccsedge: boolean,... | f2055:m0 |
def channel_angle(im, chanapproxangle=None, *, isshiftdftedge=False,<EOL>truesize=None): | im = np.asarray(im)<EOL>if not isshiftdftedge:<EOL><INDENT>im = edge(im)<EOL><DEDENT>return reg.orientation_angle(im, isshiftdft=isshiftdftedge,<EOL>approxangle=chanapproxangle,<EOL>truesize=truesize)<EOL> | Extract the channel angle from the rfft
Parameters:
-----------
im: 2d array
The channel image
chanapproxangle: number, optional
If not None, an approximation of the result
isshiftdftedge: boolean, default False
If The image has already been treated:
(edge, dft, ffts... | f2055:m1 |
def Scharr_edge(im, blurRadius=<NUM_LIT:10>, imblur=None): | im = np.asarray(im, dtype='<STR_LIT>')<EOL>blurRadius = <NUM_LIT:2> * blurRadius + <NUM_LIT:1><EOL>im = cv2.GaussianBlur(im, (blurRadius, blurRadius), <NUM_LIT:0>)<EOL>Gx = cv2.Scharr(im, -<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>)<EOL>Gy = cv2.Scharr(im, -<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:0>)<EOL>ret = cv2.magnitude(Gx, ... | Extract the edges using Scharr kernel (Sobel optimized for rotation
invariance)
Parameters:
-----------
im: 2d array
The image
blurRadius: number, default 10
The gaussian blur raduis (The kernel has size 2*blurRadius+1)
imblur: 2d array, OUT
If not None, will be fille wi... | f2055:m2 |
def edge(im): | <EOL>e0 = cv2.Canny(uint8sc(im), <NUM_LIT:100>, <NUM_LIT:200>)<EOL>return e0<EOL> | Extract the edges of an image
Parameters:
-----------
im: 2d array
The image
Returns:
--------
out: 2d array
The edges of the images computed with the Canny algorithm
Notes:
------
This scale the image to be used with Canny from OpenCV | f2055:m3 |
def register_channel(im0, im1, scale=None, ch0angle=None,<EOL>chanapproxangle=None): | im0 = np.asarray(im0)<EOL>im1 = np.asarray(im1)<EOL>e0 = edge(im0)<EOL>e1 = edge(im1)<EOL>fe0, fe1 = reg.dft_optsize_same(np.float32(e0), np.float32(e1))<EOL>w0, a0 = channel_width(<EOL>fe0, isccsedge=True, chanapproxangle=chanapproxangle)<EOL>w1, a1 = channel_width(<EOL>fe1, isccsedge=True, chanapproxangle=chanapproxa... | Register the images assuming they are channels
Parameters:
-----------
im0: 2d array
The first image
im1: 2d array
The second image
scale: number, optional
The scale difference if known
ch0angle: number, optional
The angle of the channel in the first image if kno... | f2055:m4 |
def uint8sc(im): | im = np.asarray(im)<EOL>immin = im.min()<EOL>immax = im.max()<EOL>imrange = immax - immin<EOL>return cv2.convertScaleAbs(im - immin, alpha=<NUM_LIT:255> / imrange)<EOL> | Scale the image to uint8
Parameters:
-----------
im: 2d array
The image
Returns:
--------
im: 2d array (dtype uint8)
The scaled image to uint8 | f2055:m5 |
def intercept(actions: dict={}): | for action in actions.values():<EOL><INDENT>if type(action) is not returns and type(action) is not raises:<EOL><INDENT>raise InterceptorError('<STR_LIT>')<EOL><DEDENT><DEDENT>def decorated(f):<EOL><INDENT>def wrapped(*args, **kargs):<EOL><INDENT>try:<EOL><INDENT>return f(*args, **kargs)<EOL><DEDENT>except Exception as ... | Decorates a function and handles any exceptions that may rise.
Args:
actions: A dictionary ``<exception type>: <action>``. Available actions\
are :class:`raises` and :class:`returns`.
Returns:
Any value declared using a :class:`returns` action.
Raises:
AnyException: if AnyException is declared to... | f2059:m0 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/os/list
GET - public
Retrieve a list of available operating systems. If
the 'windows' flag is true, a Windows licenses will
be included with the instance, which will increase the cost.
Link: https://www.vultr.com/api/#os_os_list | f2065:c0:m1 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/app/list
GET - account
Retrieve a list of available applications. These
refer to applications that can be launched when
creating a Vultr VPS.
Link: https://www.vultr.com/api/#app_app_list | f2066:c0:m1 |
def bandwidth(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/bandwidth
GET - account
Get the bandwidth used by a virtual machine
Link: https://www.vultr.com/api/#server_bandwidth | f2067:c0:m1 |
def create(self, dcid, vpsplanid, osid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': dcid,<EOL>'<STR_LIT>': vpsplanid,<EOL>'<STR_LIT>': osid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/create
POST - account
Create a new virtual machine. You will start being billed for this
immediately. The response only contains the SUBID for the new machine.
You should use v1/server/list to poll and wait for the machine to be
created (as this does not happen instant... | f2067:c0:m2 |
def destroy(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/destroy
POST - account
Destroy (delete) a virtual machine. All data will be permanently lost,
and the IP address will be released. There is no going back from this
call.
Link: https://www.vultr.com/api/#server_destroy | f2067:c0:m3 |
def get_user_data(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/get_user_data
GET - account
Retrieves the (base64 encoded) user-data for this subscription.
Link: https://www.vultr.com/api/#server_get_user_data | f2067:c0:m4 |
def halt(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/halt
POST - account
Halt a virtual machine. This is a hard power off (basically, unplugging
the machine). The data on the machine will not be modified, and you
will still be billed for the machine. To completely delete a
machine, see v1/server/destroy
Link: ht... | f2067:c0:m5 |
def label_set(self, subid, label, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT:label>': label<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/label_set
POST - account
Set the label of a virtual machine.
Link: https://www.vultr.com/api/#server_label_set | f2067:c0:m6 |
def list(self, subid=None, params=None): | params = update_params(<EOL>params,<EOL>{'<STR_LIT>': subid} if subid else dict()<EOL>)<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/list
GET - account
List all active or pending virtual machines on the current account. The
'status' field represents the status of the subscription and will be
one of pending|active|suspended|closed. If the status is 'active', you
can check 'power_status' to determine ... | f2067:c0:m7 |
def neighbors(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | v1/server/neighbors
GET - account
Determine what other subscriptions are hosted on the same physical
host as a given subscription.
Link: https://www.vultr.com/api/#server_neighbors | f2067:c0:m8 |
def os_change(self, subid, osid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': osid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/os_change
POST - account
Changes the operating system of a virtual machine. All data will be
permanently lost.
Link: https://www.vultr.com/api/#server_os_change | f2067:c0:m9 |
def os_change_list(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/os_change_list
GET - account
Retrieves a list of operating systems to which this server can be
changed.
Link: https://www.vultr.com/api/#server_os_change_list | f2067:c0:m10 |
def reboot(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/reboot
POST - account
Reboot a virtual machine. This is a hard reboot
(basically, unplugging the machine).
Link: https://www.vultr.com/api/#server_reboot | f2067:c0:m11 |
def reinstall(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/reinstall
POST - account
Reinstall the operating system on a virtual machine. All data
will be permanently lost, but the IP address will remain the
same There is no going back from this call.
Link: https://www.vultr.com/api/#server_reinstall | f2067:c0:m12 |
def restore_backup(self, subid, backupid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': backupid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/restore_backup
POST - account
Restore the specified backup to the virtual machine. Any data
already on the virtual machine will be lost.
Link: https://www.vultr.com/api/#server_restore_backup | f2067:c0:m13 |
def restore_snapshot(self, subid, snapshotid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': snapshotid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/restore_snapshot
POST - account
Restore the specificed snapshot to the virtual machine.
Any data already on the virtual machine will be lost.
Link: https://www.vultr.com/api/#server_restore_snapshot | f2067:c0:m14 |
def set_user_data(self, subid, userdata, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': userdata<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/set_user_data
POST - account
Sets the cloud-init user-data (base64) for this subscription.
Note that user-data is not supported on every operating
system, and is generally only provided on instance startup.
Link: https://www.vultr.com/api/#server_set_user_data | f2067:c0:m15 |
def start(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/start
POST - account
Start a virtual machine. If the machine is already
running, it will be restarted.
Link: https://www.vultr.com/api/#server_start | f2067:c0:m16 |
def upgrade_plan(self, subid, vpsplanid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': vpsplanid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/upgrade_plan
POST - account
Upgrade the plan of a virtual machine. The virtual machine will be
rebooted upon a successful upgrade.
Link: https://www.vultr.com/api/#server_upgrade_plan | f2067:c0:m17 |
def upgrade_plan_list(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/upgrade_plan_list
GET - account
Retrieve a list of the VPSPLANIDs for which a virtual machine
can be upgraded. An empty response array means that there are
currently no upgrades available.
Link: https://www.vultr.com/api/#server_upgrade_plan_list | f2067:c0:m18 |
def create_domain(self, domain, ipaddr, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': domain,<EOL>'<STR_LIT>': ipaddr<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/dns/create_domain
POST - account
Create a domain name in DNS
Link: https://www.vultr.com/api/#dns_create_domain | f2068:c0:m1 |
def create_record(self, domain, name, _type, data, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': domain,<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT:type>': _type,<EOL>'<STR_LIT:data>': data<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/dns/create_domain
POST - account
Add a DNS record
Link: https://www.vultr.com/api/#dns_create_record | f2068:c0:m2 |
def delete_domain(self, domain, params=None): | params = update_params(params, {'<STR_LIT>': domain})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/dns/delete_domain
POST - account
Delete a domain name (and all associated records)
Link: https://www.vultr.com/api/#dns_delete_domain | f2068:c0:m3 |
def delete_record(self, domain, recordid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': domain,<EOL>'<STR_LIT>': recordid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/dns/delete_record
POST - account
Deletes an individual DNS record
Link: https://www.vultr.com/api/#dns_delete_record | f2068:c0:m4 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/dns/list
GET - account
List all domains associated with the current account
Link: https://www.vultr.com/api/#dns_dns_list | f2068:c0:m5 |
def records(self, domain, params=None): | params = update_params(params, {'<STR_LIT>': domain})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/dns/records
GET - account
List all the records associated with a particular domain
Link: https://www.vultr.com/api/#dns_records | f2068:c0:m6 |
def update_record(self, domain, recordid, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': domain,<EOL>'<STR_LIT>': recordid<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/dns/update_record
POST - account
Update a DNS record
Link: https://www.vultr.com/api/#dns_update_record | f2068:c0:m7 |
def create(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/create_ipv4
POST - account
Add a new IPv4 address to a server. You will start being billed for
this immediately. The server will be rebooted unless you specify
otherwise. You must reboot the server before the IPv4 address can be
configured.
Link: https://www.v... | f2069:c0:m1 |
def destroy(self, subid, ipaddr, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': ipaddr<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/destroy_ipv4
POST - account
Removes a secondary IPv4 address from a server. Your server will be
hard-restarted. We suggest halting the machine gracefully before
removing IPs.
Link: https://www.vultr.com/api/#server_destroy_ipv4 | f2069:c0:m2 |
def list(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/list_ipv4
GET - account
List the IPv4 information of a virtual machine. IP information is only
available for virtual machines in the "active" state.
Link: https://www.vultr.com/api/#server_list_ipv4 | f2069:c0:m3 |
def reverse_default(self, subid, ipaddr, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': ipaddr<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/reverse_default_ipv4
POST - account
Set a reverse DNS entry for an IPv4 address of a virtual
machine to the original setting. Upon success, DNS changes
may take 6-12 hours to become active.
Link: https://www.vultr.com/api/#server_reverse_default_ipv4 | f2069:c0:m4 |
def reverse_set(self, subid, ipaddr, entry, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': ipaddr,<EOL>'<STR_LIT>': entry<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/reverse_set_ipv4
POST - account
Set a reverse DNS entry for an IPv4 address of a virtual machine. Upon
success, DNS changes may take 6-12 hours to become active.
Link: https://www.vultr.com/api/#server_reverse_set_ipv4 | f2069:c0:m5 |
def info(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/account/info
GET - account
Retrieve information about the current account
Link: https://www.vultr.com/api/#account_info | f2070:c0:m1 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/iso/list
GET - account
List all ISOs currently available on this account
Link: https://www.vultr.com/api/#iso_iso_list | f2071:c0:m1 |
def create_from_url(self, url, params=None): | params = update_params(params, {<EOL>'<STR_LIT:url>': url,<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /vi/iso/create_from_url
POST - account
Create a new ISO image on the current account.
The ISO image will be downloaded from a given URL.
Download status can be checked with the v1/iso/list call.
Link: https://www.vultr.com/api/#iso_create_from_url | f2071:c0:m2 |
def create(self, dcid, ip_type, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': dcid,<EOL>'<STR_LIT>': ip_type<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/reservedip/create
POST - account
Create a new reserved IP. Reserved IPs can only be used within the
same datacenter for which they were created.
Link: https://www.vultr.com/api/#reservedip_create | f2072:c0:m1 |
def group_list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/firewall/group_list
GET - account
List all firewall groups on the current account.
Link: https://www.vultr.com/api/#firewall_group_list | f2073:c0:m1 |
def create(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/snapshot/create
POST - account
Create a snapshot from an existing virtual machine.
The virtual machine does not need to be stopped.
Link: https://www.vultr.com/api/#snapshot_create | f2074:c0:m1 |
def destroy(self, snapshotid, params=None): | params = update_params(params, {'<STR_LIT>': snapshotid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/snapshot/destroy
POST - account
Destroy (delete) a snapshot. There is no going
back from this call.
Link: https://www.vultr.com/api/#snapshot_destroy | f2074:c0:m2 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/snapshot/list
GET - account
List all snapshots on the current account
Link: https://www.vultr.com/api/#snapshot_snapshot_list | f2074:c0:m3 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/backup/list
GET - account
List all backups on the current account
Link: https://www.vultr.com/api/#backup_backup_list | f2076:c0:m1 |
def availability(self, dcid, params=None): | params = update_params(params, {'<STR_LIT>': dcid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/regions/availability
GET - public
Retrieve a list of the VPSPLANIDs currently available
in this location. If your account has special plans available,
you will need to pass your api_key in in order to see them.
For all other accounts, the API key is not optional.
Lin... | f2077:c0:m1 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/regions/list
GET - public
Retrieve a list of all active regions. Note that just
because a region is listed here, does not mean that
there is room for new servers.
Link: https://www.vultr.com/api/#regions_region_list | f2077:c0:m2 |
def update_params(params, updates): | params = params.copy() if isinstance(params, dict) else dict()<EOL>params.update(updates)<EOL>return params<EOL> | Merges updates into params | f2078:m0 |
def set_requests_per_second(self, req_per_second): | self.req_per_second = req_per_second<EOL>self.req_duration = <NUM_LIT:1> / self.req_per_second<EOL> | Adjusts the request/second at run-time | f2078:c1:m1 |
def _request_get_helper(self, url, params=None): | if not isinstance(params, dict):<EOL><INDENT>params = dict()<EOL><DEDENT>if self.api_key:<EOL><INDENT>params['<STR_LIT>'] = self.api_key<EOL><DEDENT>return requests.get(url, params=params, timeout=<NUM_LIT>)<EOL> | API GET request helper | f2078:c1:m2 |
def _request_post_helper(self, url, params=None): | if self.api_key:<EOL><INDENT>query = {'<STR_LIT>': self.api_key}<EOL><DEDENT>return requests.post(url, params=query, data=params, timeout=<NUM_LIT>)<EOL> | API POST helper | f2078:c1:m3 |
def _request_helper(self, url, params, method): | try:<EOL><INDENT>if method == '<STR_LIT:POST>':<EOL><INDENT>return self._request_post_helper(url, params)<EOL><DEDENT>elif method == '<STR_LIT:GET>':<EOL><INDENT>return self._request_get_helper(url, params)<EOL><DEDENT>raise VultrError('<STR_LIT>' % method)<EOL><DEDENT>except requests.RequestException as ex:<EOL><INDEN... | API request helper method | f2078:c1:m4 |
def request(self, path, params=None, method='<STR_LIT:GET>'): | _start = time.time()<EOL>if not path.startswith('<STR_LIT:/>'):<EOL><INDENT>path = '<STR_LIT:/>' + path<EOL><DEDENT>resp = self._request_helper(self.api_endpoint + path, params, method)<EOL>if resp.status_code != <NUM_LIT:200>:<EOL><INDENT>if resp.status_code == <NUM_LIT>:<EOL><INDENT>raise VultrError('<STR_LIT>' +<EOL... | API request / call method | f2078:c1:m5 |
def create(self, name, script, params=None): | params = update_params(params, {<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT>': script<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/startupscript/create
POST - account
Create a startup script
Link: https://www.vultr.com/api/#startupscript_create | f2079:c0:m1 |
def destroy(self, scriptid, params=None): | params = update_params(params, {'<STR_LIT>': scriptid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/startupscript/destroy
POST - account
Remove a startup script
Link: https://www.vultr.com/api/#startupscript_destroy | f2079:c0:m2 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/startupscript/list
GET - account
List all startup scripts on the current account. 'boot' type
scripts are executed by the server's operating system on the
first boot. 'pxe' type scripts are executed by iPXE when the
server itself starts up.
Link: https://www.vultr.co... | f2079:c0:m3 |
def update(self, scriptid, params=None): | params = update_params(params, {'<STR_LIT>': scriptid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/startupscript/update
POST - account
Update an existing startup script
Link: https://www.vultr.com/api/#startupscript_update | f2079:c0:m4 |
def create(self, name, ssh_key, params=None): | params = update_params(params, {<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT>': ssh_key<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/sshkey/create
POST - account
Create a new SSH Key
Link: https://www.vultr.com/api/#sshkey_create | f2080:c0:m1 |
def destroy(self, sshkeyid, params=None): | params = update_params(params, {'<STR_LIT>': sshkeyid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/sshkey/destroy
POST - account
Remove a SSH key. Note that this will not remove
the key from any machines that already have it.
Link: https://www.vultr.com/api/#sshkey_destroy | f2080:c0:m2 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/sshkey/list
GET - account
List all the SSH keys on the current account
Link: https://www.vultr.com/api/#sshkey_list | f2080:c0:m3 |
def update(self, sshkeyid, params=None): | params = update_params(params, {'<STR_LIT>': sshkeyid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/sshkey/update
POST - account
Update an existing SSH Key. Note that this will only
update newly installed machines. The key will not be
updated on any existing machines.
Link: https://www.vultr.com/api/#sshkey_update | f2080:c0:m4 |
def list(self, params=None): | params = params if params else dict()<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/plans/list
GET - public
Retrieve a list of all active plans. Plans that are
no longer available will not be shown. The 'windows'
field is no longer in use, and will always be false.
Windows licenses will be automatically added to any
plan as necessary. If your account... | f2082:c0:m1 |
def list_ipv6(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/list_ipv6
GET - account
List the IPv6 information of a virtual machine. IP information is only
available for virtual machines in the "active" state. If the virtual
machine does not have IPv6 enabled, then an empty array is returned.
Link: https://www.vultr.com/api/#se... | f2083:c0:m1 |
def reverse_delete_ipv6(self, subid, ipaddr, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': ipaddr<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/reverse_delete_ipv6
POST - account
Remove a reverse DNS entry for an IPv6 address of a virtual machine.
Upon success, DNS changes may take 6-12 hours to become active.
Link: https://www.vultr.com/api/#server_reverse_delete_ipv6 | f2083:c0:m2 |
def reverse_list_ipv6(self, subid, params=None): | params = update_params(params, {'<STR_LIT>': subid})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:GET>')<EOL> | /v1/server/reverse_list_ipv6
GET - account
List the IPv6 reverse DNS entries of a virtual machine. Reverse DNS
entries are only available for virtual machines in the "active" state.
If the virtual machine does not have IPv6 enabled, then an empty array
is returned.
Link:... | f2083:c0:m3 |
def reverse_set_ipv6(self, subid, ipaddr, entry, params=None): | params = update_params(params, {<EOL>'<STR_LIT>': subid,<EOL>'<STR_LIT>': ipaddr,<EOL>'<STR_LIT>': entry<EOL>})<EOL>return self.request('<STR_LIT>', params, '<STR_LIT:POST>')<EOL> | /v1/server/reverse_set_ipv6
POST - account
Set a reverse DNS entry for an IPv6 address of a virtual machine. Upon
success, DNS changes may take 6-12 hours to become active.
Link: https://www.vultr.com/api/#server_reverse_set_ipv6 | f2083:c0:m4 |
def halt_running(): | vultr = Vultr(API_KEY)<EOL>try:<EOL><INDENT>serverList = vultr.server.list()<EOL><DEDENT>except VultrError as ex:<EOL><INDENT>logging.error('<STR_LIT>', ex)<EOL><DEDENT>for serverID in serverList:<EOL><INDENT>if serverList[serverID]['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>logging.info(serverList[serverID]['<STR_LIT:la... | Halts all running servers | f2084:m0 |
def main(): | logging.info('<STR_LIT>')<EOL>logging.info('<STR_LIT>')<EOL>halt_running()<EOL> | Entry point | f2084:m1 |
def dump_info(): | vultr = Vultr(API_KEY)<EOL>try:<EOL><INDENT>logging.info('<STR_LIT>', dumps(<EOL>vultr.account.info(), indent=<NUM_LIT:2><EOL>))<EOL>logging.info('<STR_LIT>', dumps(<EOL>vultr.app.list(), indent=<NUM_LIT:2><EOL>))<EOL>logging.info('<STR_LIT>', dumps(<EOL>vultr.backup.list(), indent=<NUM_LIT:2><EOL>))<EOL>logging.info('... | Shows various details about the account & servers | f2085:m0 |
def main(): | logging.info('<STR_LIT>')<EOL>logging.info('<STR_LIT>')<EOL>dump_info()<EOL> | Entry point | f2085:m1 |
def servers_running(): | vultr = Vultr(API_KEY)<EOL>try:<EOL><INDENT>serverList = vultr.server.list()<EOL><DEDENT>except VultrError as ex:<EOL><INDENT>logging.error('<STR_LIT>', ex)<EOL><DEDENT>for serverID in serverList:<EOL><INDENT>if serverList[serverID]['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>logging.info(serverList[serverID]['<STR_LIT:la... | Shows running servers | f2086:m0 |
def main(): | logging.info('<STR_LIT>')<EOL>logging.info('<STR_LIT>')<EOL>servers_running()<EOL> | Entry point | f2086:m1 |
def read(filename): | return open(filename).read()<EOL> | Read content from file | f2087:m0 |
def update(self): | url = self.baseurl + '<STR_LIT>'<EOL>response = self.s.get(url)<EOL>response.raise_for_status()<EOL>from xml.etree.ElementTree import XML<EOL>root = XML(response.text)<EOL>for serv_el in root.iter('<STR_LIT>'):<EOL><INDENT>serv = Monit.Service(self, serv_el)<EOL>self[serv.name] = serv<EOL>if self[serv.name].pendingacti... | Update Monit deamon and services status. | f2088:c0:m1 |
def render(self, bindings): | out = []<EOL>binding = False<EOL>for segment in self.segments:<EOL><INDENT>if segment.kind == _BINDING:<EOL><INDENT>if segment.literal not in bindings:<EOL><INDENT>raise ValidationException(<EOL>('<STR_LIT>'<EOL>'<STR_LIT>').format(segment.literal))<EOL><DEDENT>out.extend(PathTemplate(bindings[segment.literal]).segment... | Renders a string from a path template using the provided bindings.
Args:
bindings (dict): A dictionary of var names to binding strings.
Returns:
str: The rendered instantiation of this path template.
Raises:
ValidationError: If a key isn't provided or if a ... | f2092:c1:m3 |
def match(self, path): | this = self.segments<EOL>that = path.split('<STR_LIT:/>')<EOL>current_var = None<EOL>bindings = {}<EOL>segment_count = self.segment_count<EOL>j = <NUM_LIT:0><EOL>for i in range(<NUM_LIT:0>, len(this)):<EOL><INDENT>if j >= len(that):<EOL><INDENT>break<EOL><DEDENT>if this[i].kind == _TERMINAL:<EOL><INDENT>if this[i].lite... | Matches a fully qualified path template string.
Args:
path (str): A fully qualified path template string.
Returns:
dict: Var names to matched binding values.
Raises:
ValidationException: If path can't be matched to the template. | f2092:c1:m4 |
def parse(self, data): | self.binding_var_count = <NUM_LIT:0><EOL>self.segment_count = <NUM_LIT:0><EOL>segments = self.parser.parse(data)<EOL>path_wildcard = False<EOL>for segment in segments:<EOL><INDENT>if segment.kind == _TERMINAL and segment.literal == '<STR_LIT>':<EOL><INDENT>if path_wildcard:<EOL><INDENT>raise ValidationException(<EOL>'<... | Returns a list of path template segments parsed from data.
Args:
data: A path template string.
Returns:
A list of _Segment. | f2092:c2:m1 |
def p_template(self, p): | <EOL>p[<NUM_LIT:0>] = p[len(p) - <NUM_LIT:1>]<EOL> | template : FORWARD_SLASH bound_segments
| bound_segments | f2092:c2:m2 |
def p_bound_segments(self, p): | p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>if len(p) > <NUM_LIT:2>:<EOL><INDENT>p[<NUM_LIT:0>].extend(p[<NUM_LIT:3>])<EOL><DEDENT> | bound_segments : bound_segment FORWARD_SLASH bound_segments
| bound_segment | f2092:c2:m3 |
def p_unbound_segments(self, p): | p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL>if len(p) > <NUM_LIT:2>:<EOL><INDENT>p[<NUM_LIT:0>].extend(p[<NUM_LIT:3>])<EOL><DEDENT> | unbound_segments : unbound_terminal FORWARD_SLASH unbound_segments
| unbound_terminal | f2092:c2:m4 |
def p_bound_segment(self, p): | p[<NUM_LIT:0>] = p[<NUM_LIT:1>]<EOL> | bound_segment : bound_terminal
| variable | f2092:c2:m5 |
def p_unbound_terminal(self, p): | p[<NUM_LIT:0>] = [_Segment(_TERMINAL, p[<NUM_LIT:1>])]<EOL>self.segment_count += <NUM_LIT:1><EOL> | unbound_terminal : WILDCARD
| PATH_WILDCARD
| LITERAL | f2092:c2:m6 |
def p_bound_terminal(self, p): | if p[<NUM_LIT:1>][<NUM_LIT:0>].literal in ['<STR_LIT:*>', '<STR_LIT>']:<EOL><INDENT>p[<NUM_LIT:0>] = [_Segment(_BINDING, '<STR_LIT>' % self.binding_var_count),<EOL>p[<NUM_LIT:1>][<NUM_LIT:0>],<EOL>_Segment(_END_BINDING, '<STR_LIT>')]<EOL>self.binding_var_count += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>]... | bound_terminal : unbound_terminal | f2092:c2:m7 |
def p_variable(self, p): | p[<NUM_LIT:0>] = [_Segment(_BINDING, p[<NUM_LIT:2>])]<EOL>if len(p) > <NUM_LIT:4>:<EOL><INDENT>p[<NUM_LIT:0>].extend(p[<NUM_LIT:4>])<EOL><DEDENT>else:<EOL><INDENT>p[<NUM_LIT:0>].append(_Segment(_TERMINAL, '<STR_LIT:*>'))<EOL>self.segment_count += <NUM_LIT:1><EOL><DEDENT>p[<NUM_LIT:0>].append(_Segment(_END_BINDING, '<ST... | variable : LEFT_BRACE LITERAL EQUALS unbound_segments RIGHT_BRACE
| LEFT_BRACE LITERAL RIGHT_BRACE | f2092:c2:m8 |
def p_error(self, p): | if p:<EOL><INDENT>raise ValidationException(<EOL>'<STR_LIT>' % p.type)<EOL><DEDENT>else:<EOL><INDENT>raise ValidationException('<STR_LIT>')<EOL><DEDENT> | Raises a parser error. | f2092:c2:m9 |
def t_error(self, t): | raise ValidationException(<EOL>'<STR_LIT>' % t.value[<NUM_LIT:0>])<EOL> | Raises a lexer error. | f2092:c2:m10 |
def load_library(self,libname): | paths = self.getpaths(libname)<EOL>for path in paths:<EOL><INDENT>if os.path.exists(path):<EOL><INDENT>return self.load(path)<EOL><DEDENT><DEDENT>raise ImportError("<STR_LIT>" % libname)<EOL> | Given the name of a library, load it. | f2105:c5:m1 |
def load(self,path): | try:<EOL><INDENT>if sys.platform == '<STR_LIT>':<EOL><INDENT>return ctypes.CDLL(path, ctypes.RTLD_GLOBAL)<EOL><DEDENT>else:<EOL><INDENT>return ctypes.cdll.LoadLibrary(path)<EOL><DEDENT><DEDENT>except OSError as e:<EOL><INDENT>raise ImportError(e)<EOL><DEDENT> | Given a path to a library, load it. | f2105:c5:m2 |
def getpaths(self,libname): | if os.path.isabs(libname):<EOL><INDENT>yield libname<EOL><DEDENT>else:<EOL><INDENT>for path in self.getplatformpaths(libname):<EOL><INDENT>yield path<EOL><DEDENT>path = ctypes.util.find_library(libname)<EOL>if path: yield path<EOL><DEDENT> | Return a list of paths where the library might be found. | f2105:c5:m3 |
def getdirs(self,libname): | dyld_fallback_library_path = _environ_path("<STR_LIT>")<EOL>if not dyld_fallback_library_path:<EOL><INDENT>dyld_fallback_library_path = [os.path.expanduser('<STR_LIT>'),<EOL>'<STR_LIT>', '<STR_LIT>']<EOL><DEDENT>dirs = []<EOL>if '<STR_LIT:/>' in libname:<EOL><INDENT>dirs.extend(_environ_path("<STR_LIT>"))<EOL><DEDENT>e... | Implements the dylib search as specified in Apple documentation:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/
DynamicLibraries/Articles/DynamicLibraryUsageGuidelines.html
Before commencing the standard search, the method first checks
the bundle's ``Frameworks... | f2105:c6:m1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.