/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
libcloud
/
compute
/
drivers
/
/opt/imh-python/lib/python3.9/site-packages/libcloud/compute/drivers
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
abiquo.py
31529
0644
edit
dl
rm
auroracompute.py
2040
0644
edit
dl
rm
azure.py
113227
0644
edit
dl
rm
azure_arm.py
83132
0644
edit
dl
rm
bluebox.py
7426
0644
edit
dl
rm
brightbox.py
10859
0644
edit
dl
rm
bsnl.py
1958
0644
edit
dl
rm
cloudscale.py
8844
0644
edit
dl
rm
cloudsigma.py
68769
0644
edit
dl
rm
cloudstack.py
163834
0644
edit
dl
rm
cloudwatt.py
5094
0644
edit
dl
rm
digitalocean.py
27064
0644
edit
dl
rm
dimensiondata.py
189557
0644
edit
dl
rm
dummy.py
11074
0644
edit
dl
rm
ec2.py
219386
0644
edit
dl
rm
ecp.py
11723
0644
edit
dl
rm
ecs.py
63818
0644
edit
dl
rm
elastichosts.py
7441
0644
edit
dl
rm
elasticstack.py
16348
0644
edit
dl
rm
exoscale.py
1159
0644
edit
dl
rm
gandi.py
26305
0644
edit
dl
rm
gce.py
389086
0644
edit
dl
rm
gig_g8.py
22013
0644
edit
dl
rm
gogrid.py
15250
0644
edit
dl
rm
gridscale.py
35381
0644
edit
dl
rm
gridspot.py
4243
0644
edit
dl
rm
hostvirtual.py
14427
0644
edit
dl
rm
ikoula.py
1172
0644
edit
dl
rm
indosat.py
1997
0644
edit
dl
rm
internetsolutions.py
2050
0644
edit
dl
rm
joyent.py
8213
0644
edit
dl
rm
kamatera.py
23481
0644
edit
dl
rm
kili.py
3199
0644
edit
dl
rm
ktucloud.py
3595
0644
edit
dl
rm
kubevirt.py
40678
0644
edit
dl
rm
libvirt_driver.py
14671
0644
edit
dl
rm
linode.py
26646
0644
edit
dl
rm
maxihost.py
8419
0644
edit
dl
rm
medone.py
1984
0644
edit
dl
rm
nephoscale.py
17690
0644
edit
dl
rm
ntta.py
2011
0644
edit
dl
rm
nttcis.py
222933
0644
edit
dl
rm
onapp.py
16503
0644
edit
dl
rm
oneandone.py
57758
0644
edit
dl
rm
opennebula.py
43343
0644
edit
dl
rm
openstack.py
144008
0644
edit
dl
rm
ovh.py
18845
0644
edit
dl
rm
packet.py
33684
0644
edit
dl
rm
profitbricks.py
120806
0644
edit
dl
rm
rackspace.py
9442
0644
edit
dl
rm
rimuhosting.py
12292
0644
edit
dl
rm
scaleway.py
24231
0644
edit
dl
rm
serverlove.py
2934
0644
edit
dl
rm
skalicloud.py
2917
0644
edit
dl
rm
softlayer.py
17921
0644
edit
dl
rm
upcloud.py
11156
0644
edit
dl
rm
vcl.py
8843
0644
edit
dl
rm
vcloud.py
94722
0644
edit
dl
rm
voxel.py
10927
0644
edit
dl
rm
vpsnet.py
6721
0644
edit
dl
rm
vsphere.py
18407
0644
edit
dl
rm
vultr.py
13328
0644
edit
dl
rm
__init__.py
1207
0644
edit
dl
rm
Edit:
/opt/imh-python/lib/python3.9/site-packages/libcloud/compute/drivers/cloudscale.py
(8844B)
# 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. """ A driver for cloudscale.ch. """ import json from libcloud.utils.py3 import httplib from libcloud.common.base import ConnectionKey, JsonResponse from libcloud.compute.types import Provider, NodeState from libcloud.common.types import InvalidCredsError from libcloud.compute.base import NodeDriver from libcloud.compute.base import Node, NodeImage, NodeSize class CloudscaleResponse(JsonResponse): valid_response_codes = [httplib.OK, httplib.ACCEPTED, httplib.CREATED, httplib.NO_CONTENT] def parse_error(self): body = self.parse_body() if self.status == httplib.UNAUTHORIZED: raise InvalidCredsError(body['detail']) else: # We are taking the first issue here. There might be multiple ones, # but that doesn't really matter. It's nicer if the error is just # one error (because it's a Python API and there's only one # exception. return next(iter(body.values())) def success(self): return self.status in self.valid_response_codes class CloudscaleConnection(ConnectionKey): """ Connection class for the cloudscale.ch driver. """ host = 'api.cloudscale.ch' responseCls = CloudscaleResponse def add_default_headers(self, headers): """ Add headers that are necessary for every request This method adds ``token`` to the request. """ headers['Authorization'] = 'Bearer %s' % (self.key) headers['Content-Type'] = 'application/json' return headers class CloudscaleNodeDriver(NodeDriver): """ Cloudscale's node driver. """ connectionCls = CloudscaleConnection type = Provider.CLOUDSCALE name = 'Cloudscale' website = 'https://www.cloudscale.ch' NODE_STATE_MAP = dict( changing=NodeState.PENDING, running=NodeState.RUNNING, stopped=NodeState.STOPPED, paused=NodeState.PAUSED, ) def __init__(self, key, **kwargs): super(CloudscaleNodeDriver, self).__init__(key, **kwargs) def list_nodes(self): """ List all your existing compute nodes. """ return self._list_resources('/v1/servers', self._to_node) def list_sizes(self): """ Lists all available sizes. On cloudscale these are known as flavors. """ return self._list_resources('/v1/flavors', self._to_size) def list_images(self): """ List all images. Images are identified by slugs on cloudscale.ch. This means that minor version upgrades (e.g. Ubuntu 16.04.1 to Ubuntu 16.04.2) will be possible within the same id ``ubuntu-16.04``. """ return self._list_resources('/v1/images', self._to_image) def create_node(self, name, size, image, location=None, ex_create_attr=None): """ Create a node. The `ex_create_attr` parameter can include the following dictionary key and value pairs: * `ssh_keys`: ``list`` of ``str`` ssh public keys * `volume_size_gb`: ``int`` defaults to 10. * `bulk_volume_size_gb`: defaults to None. * `use_public_network`: ``bool`` defaults to True * `use_private_network`: ``bool`` defaults to False * `use_ipv6`: ``bool`` defaults to True * `anti_affinity_with`: ``uuid`` of a server to create an anti-affinity group with that server or add it to the same group as that server. * `user_data`: ``str`` for optional cloud-config data :keyword ex_create_attr: A dictionary of optional attributes for droplet creation :type ex_create_attr: ``dict`` :return: The newly created node. :rtype: :class:`Node` """ ex_create_attr = ex_create_attr or {} attr = dict(ex_create_attr) attr.update( name=name, image=image.id, flavor=size.id, ) result = self.connection.request( '/v1/servers', data=json.dumps(attr), method='POST' ) return self._to_node(result.object) def reboot_node(self, node): """ Reboot a node. It's also possible to use ``node.reboot()``. """ return self._action(node, 'reboot') def start_node(self, node): """ Start a node. This is only possible if the node is stopped. """ return self._action(node, 'start') def stop_node(self, node): """ Stop a specific node. Similar to ``shutdown -h now``. This is only possible if the node is running. """ return self._action(node, 'stop') def ex_start_node(self, node): # NOTE: This method is here for backward compatibility reasons after # this method was promoted to be part of the standard compute API in # Libcloud v2.7.0 return self.start_node(node=node) def ex_stop_node(self, node): # NOTE: This method is here for backward compatibility reasons after # this method was promoted to be part of the standard compute API in # Libcloud v2.7.0 return self.stop_node(node=node) def ex_node_by_uuid(self, uuid): """ :param str ex_user_data: A valid uuid that references your exisiting cloudscale.ch server. :type ex_user_data: ``str`` :return: The server node you asked for. :rtype: :class:`Node` """ res = self.connection.request(self._get_server_url(uuid)) return self._to_node(res.object) def destroy_node(self, node): """ Delete a node. It's also possible to use ``node.destroy()``. This will irreversibly delete the cloudscale.ch server and all its volumes. So please be cautious. """ res = self.connection.request( self._get_server_url(node.id), method='DELETE' ) return res.status == httplib.NO_CONTENT def _get_server_url(self, uuid): return '/v1/servers/%s' % uuid def _action(self, node, action_name): response = self.connection.request( self._get_server_url(node.id) + '/' + action_name, method='POST' ) return response.status == httplib.OK def _list_resources(self, url, tranform_func): data = self.connection.request(url, method='GET').object return [tranform_func(obj) for obj in data] def _to_node(self, data): state = self.NODE_STATE_MAP.get(data['status'], NodeState.UNKNOWN) extra_keys_exclude = ['uuid', 'name', 'status', 'flavor', 'image'] extra = {} for k, v in data.items(): if k not in extra_keys_exclude: extra[k] = v public_ips = [] private_ips = [] for interface in data['interfaces']: if interface['type'] == 'public': ips = public_ips else: ips = private_ips for address_obj in interface['addresses']: ips.append(address_obj['address']) return Node( id=data['uuid'], name=data['name'], state=state, public_ips=public_ips, private_ips=private_ips, extra=extra, driver=self, image=self._to_image(data['image']), size=self._to_size(data['flavor']), ) def _to_size(self, data): extra = {'vcpu_count': data['vcpu_count']} ram = data['memory_gb'] * 1024 return NodeSize(id=data['slug'], name=data['name'], ram=ram, disk=10, bandwidth=0, price=0, extra=extra, driver=self) def _to_image(self, data): extra = {'operating_system': data['operating_system']} return NodeImage(id=data['slug'], name=data['name'], extra=extra, driver=self)
Save
cmd:
run