Commit f06f423d by Őry Máté

one: more consistent host names

parent cfd5ca86
...@@ -476,6 +476,7 @@ class Instance(models.Model): ...@@ -476,6 +476,7 @@ class Instance(models.Model):
out = "" out = ""
inst = Instance(pw=pwgen(), template=template, owner=owner, share=share) inst = Instance(pw=pwgen(), template=template, owner=owner, share=share)
inst.save() inst.save()
hostname = u"cloud-%d" % (inst.id, )
with tempfile.NamedTemporaryFile(delete=False) as f: with tempfile.NamedTemporaryFile(delete=False) as f:
os.chmod(f.name, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH) os.chmod(f.name, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH)
token = signing.dumps(inst.id, salt='activate') token = signing.dumps(inst.id, salt='activate')
...@@ -497,7 +498,7 @@ class Instance(models.Model): ...@@ -497,7 +498,7 @@ class Instance(models.Model):
</NIC> </NIC>
<CONTEXT> <CONTEXT>
<SOURCE>web</SOURCE> <SOURCE>web</SOURCE>
<HOSTNAME>cloud-$VMID</HOSTNAME> <HOSTNAME>%(hostname)s</HOSTNAME>
<NEPTUN>%(neptun)s</NEPTUN> <NEPTUN>%(neptun)s</NEPTUN>
<USERPW>%(pw)s</USERPW> <USERPW>%(pw)s</USERPW>
<SMBPW>%(smbpw)s</SMBPW> <SMBPW>%(smbpw)s</SMBPW>
...@@ -511,6 +512,7 @@ class Instance(models.Model): ...@@ -511,6 +512,7 @@ class Instance(models.Model):
"disk": template.disk.id, "disk": template.disk.id,
"net": template.network.id, "net": template.network.id,
"pw": escape(inst.pw), "pw": escape(inst.pw),
"hostname": escape(hostname),
"smbpw": escape(details.smb_password), "smbpw": escape(details.smb_password),
"sshkey": escape(details.ssh_private_key), "sshkey": escape(details.ssh_private_key),
"neptun": escape(owner.username), "neptun": escape(owner.username),
...@@ -527,6 +529,7 @@ class Instance(models.Model): ...@@ -527,6 +529,7 @@ class Instance(models.Model):
try: try:
x = parseString(out) x = parseString(out)
except: except:
inst.delete()
raise Exception("Unable to create VM instance.") raise Exception("Unable to create VM instance.")
inst.one_id = int(x.getElementsByTagName("ID")[0].childNodes[0] inst.one_id = int(x.getElementsByTagName("ID")[0].childNodes[0]
.nodeValue) .nodeValue)
...@@ -538,7 +541,7 @@ class Instance(models.Model): ...@@ -538,7 +541,7 @@ class Instance(models.Model):
inst.update_state() inst.update_state()
host = Host(vlan=Vlan.objects.get(name=template.network.name), host = Host(vlan=Vlan.objects.get(name=template.network.name),
owner=owner, shared_ip=True) owner=owner, shared_ip=True)
host.hostname = u"id-%d_user-%s" % (inst.id, owner.username) host.hostname = hostname
host.mac = x.getElementsByTagName("MAC")[0].childNodes[0].nodeValue host.mac = x.getElementsByTagName("MAC")[0].childNodes[0].nodeValue
host.ipv4 = inst.ip host.ipv4 = inst.ip
host.pub_ipv4 = Vlan.objects.get(name=template.network.name).snat_ip host.pub_ipv4 = Vlan.objects.get(name=template.network.name).snat_ip
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment