def stop(self): r = self.ctx.r rv = self.ctx.rv p = self.ctx.props # get rid of rabbitmq bindings rabbitmqctl = get_rabbitmq_executable(p.input_ports.host) # the following commands run as root r(sudo_run_program, [rabbitmqctl, 'delete_user', p.config_port.username]) r(sudo_run_program, [rabbitmqctl, 'delete_vhost', p.config_port.vhost]) self.started = False
def start(self): r = self.ctx.r rv = self.ctx.rv p = self.ctx.props # set up rabbitmq connection rabbitmqctl = get_rabbitmq_executable(p.input_ports.host) # the following commands run as root pat = re.escape('Error: {user_already_exists,<<"' + p.config_port.username + '">>}') (rc, re_map) = rv(sudo_run_program_and_scan_results, [rabbitmqctl, 'add_user', p.config_port.username, p.config_port.password], {"pw_already_exists": pat}, log_output=True) if (not self.ctx.dry_run) and rc!=0 and re_map['pw_already_exists']==False: raise UserError(errors[ERR_ADD_USER], msg_args={"user":p.config_port.username, "id":p.id}, developer_msg="rc was %d" % rc) pat = re.escape('Error: {vhost_already_exists,<<"' + p.config_port.vhost + '">>}') (rc, re_map) = rv(sudo_run_program_and_scan_results, [rabbitmqctl, 'add_vhost', p.config_port.vhost], {"vhost_already_exists":pat}, log_output=True) if (not self.ctx.dry_run) and rc!=0 and \ re_map["vhost_already_exists"]==False: raise UserError(errors[ERR_ADD_VHOST], msg_args={"vhost":p.config_port.vhost, "id":p.id}, developer_msg="rc was %d" % rc) r(sudo_run_program, [rabbitmqctl, 'set_permissions', '-p', p.config_port.vhost, p.config_port.username, '.*', '.*', '.*']) self.started = True # no more root # make config file _format_str = \ """BROKER_HOST = "%(hostname)s" BROKER_PORT = %(portname)s BROKER_USER = "******" BROKER_PASSWORD = "******" BROKER_VHOST = "%(vhost)s" CELERY_RESULT_BACKEND = "amqp" """ substitutions = { "hostname" : p.input_ports.broker.BROKER_HOST, "portname" : p.input_ports.broker.BROKER_PORT, "username" : p.config_port.username, "password" : p.config_port.password, "vhost" : p.config_port.vhost, }