Example #1
0
def ensure(**kwargs):
    """ Ensure that the hostname for each host is set correctly according to parameters. """
    if env.host in kwargs:
        if is_debian_or_ubuntu():
            run("""echo "%s" > /etc/hostname""" % kwargs[env.host])
            run("""sysctl kernel.hostname=%s""" % kwargs[env.host])

            import service
            svc = {"hostname.sh": "restarted"}
            service.ensure(**svc)
Example #2
0
def ensure(**kwargs):
    """ Ensure that the hostname for each host is set correctly according to parameters. """
    if env.host in kwargs:
        if is_debian_or_ubuntu():
            run("""echo "%s" > /etc/hostname""" % kwargs[env.host])
            run("""sysctl kernel.hostname=%s""" % kwargs[env.host])
            
            import service
            svc = {"hostname.sh":"restarted"}
            service.ensure(**svc)
Example #3
0
def deploy():
    """ Install and configure and start cups client. """
    if not is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return
    
    import apt, service
    packages = {"cupsys":"latest", "cups-client":"latest"}
    apt.ensure(**packages)
    configure()
    service.ensure(cupsys="restarted")
Example #4
0
def deploy(server=config.get("syslog_client", {}).get("syslog_server", ""),
           proto=config.get("syslog_client", {}).get("syslog_proto", ""),
           port=config.get("syslog_client", {}).get("syslog_port", ""),
           scope=config.get("syslog_client", {}).get("syslog_scope", "")):
    """ Configure and re-start syslog. """
    if not is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return

    with cd("/etc/init.d"):
        svcn = run("ls -1 *sys*log*")
        svcn = svcn.split("\n")[0]

    if exists("/etc/syslog.conf"):
        conf = "/etc/syslog.conf"
    elif exists("/etc/rsyslog.conf"):
        conf = "/etc/rsyslog.conf"

    with hide("running", "stdout", "stderr"):
        config = run("cat %s" % conf)
    line = "%s  %s%s:%s" % (scope, "@@" if proto == "tcp" else "@", server,
                            port)

    if config.find(server) > -1:
        # Check if current config matches existing config
        if config.find(line) > -1:
            print green("%s: No changes necessary" % env.host)
            return True
        else:
            config_lines = config.split("\n")
            for i, l in enumerate(config_lines):
                if l.find(server) > -1:
                    config_lines[i] = line
                    break
            config = "\n".join(config_lines)
            config += "\n"
    else:
        config = ("\n" + line + "\n") + config
        config = config.replace("\n\n", "\n")

    fn = os.path.join("templates", uuid.uuid1().hex)

    with open(fn, "wb") as outf:
        outf.write(config)

    # Put the file on the server
    upload_template(fn, conf)
    os.remove(fn)

    kw = {}
    kw[svcn] = "restarted"
    import service
    service.ensure(**kw)
def deploy(server=config.get("syslog_client", {}).get("syslog_server", ""),
            proto=config.get("syslog_client", {}).get("syslog_proto", ""),
            port=config.get("syslog_client", {}).get("syslog_port", ""),
            scope=config.get("syslog_client", {}).get("syslog_scope", "")):
    """ Configure and re-start syslog. """
    if not is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return
    
    with cd("/etc/init.d"):
        svcn = run("ls -1 *sys*log*")
        svcn = svcn.split("\n")[0]
        
    if exists("/etc/syslog.conf"):
        conf = "/etc/syslog.conf"
    elif exists("/etc/rsyslog.conf"):
        conf = "/etc/rsyslog.conf"
    
    with hide("running", "stdout", "stderr"):
        config = run("cat %s" % conf)
    line = "%s  %s%s:%s" % (scope, "@@" if proto == "tcp" else "@", server, port)
    
    if config.find(server) > -1:
        # Check if current config matches existing config
        if config.find(line) > -1:
            print green("%s: No changes necessary" % env.host)
            return True
        else:
            config_lines = config.split("\n")
            for i, l in enumerate(config_lines):
                if l.find(server) > -1:
                    config_lines[i] = line
                    break
            config = "\n".join(config_lines)
            config += "\n"
    else:
        config = ("\n" + line + "\n") + config
        config = config.replace("\n\n", "\n")
    
    fn = os.path.join("templates", uuid.uuid1().hex)
    
    with open(fn, "wb") as outf:
        outf.write(config)
    
    # Put the file on the server
    upload_template(fn, conf)
    os.remove(fn)
    
    kw = {}
    kw[svcn] = "restarted"
    import service
    service.ensure(**kw)
Example #6
0
def ensure_workers(cfn,
                   config,
                   server_ip,
                   current_count,
                   lower_count=-1,
                   upper_count=-1,
                   force_update=False):
  "Ensures that the build workers conform to spec."
  if server_ip == "NULL":
    if upper_count == 0:
      return service.Response.UpToDate
    return service.Response.WaitingForPrecondition
  auth_info = auth.get_authenticator(config).get_server_auth_info()
  return service.ensure(
      cfn,
      stack_name=config["stacks"]["workers"],
      template_body=template('worker.yaml'),
      parameters={
          "StackName": config["stacks"]["infra"],
          "ServerIP": server_ip,
          "WorkerImage": config["worker_image"],
          "LogsRegion": config["awslogs_region"],
          "LogsGroup": config["awslogs_group"],
          "TrustCertCollection": auth_info["ca_crt"],
          "ClientPrivateKey": auth_info["client_pkcs8_key"],
          "WorkerCertChain": auth_info["client_crt"],
      },
      current_count=current_count,
      lower_count=lower_count,
      upper_count=upper_count,
      force_update=force_update)
