Return network, size, image and created_at info for GigG8
@@ -17,6 +17,8 @@ GiG G8 Driver
"""
import json
+import hashlib
+
from libcloud.compute.base import NodeImage, NodeSize, Node
from libcloud.compute.base import NodeDriver, UuidMixin
from libcloud.compute.base import StorageVolume, NodeAuthSSHKey
@@ -251,7 +253,7 @@ class G8NodeDriver(NodeDriver):
params={"machineId": machineId})
node = self._to_node(machine, ex_network)
if ex_expose_ssh:
- port = self.ex_expose_ssh_node(node)
+ port = self.ex_expose_ssh_node(node, ex_network)
node.extra["ssh_port"] = port
node.extra["ssh_ip"] = ex_network.publicipaddress
return node
@@ -266,7 +268,7 @@ class G8NodeDriver(NodeDriver):
result["node"] = forward.privateport
return result
- def ex_expose_ssh_node(self, node):
+ def ex_expose_ssh_node(self, node, network):
"""
Create portforward for ssh purposed
@@ -276,7 +278,6 @@ class G8NodeDriver(NodeDriver):
:rtype: ``int``
"""
- network = node.extra["network"]
ports = self._find_ssh_ports(network, node)
if ports["node"]:
return ports["node"]
@@ -538,6 +539,7 @@ class G8NodeDriver(NodeDriver):
def _to_node(self, nodedata, ex_network):
# type (dict) -> Node
state = self.NODE_STATE_MAP.get(nodedata["status"], NodeState.UNKNOWN)
+ name = nodedata['name']
public_ips = []
private_ips = []
nics = nodedata.get("nics", [])
@@ -549,10 +551,25 @@ class G8NodeDriver(NodeDriver):
public_ips.append(nic["ipAddress"].split("/")[0])
else:
private_ips.append(nic["ipAddress"])
+
+ memory = nodedata.get('memory')
+ cpus = nodedata.get('vcpus')
+ size_extra = {'cpus': cpus}
+ disk = nodedata.get('storage')
+ id_to_hash = str(memory) + str(cpus) + str(disk)
+ size_id = hashlib.md5(id_to_hash.encode("utf-8")).hexdigest()
+ size_name = name + "-size"
+ size = NodeSize(id=size_id, name=size_name, ram=memory, disk=disk,
+ bandwidth=0, price=0, driver=self, extra=size_extra)
+
public_ips.append(ex_network.publicipaddress)
- extra = {"network": ex_network}
+ created_at = nodedata.get('creationTime')
+ imageId = str(nodedata.get('imageId'))
+ extra = {"network_id": str(ex_network.id),
+ "created_at": created_at,
+ "imageId": imageId}
- return Node(id=str(nodedata['id']), name=nodedata['name'],
+ return Node(id=str(nodedata['id']), name=name, size=size,
driver=self, public_ips=public_ips,
private_ips=private_ips, state=state, extra=extra)
