Exemple #1
0
def disable_apis(env):
    controllers = list(env_util.get_controllers(env))
    maintenance_line = 'backend maintenance'
    stats_socket_re = re.compile('stats\s+socket\s+/var/lib/haproxy/stats'
                                 '(?!.*level admin)')
    mode_tcp_re = re.compile('mode\s+tcp')
    use_backend_line = '  use_backend maintenance if TRUE'
    for node in controllers:
        sftp = ssh.sftp(node)
        sftp.chdir('/etc/haproxy')
        with ssh.update_file(sftp, 'haproxy.cfg') as (old, new):
            found_maint_line = False
            for line in old:
                if maintenance_line in line:
                    found_maint_line = True
                line = stats_socket_re.sub(r'\g<0> level admin', line)
                new.write(line)
            if not found_maint_line:
                new.write(maintenance_line)
        sftp.chdir('/etc/haproxy/conf.d')
        for f in sftp.listdir():
            with ssh.update_file(sftp, f) as (old, new):
                contents = old.read()
                if not mode_tcp_re.search(contents):
                    raise ssh.DontUpdateException
                new.write(contents)
                if not contents.endswith('\n'):
                    new.write('\n')
                new.write(use_backend_line)
        ssh.call(['crm', 'resource', 'restart', 'p_haproxy'], node=node)
Exemple #2
0
def disable_apis(env):
    controllers = list(env_util.get_controllers(env))
    maintenance_line = 'backend maintenance'
    stats_socket_re = re.compile('stats\s+socket\s+/var/lib/haproxy/stats'
                                 '(?!.*level admin)')
    mode_tcp_re = re.compile('mode\s+tcp')
    use_backend_line = '  use_backend maintenance if TRUE'
    for node in controllers:
        sftp = ssh.sftp(node)
        sftp.chdir('/etc/haproxy')
        with ssh.update_file(sftp, 'haproxy.cfg') as (old, new):
            found_maint_line = False
            for line in old:
                if maintenance_line in line:
                    found_maint_line = True
                line = stats_socket_re.sub(r'\g<0> level admin', line)
                new.write(line)
            if not found_maint_line:
                new.write(maintenance_line)
        sftp.chdir('/etc/haproxy/conf.d')
        for f in sftp.listdir():
            with ssh.update_file(sftp, f) as (old, new):
                contents = old.read()
                if not mode_tcp_re.search(contents):
                    raise ssh.DontUpdateException
                new.write(contents)
                if not contents.endswith('\n'):
                    new.write('\n')
                new.write(use_backend_line)
        ssh.call(['crm', 'resource', 'restart', 'p_haproxy'], node=node)
Exemple #3
0
def disable_apis(env):
    controllers = list(env_util.get_controllers(env))
    maintenance_line = "backend maintenance"
    stats_socket_re = re.compile("stats\s+socket\s+/var/lib/haproxy/stats" "(?!.*level admin)")
    mode_tcp_re = re.compile("mode\s+tcp")
    use_backend_line = "  use_backend maintenance if TRUE"
    for node in controllers:
        sftp = ssh.sftp(node)
        sftp.chdir("/etc/haproxy")
        with ssh.update_file(sftp, "haproxy.cfg") as (old, new):
            found_maint_line = False
            for line in old:
                if maintenance_line in line:
                    found_maint_line = True
                line = stats_socket_re.sub(r"\g<0> level admin", line)
                new.write(line)
            if not found_maint_line:
                new.write(maintenance_line)
        sftp.chdir("/etc/haproxy/conf.d")
        for f in sftp.listdir():
            with ssh.update_file(sftp, f) as (old, new):
                contents = old.read()
                if not mode_tcp_re.search(contents):
                    raise ssh.DontUpdateException
                new.write(contents)
                if not contents.endswith("\n"):
                    new.write("\n")
                new.write(use_backend_line)
        ssh.call(["crm", "resource", "restart", "p_haproxy"], node=node)
Exemple #4
0
def remove_compute_upgrade_levels(node):
    sftp = ssh.sftp(node)
    with ssh.update_file(sftp, '/etc/nova/nova.conf') as (old, new):
        for line in old:
            if line.startswith("compute="):
                continue
            new.write(line)
Exemple #5
0
def add_compute_upgrade_levels(node, version):
    sftp = ssh.sftp(node)
    with ssh.update_file(sftp, '/etc/nova/nova.conf') as (old, new):
        for line in old:
            new.write(line)
            if line.startswith("[upgrade_levels]"):
                new.write("compute={0}\n".format(version))
