def install_logrotate_script(himn, username):
    "Install console logrotate script"
    utils.scp(himn, username, '/root/', 'rotate_xen_guest_logs.sh')
    utils.ssh(himn, username, 'mkdir -p /var/log/xen/guest')
    utils.ssh(himn, username, '''crontab - << CRONTAB
* * * * * /root/rotate_xen_guest_logs.sh >/dev/null 2>&1
CRONTAB''')
예제 #2
0
파일: generator.py 프로젝트: kjelly/netcpy
 def config(self, data):
     device = data['ifnames'][0]
     local_file_path = self.generate(data, templates.ubuntu_eth, device)
     file_name = self.file_prefix + device
     remote_tmp_path = os.path.join(self.remote_tmp_dir, file_name)
     remote_file_path = os.path.join(self.local_tmp_dir, file_name)
     utils.scp(data, local_file_path, remote_tmp_path, remote_file_path)
def install_suppack(himn, username, package):
    """Install xapi driver supplemental pack. """
    tmp = utils.ssh(himn, username, 'mktemp', '-d')
    utils.scp(himn, username, tmp, package)
    utils.ssh(himn, username, 'xe-install-supplemental-pack',
              tmp + '/' + package, prompt='Y\n')
    utils.ssh(himn, username, 'rm', tmp, '-rf')
예제 #4
0
def install_suppack(himn, username, package, xcp_version):
    """Install xapi driver supplemental pack. """
    tmp = utils.ssh(himn, username, 'mktemp', '-d')
    real_pack = "xcp_%s/%s" % (xcp_version, package)
    if not os.path.exists(real_pack):
        utils.reportError('Package folder %s not exist' % real_pack)
    utils.scp(himn, username, tmp, real_pack)
    if LooseVersion(xcp_version) < LooseVersion('2.2.0'):
        utils.ssh(himn,
                  username,
                  'xe-install-supplemental-pack',
                  tmp + '/' + package,
                  prompt='Y\n')
    else:
        errcode, uuid, errmsg = \
            utils.ssh_detailed(himn, username, 'xe', 'update-upload',
                               'file-name=' + tmp + '/' + package,
                               allowed_return_codes=[0, 1])
        if errcode == 0:
            utils.ssh(himn, username, 'xe', 'update-apply',
                      'uuid=' + uuid.strip())
        else:
            LOG.debug("Install supplemental pack failed, err: %s", errmsg)
            if "The uploaded update already exists" in errmsg:
                uuid = parse_uuid(errmsg)
                if uuid is None:
                    raise utils.ExecutionError(errmsg)
                # Check current update is applied already
                out = utils.ssh(himn, username, 'xe', 'update-list',
                                'uuid=' + uuid, '--minimal')
                # Apply this update if cannot find it with uuid
                if not out:
                    utils.ssh(himn, username, 'xe', 'update-apply',
                              'uuid=' + uuid)
    utils.ssh(himn, username, 'rm', tmp, '-rf')
예제 #5
0
def install_logrotate_script(himn, username):
    "Install console logrotate script"
    utils.scp(himn, username, '/root/', 'rotate_xen_guest_logs.sh')
    utils.ssh(himn, username, 'mkdir -p /var/log/xen/guest')
    utils.ssh(
        himn, username, '''crontab - << CRONTAB
* * * * * /root/rotate_xen_guest_logs.sh >/dev/null 2>&1
CRONTAB''')
예제 #6
0
 def scp(self, source, dest, host=None):
     """ this method requires that an ssh daemon is running on the target
         and that an authorized_keys file is set with a rsa plubilc key,
         all conditions met by images provided in this project.
     """
     containers = [self.containers[host]] if host else self.containers.itervalues()
     for container in containers:
         utils.scp(source, dest, get_container_ip(container), self.user)
     return self
예제 #7
0
def install_suppack(himn, username, package):
    """Install xapi driver supplemental pack. """
    tmp = utils.ssh(himn, username, 'mktemp', '-d')
    utils.scp(himn, username, tmp, package)
    utils.ssh(himn,
              username,
              'xe-install-supplemental-pack',
              tmp + '/' + package,
              prompt='Y\n')
    utils.ssh(himn, username, 'rm', tmp, '-rf')
