Move hostname setting from vagrant into common

This closes #19.
This commit is contained in:
Tiago Ilieve 2014-04-13 21:18:02 -03:00
parent 69a76f2597
commit 18fce45d91
9 changed files with 40 additions and 31 deletions

View file

@ -34,7 +34,11 @@
"bootloader": { "enum": ["pvgrub", "grub", "extlinux"] },
"timezone": { "type": "string" },
"locale": { "type": "string" },
"charmap": { "type": "string" }
"charmap": { "type": "string" },
"hostname": {
"type": "string",
"pattern": "^\\S+$"
}
},
"required": ["release", "architecture", "bootloader", "timezone", "locale", "charmap"]
},

View file

@ -23,6 +23,22 @@ class RemoveHostname(Task):
os.remove(os.path.join(info.root, 'etc/hostname'))
class SetHostname(Task):
description = 'Writing hostname into the hostname file'
phase = phases.system_modification
@classmethod
def run(cls, info):
hostname = info.manifest.system['hostname'].format(**info.manifest_vars)
hostname_file_path = os.path.join(info.root, 'etc/hostname')
with open(hostname_file_path, 'w') as hostname_file:
hostname_file.write(hostname)
hosts_path = os.path.join(info.root, 'etc/hosts')
from bootstrapvz.common.tools import sed_i
sed_i(hosts_path, '^127.0.0.1\tlocalhost$', '127.0.0.1\tlocalhost\n127.0.1.1\t' + hostname)
class ConfigureNetworkIF(Task):
description = 'Configuring network interfaces'
phase = phases.system_modification

View file

@ -13,13 +13,11 @@ def resolve_tasks(taskset, manifest):
from bootstrapvz.common.tasks import network
taskset.discard(security.DisableSSHPasswordAuthentication)
taskset.discard(loopback.MoveImage)
taskset.discard(network.RemoveHostname)
from bootstrapvz.common.tasks import volume
taskset.update([tasks.CheckBoxPath,
tasks.CreateVagrantBoxDir,
tasks.AddPackages,
tasks.SetHostname,
tasks.CreateVagrantUser,
tasks.PasswordlessSudo,
tasks.SetRootPassword,

View file

@ -25,12 +25,7 @@
"vagrant": {
"type": "object",
"properties": {
"hostname": {
"type": "string",
"pattern": "^\\S+$"
}
},
"required": ["hostname"]
}
}
}
}

View file

@ -48,22 +48,6 @@ class AddPackages(Task):
info.packages.add('nfs-client')
class SetHostname(Task):
description = 'Writing hostname into the hostname file'
phase = phases.system_modification
@classmethod
def run(cls, info):
hostname = info.manifest.plugins['vagrant']['hostname'].format(**info.manifest_vars)
hostname_file_path = os.path.join(info.root, 'etc/hostname')
with open(hostname_file_path, 'w') as hostname_file:
hostname_file.write(hostname)
hosts_path = os.path.join(info.root, 'etc/hosts')
from bootstrapvz.common.tools import sed_i
sed_i(hosts_path, '^127.0.0.1\tlocalhost$', '127.0.0.1\tlocalhost\n127.0.0.1\t' + hostname)
class CreateVagrantUser(Task):
description = 'Creating the vagrant user'
phase = phases.system_modification

View file

@ -61,6 +61,11 @@ def resolve_tasks(taskset, manifest):
if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_sets.partitioning_set)
if manifest.system.get('hostname', False):
taskset.add(network.SetHostname)
else:
taskset.add(network.RemoveHostname)
taskset.update([tasks.host.AddExternalCommands,
tasks.packages.DefaultPackages,
tasks.connection.GetCredentials,
@ -72,7 +77,6 @@ def resolve_tasks(taskset, manifest):
boot.DisableGetTTYs,
security.EnableShadowConfig,
network.RemoveDNSInfo,
network.RemoveHostname,
network.ConfigureNetworkIF,
tasks.network.EnableDHCPCDDNS,
initd.AddExpandRoot,

View file

@ -37,6 +37,11 @@ def resolve_tasks(tasklist, manifest):
if manifest.volume['partitions']['type'] != 'none':
tasklist.update(task_sets.partitioning_set)
if manifest.system.get('hostname', False):
tasklist.add(network.SetHostname)
else:
tasklist.add(network.RemoveHostname)
tasklist.update([tasks.packages.DefaultPackages,
loopback.Create,
@ -44,7 +49,6 @@ def resolve_tasks(tasklist, manifest):
security.EnableShadowConfig,
network.RemoveDNSInfo,
network.ConfigureNetworkIF,
network.RemoveHostname,
initd.AddSSHKeyGeneration,
initd.InstallInitScripts,
cleanup.ClearMOTD,

View file

@ -37,6 +37,11 @@ def resolve_tasks(taskset, manifest):
if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_sets.partitioning_set)
if manifest.system.get('hostname', False):
taskset.add(network.SetHostname)
else:
taskset.add(network.RemoveHostname)
taskset.update([tasks.packages.DefaultPackages,
loopback.Create,
@ -44,7 +49,6 @@ def resolve_tasks(taskset, manifest):
security.EnableShadowConfig,
network.RemoveDNSInfo,
network.ConfigureNetworkIF,
network.RemoveHostname,
initd.AddSSHKeyGeneration,
initd.InstallInitScripts,
cleanup.ClearMOTD,

View file

@ -14,7 +14,8 @@
"bootloader": "grub",
"timezone": "UTC",
"locale": "en_US",
"charmap": "UTF-8"
"charmap": "UTF-8",
"hostname": "localhost"
},
"packages": {},
"volume": {
@ -34,7 +35,6 @@
},
"plugins": {
"vagrant": {
"hostname": "localhost"
}
}
}