Example #7
0
def ensure_servers(cfn,
                   config,
                   current_count,
                   lower_count=-1,
                   upper_count=-1,
                   force_update=False):
  """Ensure that the build servers conform to spec."""
  auth_info = auth.get_authenticator(config).get_server_auth_info()
  return service.ensure(
      cfn,
      stack_name=config["stacks"]["server"],
      template_body=template('server.yaml'),
      parameters={
          "StackName": config["stacks"]["infra"],
          "ServerImage": config["server_image"],
          "LogsRegion": config["awslogs_region"],
          "LogsGroup": config["awslogs_group"],
          "CertChain": auth_info["server_crt"],
          "PrivateKey": auth_info["server_pkcs8_key"],
          "ClientCertChain": auth_info["ca_crt"],
      },
      current_count=current_count,
      lower_count=lower_count,
      upper_count=upper_count,
      force_update=force_update)
Example #8
0
def deploy():
    """ Install, configure and start snmpd. """
    if not is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return
    
    import apt, service
    packages = {"snmpd":"latest"}
    if run("cat /etc/issue").find("6.0") > -1:
        # its debian 6
        packages["snmp-mibs-downloader"] = "installed"
        
    apt.ensure(**packages)
    
    configure()
    service.ensure(snmpd="restarted")
Example #9
0
 def test_current_count_is_desired_count(self):
     resp = service.ensure(cfn=None,
                           stack_name="my_stack_name",
                           template_body="my_template_body",
                           parameters={},
                           current_count=10,
                           lower_count=5,
                           upper_count=15)
     self.assertEqual(resp, service.Response.UpToDate)
Example #10
0
def deploy(server=config.get("ntp_client", {}).get("ntp_server", "")):
    """ Install, configure and start ntp sync and timezone. """
    if not is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return
        
    import apt, service
    packages = {"ntp":"latest", "ntpdate":"latest"}
    apt.ensure(**packages)
    configure()
    
    # Sync with server
    run("ntpdate %s" % server)
    
    # Sync hardware clock to correct time
    run("hwclock --systohc")
    
    service.ensure(ntp="restarted")
    timezone()
Example #11
0
def deploy(server=config.get("ntp_client", {}).get("ntp_server", "")):
    """ Install, configure and start ntp sync and timezone. """
    if not is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return

    import apt, service
    packages = {"ntp": "latest", "ntpdate": "latest"}
    apt.ensure(**packages)
    configure()

    # Sync with server
    run("ntpdate %s" % server)

    # Sync hardware clock to correct time
    run("hwclock --systohc")

    service.ensure(ntp="restarted")
    timezone()
Example #12
0
def deploy():
    """ Install, configure and start webmin. """
    
    if not utils.is_debian_or_ubuntu():
        print red("Cannot deploy to non-debian/ubuntu host: %s" % env.host)
        return
        
    # Check if webmin is installed
    installed, upgradeable = apt.status("webmin")
    if not installed:
        packages = {
            "libnet-ssleay-perl":"latest",
            "libauthen-pam-perl":"latest",
            "libio-pty-perl":"latest",
            "libmd5-perl":"latest"
        }
        apt.ensure(**packages)
        download()
        install()
    
    service.ensure(webmin="running")
Example #13
0
def enabled(**kwargs):
    """ Ensure nginx web proxying to a sub-domain is enabled """
    if len(kwargs) < 1:
        usage()
    changed = False
    
    for sub, url in kwargs.iteritems():
        template = "web_nginx.template"
        if url.lower().startswith("https:"):
            template = "web_ssl_nginx.template"
        
        params = {}
        params.update(config.get("web", {}))
        params['sub'] = sub
        params['url'] = url
        
        changed = changed or reconfigure(template, params, "/etc/nginx/sites-available/%s" % sub)
        if not exists("/etc/nginx/sites-enabled/%s" % sub):
            changed = True
            run("ln -s /etc/nginx/sites-available/%s /etc/nginx/sites-enabled/%s" % (sub, sub))
    if changed:
        import service
        service.ensure(nginx="restarted")
Example #14
0
    def test_already_updating(self):
        cfn = boto3.client('cloudformation', region_name="eu-west-1")
        stubber = Stubber(cfn)
        _add_describe_stacks_response(stubber, StackStatus="test")
        stubber.activate()

        resp = service.ensure(cfn=cfn,
                              stack_name="my_stack_name",
                              template_body="my_template_body",
                              parameters={},
                              current_count=5,
                              lower_count=10)
        self.assertEqual(resp, service.Response.AlreadyUpdating)
        stubber.assert_no_pending_responses()
Example #15
0
    def test_nothing_to_update(self):
        cfn = boto3.client('cloudformation', region_name="eu-west-1")
        stubber = Stubber(cfn)
        _add_describe_stacks_response(stubber, StackStatus="CREATE_COMPLETE")
        stubber.add_client_error(
            "update_stack", service_message="No updates are to be performed.")
        stubber.activate()

        resp = service.ensure(cfn=cfn,
                              stack_name="my_stack_name",
                              template_body="my_template_body",
                              parameters={},
                              current_count=5,
                              lower_count=10)
        self.assertEqual(resp, service.Response.UpToDate)
        stubber.assert_no_pending_responses()