Merge "Set hostname in launch node"

This commit is contained in:
Jenkins 2016-02-24 23:24:37 +00:00 committed by Gerrit Code Review
commit b487feaf7c
2 changed files with 15 additions and 0 deletions

View File

@ -84,6 +84,13 @@ def bootstrap_server(server, key, cert, environment, name,
ssh_client.ssh('bash -x install_puppet.sh')
certname = cert[:(0 - len('.pem'))]
shortname = name.split('.')[0]
with ssh_client.open('/etc/hosts', 'w') as f:
f.write('127.0.0.1 localhost\n')
f.write('127.0.1.1 %s %s\n' % (name, shortname))
with ssh_client.open('/etc/hostname', 'w') as f:
f.write('%s\n' % (shortname,))
ssh_client.ssh("hostname %s" % (name,))
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/certs")
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/private_keys")
ssh_client.ssh("mkdir -p /var/lib/puppet/ssl/public_keys")

View File

@ -18,6 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import contextlib
import sys
import paramiko
@ -55,3 +56,10 @@ class SSHClient(object):
ftp = self.client.open_sftp()
ftp.put(source, dest)
ftp.close()
@contextlib.contextmanager
def open(self, path, mode):
ftp = self.client.open_sftp()
f = ftp.open(path, mode)
yield f
ftp.close()