Exemple #6
0
def enable_apis(env):
    controllers = list(env_util.get_controllers(env))
    maintenance_line = 'backend maintenance'
    use_backend_line = '  use_backend maintenance if TRUE'
    for node in controllers:
        sftp = ssh.sftp(node)
        sftp.chdir('/etc/haproxy')
        with ssh.update_file(sftp, 'haproxy.cfg') as (old, new):
            for line in old:
                if maintenance_line in line:
                    continue
                new.write(line)
        sftp.chdir('/etc/haproxy/conf.d')
        for f in sftp.listdir():
            with ssh.update_file(sftp, f) as (old, new):
                for line in old:
                    if use_backend_line in line:
                        continue
                    new.write(line)
        ssh.call(['crm', 'resource', 'restart', 'p_haproxy'], node=node)
Exemple #7
0
def save_port_lnx(node, bridge, port):
    ifaces_path = '/etc/network/interfaces.d'
    bridge_file = os.path.join(ifaces_path, 'ifcfg-{0}'.format(bridge))
    sftp = ssh.sftp(node)
    with ssh.update_file(sftp, bridge_file) as (old, new):
        found_bridge_port_line = False
        for line in old:
            if line.startswith('bridge_ports'):
                found_bridge_port_line = True
                if port['name'] not in line:
                    option, _, ports = line.rstrip().partition(' ')
                    line = "{0} {1} {2}\n".format(option, port['name'], ports)
            new.write(line)
        if not found_bridge_port_line:
            new.write('bridge_ports {0}\n'.format(port['name']))
Exemple #8
0
 def postdeploy(self):
     # From neutron_update_admin_tenant_id
     sftp = ssh.sftp(self.node)
     with ssh.update_file(sftp, '/etc/neutron/neutron.conf') as (old, new):
         for line in old:
             if line.startswith('nova_admin_tenant_id'):
                 new.write('nova_admin_tenant_id = {0}\n'.format(
                     self.service_tenant_id))
             else:
                 new.write(line)
     ssh.call(['restart', 'neutron-server'], node=self.node)
     if self.isolated:
         # From restore_default_gateway
         ssh.call(['ip', 'route', 'delete', 'default'], node=self.node)
         ssh.call(['ip', 'route', 'add', 'default', 'via', self.gateway],
                  node=self.node)
Exemple #9
0
    def postdeploy(self):
        # From neutron_update_admin_tenant_id
        sftp = ssh.sftp(self.node)
        with ssh.update_file(sftp, '/etc/neutron/neutron.conf') as (old, new):
            for line in old:
                if line.startswith('nova_admin_tenant_id'):
                    new.write('nova_admin_tenant_id = {0}\n'.format(
                        self.service_tenant_id))
                else:
                    new.write(line)
        orig_version = self.orig_env.data["fuel_version"]
        if orig_version == "6.1":
            openstack_release = magic_consts.VERSIONS[orig_version]
            node_util.add_compute_upgrade_levels(self.node, openstack_release)

            nova_services = ssh.call_output(
                ["bash", "-c",
                 "initctl list | "
                 "awk '/nova/ && /start/ {print $1}' | tr '\n' ' '"],
                node=self.node
            )

            for nova_service in nova_services.split():
                ssh.call(["service", nova_service, "restart"], node=self.node)

        ssh.call(['restart', 'neutron-server'], node=self.node)
        if self.isolated and self.gateway:
            # From restore_default_gateway
            LOG.info("Deleting default route at node %s",
                     self.node.id)
            try:
                ssh.call(['ip', 'route', 'delete', 'default'], node=self.node)
            except subprocess.CalledProcessError as exc:
                LOG.warn("Cannot delete default route at node %s: %s",
                         self.node.id, exc.args[0])
            LOG.info("Set default route at node %s: %s",
                     self.node.id, self.gateway)
            ssh.call(['ip', 'route', 'add', 'default', 'via', self.gateway],
                     node=self.node)
Exemple #10
0
def add_compute_upgrade_levels(node, version):
    sftp = ssh.sftp(node)
    with ssh.update_file(sftp, '/etc/nova/nova.conf') as (old, new):
        add_upgrade_levels = True
        in_section = False
        for line in old:
            if line.startswith("[upgrade_levels]"):
                add_upgrade_levels = False
                in_section = True
                new.write(line)
                new.write("compute={0}\n".format(version))
                continue
            if in_section and line.startswith("["):
                in_section = False
            if in_section and line.startswith("compute="):
                LOG.warning(
                    "Skipping line so not to duplicate compute "
                    "upgrade level setting: %s" % line.rstrip())
                continue
            new.write(line)
        if add_upgrade_levels:
            new.write("[upgrade_levels]\ncompute={0}\n".format(version))
