in libcloud/compute/drivers/scaleway.py [0:0]
def create_node(self, name, size, image, ex_volumes=None, ex_tags=None, region=None):
"""
Create a new node.
:param name: The name to give the node
:type name: ``str``
:param size: The size of node to create
:type size: :class:`.NodeSize`
:param image: The image to create the node with
:type image: :class:`.NodeImage`
:param ex_volumes: Additional volumes to create the node with
:type ex_volumes: ``dict`` of :class:`.StorageVolume`s
:param ex_tags: Tags to assign to the node
:type ex_tags: ``list`` of ``str``
:param region: The region in which to create the node
(if None, use default region specified in __init__)
:type region: :class:`.NodeLocation`
:return: the newly created node object
:rtype: :class:`.Node`
"""
data = {
"name": name,
"organization": self.key,
"image": image.id,
"volumes": ex_volumes or {},
"commercial_type": size.id,
"tags": ex_tags or [],
}
allocate_space = image.extra.get("size", 50)
for volume in data["volumes"]:
allocate_space += _to_lib_size(volume["size"])
while allocate_space < size.disk:
if size.disk - allocate_space > 150:
bump = 150
else:
bump = size.disk - allocate_space
vol_num = len(data["volumes"]) + 1
data["volumes"][str(vol_num)] = {
"name": "%s-%d" % (name, vol_num),
"organization": self.key,
"size": _to_api_size(bump),
"volume_type": "l_ssd",
}
allocate_space += bump
if allocate_space > size.extra.get("max_disk", size.disk):
range = (
"of %dGB" % size.disk
if size.extra.get("max_disk", size.disk) == size.disk
else "between %dGB and %dGB" % (size.extra.get("max_disk", size.disk), size.disk)
)
raise ProviderError(
value=(
"%s only supports a total volume size %s; tried %dGB"
% (size.id, range, allocate_space)
),
http_code=400,
driver=self,
)
response = self.connection.request(
"/servers", data=json.dumps(data), region=region, method="POST"
)
server = response.object["server"]
node = self._to_node(server)
node.extra["region"] = (region.id if isinstance(region, NodeLocation) else region) or "par1"
# Scaleway doesn't start servers by default, let's do it
self._action(node.id, "poweron")
return node