Produce safe libcloud id for Maxihost provider
import json
import re
+import hashlib
+import json
from libcloud.compute.base import Node, NodeDriver, NodeLocation
from libcloud.compute.base import NodeSize, NodeImage
@@ -26,10 +28,6 @@ from libcloud.common.exceptions import BaseHTTPError
from libcloud.utils.py3 import httplib
-
-import json
-
-
__all__ = [
"MaxihostNodeDriver"
]
@@ -162,7 +160,9 @@ class MaxihostNodeDriver(NodeDriver):
for key in data:
extra[key] = data[key]
- node = Node(id=data['service_id'], name=data['description'], state=state,
+ name = data['description']
+ _id = data['service_id'] or hashlib.sha1(name.encode()).hexdigest()
+ node = Node(id=_id, name=name, state=state,
private_ips=private_ips, public_ips=public_ips,
driver=self, extra=extra)
return node
