コード例 #1
0
 def set_hostname(self, hostname):
     """
     Set /etc/sysconfig/network
     """
     fileutil.update_conf_file('/etc/sysconfig/network', 'HOSTNAME',
                               'HOSTNAME={0}'.format(hostname))
     shellutil.run("hostname {0}".format(hostname), chk_err=False)
コード例 #2
0
ファイル: redhat.py プロジェクト: bingosummer/WALinuxAgent
 def set_hostname(self, hostname):
     """
     Set /etc/sysconfig/network
     """
     fileutil.update_conf_file('/etc/sysconfig/network',
                               'HOSTNAME',
                               'HOSTNAME={0}'.format(hostname))
     shellutil.run("hostname {0}".format(hostname), chk_err=False)
コード例 #3
0
 def set_hostname(self, hostname):
     """
     Set /etc/sysconfig/network
     """
     fileutil.update_conf_file('/etc/sysconfig/network', 'HOSTNAME',
                               'HOSTNAME={0}'.format(hostname))
     self._run_command_without_raising(["hostname", hostname],
                                       log_error=False)
コード例 #4
0
ファイル: default.py プロジェクト: sundaxi/WALinuxAgent
 def set_dhcp_hostname(self, hostname):
     autosend = r'^[^#]*?send\s*host-name.*?(<hostname>|gethostname[(,)])'
     dhclient_files = ['/etc/dhcp/dhclient.conf', '/etc/dhcp3/dhclient.conf', '/etc/dhclient.conf']
     for conf_file in dhclient_files:
         if not os.path.isfile(conf_file):
             continue
         if fileutil.findre_in_file(conf_file, autosend):
             #Return if auto send host-name is configured
             return
         fileutil.update_conf_file(conf_file,
                                   'send host-name',
                                   'send host-name "{0}";'.format(hostname))
コード例 #5
0
ファイル: default.py プロジェクト: vittyvk/WALinuxAgent
 def set_dhcp_hostname(self, hostname):
     autosend = r'^[^#]*?send\s*host-name.*?(<hostname>|gethostname[(,)])'
     dhclient_files = ['/etc/dhcp/dhclient.conf', '/etc/dhcp3/dhclient.conf', '/etc/dhclient.conf']
     for conf_file in dhclient_files:
         if not os.path.isfile(conf_file):
             continue
         if fileutil.findstr_in_file(conf_file, autosend):
             #Return if auto send host-name is configured
             return
         fileutil.update_conf_file(conf_file,
                                   'send host-name',
                                   'send host-name "{0}";'.format(hostname))
コード例 #6
0
    def test_update_conf_file(self, _):
        new_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n"

        existing_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
DHCP_HOSTNAME=existing\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n"

        bad_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n\
DHCP_HOSTNAME=no_new_line"

        updated_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n\
DHCP_HOSTNAME=test\n"

        path = 'path'
        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=new_file):
                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
                patch_write.assert_called_once_with(path, updated_file)

        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=existing_file):
                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
                patch_write.assert_called_once_with(path, updated_file)

        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=bad_file):
                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
                patch_write.assert_called_once_with(path, updated_file)
コード例 #7
0
ファイル: test_file_util.py プロジェクト: zr000/WALinuxAgent
    def test_update_conf_file(self, _):
        new_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n"

        existing_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
DHCP_HOSTNAME=existing\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n"

        bad_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n\
DHCP_HOSTNAME=no_new_line"

        updated_file = "\
DEVICE=eth0\n\
ONBOOT=yes\n\
BOOTPROTO=dhcp\n\
TYPE=Ethernet\n\
USERCTL=no\n\
PEERDNS=yes\n\
IPV6INIT=no\n\
NM_CONTROLLED=yes\n\
DHCP_HOSTNAME=test\n"

        path = 'path'
        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=new_file):
                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
                patch_write.assert_called_once_with(path, updated_file)

        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=existing_file):
                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
                patch_write.assert_called_once_with(path, updated_file)

        with patch.object(fileutil, 'write_file') as patch_write:
            with patch.object(fileutil, 'read_file', return_value=bad_file):
                fileutil.update_conf_file(path, 'DHCP_HOSTNAME', 'DHCP_HOSTNAME=test')
                patch_write.assert_called_once_with(path, updated_file)
コード例 #8
0
 def set_dhcp_hostname(self, hostname):
     ifname = self.get_if_name()
     filepath = "/etc/sysconfig/network-scripts/ifcfg-{0}".format(ifname)
     fileutil.update_conf_file(filepath, 'DHCP_HOSTNAME',
                               'DHCP_HOSTNAME={0}'.format(hostname))
コード例 #9
0
ファイル: redhat.py プロジェクト: bingosummer/WALinuxAgent
 def set_dhcp_hostname(self, hostname):
     ifname = self.get_if_name()
     filepath = "/etc/sysconfig/network-scripts/ifcfg-{0}".format(ifname)
     fileutil.update_conf_file(filepath,
                               'DHCP_HOSTNAME',
                               'DHCP_HOSTNAME={0}'.format(hostname))
コード例 #10
0
ファイル: illumos.py プロジェクト: omniosorg/WAGuestAgent
 def clear_ips_uuid(self):
     if not os.path.isfile('/var/pkg/pkg5.image'): return
     fileutil.update_conf_file("/var/pkg/pkg5.image", "last_uuid", "")