Exemple #11
0
 def postdeploy(self):
     # From neutron_update_admin_tenant_id
     sftp = ssh.sftp(self.node)
     with ssh.update_file(sftp, '/etc/neutron/neutron.conf') as (old, new):
         for line in old:
             if line.startswith('nova_admin_tenant_id'):
                 new.write('nova_admin_tenant_id = {0}\n'.format(
                     self.service_tenant_id))
             else:
                 new.write(line)
     ssh.call(['restart', 'neutron-server'], node=self.node)
     if self.isolated and self.gateway:
         # From restore_default_gateway
         LOG.info("Deleting default route at node %s", self.node.id)
         try:
             ssh.call(['ip', 'route', 'delete', 'default'], node=self.node)
         except subprocess.CalledProcessError as exc:
             LOG.warn("Cannot delete default route at node %s: %s",
                      self.node.id, exc.args[0])
         LOG.info("Set default route at node %s: %s", self.node.id,
                  self.gateway)
         ssh.call(['ip', 'route', 'add', 'default', 'via', self.gateway],
                  node=self.node)
Exemple #12
0
    def postdeploy(self):
        # From neutron_update_admin_tenant_id
        sftp = ssh.sftp(self.node)
        with ssh.update_file(sftp, '/etc/neutron/neutron.conf') as (old, new):
            for line in old:
                if line.startswith('nova_admin_tenant_id'):
                    new.write('nova_admin_tenant_id = {0}\n'.format(
                        self.service_tenant_id))
                else:
                    new.write(line)
        orig_version = self.orig_env.data["fuel_version"]
        if orig_version == "6.1":
            openstack_release = magic_consts.VERSIONS[orig_version]
            node_util.add_compute_upgrade_levels(self.node, openstack_release)

            nova_services = ssh.call_output([
                "bash", "-c", "initctl list | "
                "awk '/nova/ && /start/ {print $1}' | tr '\n' ' '"
            ],
                                            node=self.node)

            for nova_service in nova_services.split():
                ssh.call(["service", nova_service, "restart"], node=self.node)

        ssh.call(['restart', 'neutron-server'], node=self.node)
        if self.isolated and self.gateway:
            # From restore_default_gateway
            LOG.info("Deleting default route at node %s", self.node.id)
            try:
                ssh.call(['ip', 'route', 'delete', 'default'], node=self.node)
            except subprocess.CalledProcessError as exc:
                LOG.warn("Cannot delete default route at node %s: %s",
                         self.node.id, exc.args[0])
            LOG.info("Set default route at node %s: %s", self.node.id,
                     self.gateway)
            ssh.call(['ip', 'route', 'add', 'default', 'via', self.gateway],
                     node=self.node)
Exemple #13
0
 def postdeploy(self):
     # From neutron_update_admin_tenant_id
     sftp = ssh.sftp(self.node)
     with ssh.update_file(sftp, '/etc/neutron/neutron.conf') as (old, new):
         for line in old:
             if line.startswith('nova_admin_tenant_id'):
                 new.write('nova_admin_tenant_id = {0}\n'.format(
                     self.service_tenant_id))
             else:
                 new.write(line)
     ssh.call(['restart', 'neutron-server'], node=self.node)
     if self.isolated and self.gateway:
         # From restore_default_gateway
         LOG.info("Deleting default route at node %s",
                  self.node.id)
         try:
             ssh.call(['ip', 'route', 'delete', 'default'], node=self.node)
         except subprocess.CalledProcessError as exc:
             LOG.warn("Cannot delete default route at node %s: %s",
                      self.node.id, exc.args[0])
         LOG.info("Set default route at node %s: %s",
                  self.node.id, self.gateway)
         ssh.call(['ip', 'route', 'add', 'default', 'via', self.gateway],
                  node=self.node)
Exemple #14
0
def change_fsid(conf_file_path, node, fsid):
    with ssh.update_file(ssh.sftp(node), conf_file_path) as (old, new):
        for line in old:
            if line.startswith("fsid"):
                line = u"fsid = {0}\n".format(fsid)
            new.write(line)