예제 #8
0
def create_dom0_mesh_bridge(himn, username, dom0_bridge, mesh_info):
    # Create br-mesh and veth pair if not exist in Dom0
    exitcode, out, _ = utils.ssh_detailed(himn,
                                          username,
                                          'ip',
                                          'addr',
                                          'show',
                                          MESH_BRIDGE,
                                          allowed_return_codes=[0, 1])
    if exitcode == 1:
        # create mesh bridge if it not exist in Dom0
        create_mesh_bridge = True
    else:
        # if mesh bridge exist in Dom0, check its ip, re-configure ip if
        # it's not the same as what we want to set
        bridge_info = out.split()
        try:
            index_inet = bridge_info.index('inet')
            # get inet info like '192.168.2.2/24'
            ipaddr = bridge_info[index_inet + 1].split('/')[0]
            current_ip = ipaddress.ip_address(unicode(ipaddr))
            configured_ip = ipaddress.ip_address(unicode(mesh_info['ipaddr']))
            if current_ip == configured_ip:
                LOG.info('Bridge %s already exist in Dom0' % MESH_BRIDGE)
                return
            else:
                create_mesh_bridge = True
                remove_old_mesh_bridge(himn, username, MESH_BRIDGE)
        except ValueError:
            create_mesh_bridge = True
            remove_old_mesh_bridge(himn, username, MESH_BRIDGE)

    if create_mesh_bridge:
        LOG.debug("Create mesh bridge in Dom0")
        utils.scp(himn, username, '/etc/sysconfig/network-scripts/',
                  AUTO_SCRIPT)
        utils.ssh(himn, username, 'chmod', '+x',
                  '/etc/sysconfig/network-scripts/%s' % AUTO_SCRIPT)

        start_param = '%(bridge)s %(ip)s %(netmask)s %(broadcast)s %(tag)s' \
                      % {'bridge': dom0_bridge,
                         'ip': mesh_info['ipaddr'],
                         'netmask': mesh_info['netmask'],
                         'broadcast': mesh_info['broadcast'],
                         'tag': mesh_info['tag']}
        with open(AUTO_START_SERVICE_TEMPLATE) as f:
            contents = f.read()
        contents = contents.replace('@MESH_INFO@', start_param)
        with open(AUTO_START_SERVICE, 'w') as f:
            f.write(contents)
        utils.scp(himn, username, '/etc/systemd/system', AUTO_START_SERVICE)
        utils.ssh(himn, username, 'systemctl', 'daemon-reload')
        utils.ssh(himn, username, 'systemctl', 'enable', AUTO_START_SERVICE)
        utils.ssh(himn, username, 'systemctl', 'start', AUTO_START_SERVICE)
예제 #9
0
    def init_remote(self, host, filename, use_sudo):
        """ send the pgqadm file to the remote host """
        from options import VERBOSE

        utils.scp(host, filename, '/tmp')
        remote_filename = os.path.basename(filename)

        args = ['init-pgq', remote_filename]
        out = utils.run_client_script(host, args, use_sudo)

        if VERBOSE:
            print out

        return remote_filename
예제 #10
0
    def init_remote(self, host, filename, use_sudo):
        """ send the pgqadm file to the remote host """
        from options import VERBOSE

        utils.scp(host, filename, '/tmp')
        remote_filename = os.path.basename(filename)

        args = ['init-pgq', remote_filename]
        out  = utils.run_client_script(host, args, use_sudo)

        if VERBOSE:
            print out

        return remote_filename
예제 #11
0
    def init_remote(self, provider, host, filename, use_sudo):
        """ send the londiste file for provider to the remote host """
        from options import VERBOSE

        utils.scp(host, filename, '/tmp')

        remote_filename = os.path.basename(filename)
        tables = self.clean_provides(self.config.get(provider, 'provides'))
        args = ['init-londiste', provider, remote_filename] + tables
        out = utils.run_client_script(host, args, use_sudo)

        if VERBOSE:
            print out

        return remote_filename
