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

@ -29,12 +29,16 @@
"sections": { "sections": {
"type": "array", "type": "array",
"minItems": 1 "minItems": 1
}, },
"architecture": { "enum": ["i386", "amd64"] }, "architecture": { "enum": ["i386", "amd64"] },
"bootloader": { "enum": ["pvgrub", "grub", "extlinux"] }, "bootloader": { "enum": ["pvgrub", "grub", "extlinux"] },
"timezone": { "type": "string" }, "timezone": { "type": "string" },
"locale": { "type": "string" }, "locale": { "type": "string" },
"charmap": { "type": "string" } "charmap": { "type": "string" },
"hostname": {
"type": "string",
"pattern": "^\\S+$"
}
}, },
"required": ["release", "architecture", "bootloader", "timezone", "locale", "charmap"] "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')) 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): class ConfigureNetworkIF(Task):
description = 'Configuring network interfaces' description = 'Configuring network interfaces'
phase = phases.system_modification phase = phases.system_modification

View file

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

View file

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

View file

@ -48,22 +48,6 @@ class AddPackages(Task):
info.packages.add('nfs-client') 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): class CreateVagrantUser(Task):
description = 'Creating the vagrant user' description = 'Creating the vagrant user'
phase = phases.system_modification phase = phases.system_modification

View file

@ -61,6 +61,11 @@ def resolve_tasks(taskset, manifest):
if manifest.volume['partitions']['type'] != 'none': if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_sets.partitioning_set) 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, taskset.update([tasks.host.AddExternalCommands,
tasks.packages.DefaultPackages, tasks.packages.DefaultPackages,
tasks.connection.GetCredentials, tasks.connection.GetCredentials,
@ -72,7 +77,6 @@ def resolve_tasks(taskset, manifest):
boot.DisableGetTTYs, boot.DisableGetTTYs,
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo, network.RemoveDNSInfo,
network.RemoveHostname,
network.ConfigureNetworkIF, network.ConfigureNetworkIF,
tasks.network.EnableDHCPCDDNS, tasks.network.EnableDHCPCDDNS,
initd.AddExpandRoot, initd.AddExpandRoot,

View file

@ -37,6 +37,11 @@ def resolve_tasks(tasklist, manifest):
if manifest.volume['partitions']['type'] != 'none': if manifest.volume['partitions']['type'] != 'none':
tasklist.update(task_sets.partitioning_set) 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, tasklist.update([tasks.packages.DefaultPackages,
loopback.Create, loopback.Create,
@ -44,7 +49,6 @@ def resolve_tasks(tasklist, manifest):
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo, network.RemoveDNSInfo,
network.ConfigureNetworkIF, network.ConfigureNetworkIF,
network.RemoveHostname,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
initd.InstallInitScripts, initd.InstallInitScripts,
cleanup.ClearMOTD, cleanup.ClearMOTD,

View file

@ -37,6 +37,11 @@ def resolve_tasks(taskset, manifest):
if manifest.volume['partitions']['type'] != 'none': if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_sets.partitioning_set) 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, taskset.update([tasks.packages.DefaultPackages,
loopback.Create, loopback.Create,
@ -44,7 +49,6 @@ def resolve_tasks(taskset, manifest):
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo, network.RemoveDNSInfo,
network.ConfigureNetworkIF, network.ConfigureNetworkIF,
network.RemoveHostname,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
initd.InstallInitScripts, initd.InstallInitScripts,
cleanup.ClearMOTD, cleanup.ClearMOTD,

View file

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