003 File Manager
Current Path:
/usr/local/lib/python3.8/site-packages/libcloud/compute/drivers
usr
/
local
/
lib
/
python3.8
/
site-packages
/
libcloud
/
compute
/
drivers
/
📁
..
📄
__init__.py
(1.18 KB)
📁
__pycache__
📄
abiquo.py
(30.79 KB)
📄
auroracompute.py
(1.99 KB)
📄
azure.py
(110.57 KB)
📄
azure_arm.py
(81.18 KB)
📄
bluebox.py
(7.25 KB)
📄
brightbox.py
(10.6 KB)
📄
bsnl.py
(1.91 KB)
📄
cloudscale.py
(8.64 KB)
📄
cloudsigma.py
(67.16 KB)
📄
cloudstack.py
(159.99 KB)
📄
cloudwatt.py
(4.97 KB)
📄
digitalocean.py
(26.89 KB)
📄
dimensiondata.py
(185.11 KB)
📄
dummy.py
(10.81 KB)
📄
ec2.py
(216.23 KB)
📄
ecp.py
(11.45 KB)
📄
ecs.py
(62.32 KB)
📄
elastichosts.py
(7.27 KB)
📄
elasticstack.py
(15.96 KB)
📄
equinixmetal.py
(33.73 KB)
📄
exoscale.py
(1.13 KB)
📄
gandi.py
(25.69 KB)
📄
gce.py
(381.02 KB)
📄
gig_g8.py
(21.5 KB)
📄
gogrid.py
(14.89 KB)
📄
gridscale.py
(34.55 KB)
📄
gridspot.py
(4.14 KB)
📄
hostvirtual.py
(14.09 KB)
📄
ikoula.py
(1.14 KB)
📄
indosat.py
(1.95 KB)
📄
internetsolutions.py
(2 KB)
📄
joyent.py
(8.02 KB)
📄
kamatera.py
(22.93 KB)
📄
kili.py
(3.12 KB)
📄
ktucloud.py
(3.51 KB)
📄
kubevirt.py
(50.35 KB)
📄
libvirt_driver.py
(14.33 KB)
📄
linode.py
(58.85 KB)
📄
maxihost.py
(8.22 KB)
📄
medone.py
(1.94 KB)
📄
nephoscale.py
(17.28 KB)
📄
ntta.py
(1.96 KB)
📄
nttcis.py
(217.71 KB)
📄
onapp.py
(16.12 KB)
📄
oneandone.py
(56.4 KB)
📄
opennebula.py
(42.33 KB)
📄
openstack.py
(154.85 KB)
📄
outscale.py
(285.94 KB)
📄
ovh.py
(19.11 KB)
📄
profitbricks.py
(117.97 KB)
📄
rackspace.py
(9.22 KB)
📄
rimuhosting.py
(12 KB)
📄
scaleway.py
(23.66 KB)
📄
serverlove.py
(2.87 KB)
📄
skalicloud.py
(2.85 KB)
📄
softlayer.py
(17.5 KB)
📄
upcloud.py
(10.89 KB)
📄
vcl.py
(8.64 KB)
📄
vcloud.py
(92.5 KB)
📄
voxel.py
(10.67 KB)
📄
vpsnet.py
(6.56 KB)
📄
vsphere.py
(76.51 KB)
📄
vultr.py
(28.4 KB)
Editing: vpsnet.py
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ VPS.net driver """ import base64 try: import simplejson as json except ImportError: import json from libcloud.utils.py3 import b from libcloud.common.base import ConnectionUserAndKey, JsonResponse from libcloud.common.types import InvalidCredsError, MalformedResponseError from libcloud.compute.providers import Provider from libcloud.compute.types import NodeState from libcloud.compute.base import Node, NodeDriver from libcloud.compute.base import NodeSize, NodeImage, NodeLocation API_HOST = 'api.vps.net' API_VERSION = 'api10json' RAM_PER_NODE = 256 DISK_PER_NODE = 10 BANDWIDTH_PER_NODE = 250 class VPSNetResponse(JsonResponse): def parse_body(self): try: return super(VPSNetResponse, self).parse_body() except MalformedResponseError: return self.body def success(self): # vps.net wrongly uses 406 for invalid auth creds if self.status == 406 or self.status == 403: raise InvalidCredsError() return True def parse_error(self): try: errors = super(VPSNetResponse, self).parse_body()['errors'][0] except MalformedResponseError: return self.body else: return "\n".join(errors) class VPSNetConnection(ConnectionUserAndKey): """ Connection class for the VPS.net driver """ host = API_HOST responseCls = VPSNetResponse allow_insecure = False def add_default_headers(self, headers): user_b64 = base64.b64encode(b('%s:%s' % (self.user_id, self.key))) headers['Authorization'] = 'Basic %s' % (user_b64.decode('utf-8')) return headers class VPSNetNodeDriver(NodeDriver): """ VPS.net node driver """ type = Provider.VPSNET api_name = 'vps_net' name = "vps.net" website = 'http://vps.net/' connectionCls = VPSNetConnection def _to_node(self, vm): if vm['running']: state = NodeState.RUNNING else: state = NodeState.PENDING n = Node(id=vm['id'], name=vm['label'], state=state, public_ips=[vm.get('primary_ip_address', None)], private_ips=[], extra={'slices_count': vm['slices_count']}, # Number of nodes consumed by VM driver=self.connection.driver) return n def _to_image(self, image, cloud): image = NodeImage(id=image['id'], name="%s: %s" % (cloud, image['label']), driver=self.connection.driver) return image def _to_size(self, num): size = NodeSize(id=num, name="%d Node" % (num,), ram=RAM_PER_NODE * num, disk=DISK_PER_NODE, bandwidth=BANDWIDTH_PER_NODE * num, price=self._get_price_per_node(num) * num, driver=self.connection.driver) return size def _get_price_per_node(self, num): single_node_price = self._get_size_price(size_id='1') return num * single_node_price def create_node(self, name, image, size, ex_backups_enabled=False, ex_fqdn=None): """Create a new VPS.net node @inherits: :class:`NodeDriver.create_node` :keyword ex_backups_enabled: Enable automatic backups :type ex_backups_enabled: ``bool`` :keyword ex_fqdn: Fully Qualified domain of the node :type ex_fqdn: ``str`` """ ex_backups_enabled = 1 if ex_backups_enabled else 0 headers = {'Content-Type': 'application/json'} request = {'virtual_machine': {'label': name, 'fqdn': ex_fqdn or '', 'system_template_id': image.id, 'backups_enabled': ex_backups_enabled, 'slices_required': size.id}} res = self.connection.request('/virtual_machines.%s' % (API_VERSION,), data=json.dumps(request), headers=headers, method='POST') node = self._to_node(res.object['virtual_machine']) return node def reboot_node(self, node): res = self.connection.request( '/virtual_machines/%s/%s.%s' % (node.id, 'reboot', API_VERSION), method="POST") node = self._to_node(res.object['virtual_machine']) return True def list_sizes(self, location=None): res = self.connection.request('/nodes.%s' % (API_VERSION,)) available_nodes = len([size for size in res.object if size['slice']['virtual_machine_id']]) sizes = [self._to_size(i) for i in range(1, available_nodes + 1)] return sizes def destroy_node(self, node): res = self.connection.request('/virtual_machines/%s.%s' % (node.id, API_VERSION), method='DELETE') return res.status == 200 def list_nodes(self): res = self.connection.request('/virtual_machines.%s' % (API_VERSION,)) return [self._to_node(i['virtual_machine']) for i in res.object] def list_images(self, location=None): res = self.connection.request('/available_clouds.%s' % (API_VERSION,)) images = [] for cloud in res.object: label = cloud['cloud']['label'] templates = cloud['cloud']['system_templates'] images.extend([self._to_image(image, label) for image in templates]) return images def list_locations(self): return [NodeLocation(0, "VPS.net Western US", 'US', self)]
Upload File
Create Folder