예제 #12
0
    def init_remote(self, provider, host, filename, use_sudo):
        """ send the londiste file for provider to the remote host """
        from options import VERBOSE

        utils.scp(host, filename, '/tmp')

        remote_filename = os.path.basename(filename)
        tables = self.clean_provides( self.config.get(provider, 'provides') )
        args   = ['init-londiste', provider, remote_filename] + tables
        out    = utils.run_client_script(host, args, use_sudo)

        if VERBOSE:
            print out

        return remote_filename
예제 #13
0
def copy2_wrapper(arg_tuple):
    node, ssh_cert, adm_usr, nargs, sudo, noSupressWarning = arg_tuple
    source, target = nargs[0], nargs[1]
    if sudo:
        utils.sudo_scp(ssh_cert,
                       source,
                       target,
                       adm_usr,
                       node,
                       verbose=noSupressWarning)
    else:
        utils.scp(ssh_cert,
                  source,
                  target,
                  adm_usr,
                  node,
                  verbose=noSupressWarning)
예제 #14
0
    def pgbouncer_update_conf(self, newconffile):
        """ reconfigure targeted pgbouncer with given file """
        import os.path
        from options import VERBOSE, TERSE, CLIENT_SCRIPT

        baseconfdir = os.path.dirname(self.pgbouncer_conf)

        # skip scp when target is localhost
        if self.host not in ("localhost", "127.0.0.1"):
            utils.scp(self.host, newconffile, '/tmp')

        utils.run_client_script(
            self.host, ["pgbouncer", newconffile, self.pgbouncer_port],
            self.use_sudo)

        # if target isn't localhost, rm the local temp file
        # when target host is localhost, we used mv already
        if self.host not in ("localhost", "127.0.0.1"):
            os.unlink(newconffile)
예제 #15
0
    def pgbouncer_update_conf(self, newconffile):
        """ reconfigure targeted pgbouncer with given file """
        import os.path
        from options import VERBOSE, TERSE, CLIENT_SCRIPT

        baseconfdir = os.path.dirname(self.pgbouncer_conf)

        # skip scp when target is localhost
        if self.host not in ("localhost", "127.0.0.1"):
            utils.scp(self.host, newconffile, '/tmp')

        utils.run_client_script(self.host,
                                ["pgbouncer", newconffile, self.pgbouncer_port],
                                self.use_sudo)

        # if target isn't localhost, rm the local temp file
        # when target host is localhost, we used mv already
        if self.host not in ("localhost", "127.0.0.1"):
            os.unlink(newconffile)
예제 #16
0
def enable_conntrack_service(himn, username):
    # use conntrack statistic mode, so change conntrackd.conf
    errcode, out, err = utils.ssh_detailed(
        himn,
        username,
        'ls',
        '/etc/conntrackd/conntrackd.conf.back',
        allowed_return_codes=[0, 2])
    if errcode == 2:
        # Only make conntrackd.conf.back if it doesn't exist
        utils.ssh(himn, username, 'mv', '/etc/conntrackd/conntrackd.conf',
                  '/etc/conntrackd/conntrackd.conf.back')
        utils.ssh(himn, username, 'cp', CONNTRACK_CONF_SAMPLE,
                  '/etc/conntrackd/conntrackd.conf')

    # Rotate log file for conntrack
    utils.scp(himn, username, '/etc/logrotate.d', 'etc/logrotate.d/conntrackd')

    # Restart conntrackd service
    utils.ssh(himn, username, 'service', 'conntrackd', 'restart')
예제 #17
0
파일: generator.py 프로젝트: kjelly/netcpy
 def generate_and_scp_bond(self, data, template, device):
     local_file_path = self.generate(data, template, device)
     file_name = self.file_prefix + device
     remote_file_path = os.path.join(self.local_tmp_dir, file_name)
     remote_tmp_path = os.path.join(self.remote_tmp_dir, file_name)
     utils.scp(data, local_file_path, remote_tmp_path, remote_file_path)