def create_network(self, name, network, public=None): cidr = IPv4Network(network) cidr_e = cidr.exploded cidr_gw = (cidr.network_address + 1).exploded cidr_start = (cidr.network_address + 2).exploded cidr_end = (cidr.broadcast_address - 1).exploded try: LOG.debug("checking if network '{0}' exists".format(name)) util.run_command("neutron net-show %s" % name, environ=self._env) except: LOG.debug("creating network '{0}'".format(name)) cmd = "neutron net-create %s" % name if public: cmd += (" --provider:physical_network public" " --shared --provider:network_type flat") util.run_command(cmd, environ=self._env) cmd = ("neutron subnet-create %s %s --name %s" " --gateway %s" % (name, cidr_e, name, cidr_gw)) if public: cmd += (" --allocation-pool start=%s,end=%s" % (cidr_start, cidr_end)) util.run_command(cmd, environ=self._env) if public: util.run_command("neutron net-update %s --router:external" % name, environ=self._env)
def ceilometer_enable(self, configfile): LOG.debug("setting up rabbitmq configuration" " in '{0}'".format(configfile)) self.config_rabbitmq(configfile) config = ("[DEFAULT]\n" "notification_driver = messagingv2\n") util.write_config(configfile, config)
def create_role(self, role): LOG.debug("setting up %s role" % role) try: util.run_command("openstack role show %s" % role, environ=self._env) except: util.run_command("openstack role create %s" % role, environ=self._env)
def start_server(self, services=None): services = services or self._services LOG.debug("Starting services") util.run_command("systemctl enable %s" % " ".join(services)) for service in services: if service.endswith(".socket"): util.run_command("systemctl stop %s" % service.replace(".socket", ".service")) util.run_command("systemctl restart %s" % service)
def sync_database(self): LOG.debug("populating neutron database") util.run_command('su -s /bin/sh -c "neutron-db-manage ' '--config-file /etc/neutron/neutron.conf ' '--config-file /etc/neutron/plugins/ml2/ml2_conf.ini ' 'upgrade head" neutron') if util.str2bool(CONF['CONFIG_LBAAS_INSTALL']): util.run_command('su -s /bin/sh -c "neutron-db-manage ' '--service lbaas upgrade head"')
def create_domain(self, domain, description): LOG.debug("setting up %s domain" % domain) try: """ test if domain already exists """ util.run_command("openstack domain show %s" % domain, environ=self._env) except: util.run_command("openstack domain create --description \"%s\" %s" % (description, domain), environ=self._env, debug=False)
def create_project(self, project, description): LOG.debug("setting up %s project" % project) try: """ test if project already exists """ util.run_command("openstack project show %s" % project, environ=self._env) except: util.run_command( "openstack project create --domain default" ' --description "%s" %s' % (description, project), environ=self._env, )
def create_project(self, project, description): try: """ test if project already exists """ LOG.debug("checking if project '{0}' exists".format(project)) util.run_command("openstack project show %s" % project, environ=self._env) except: LOG.debug("setting up project '{0}'".format(project)) util.run_command("openstack project create --domain default" " --description \"%s\" %s" % (description, project), environ=self._env)
def start_server(self): LOG.debug("starting services") util.run_command("systemctl enable mongodb") util.run_command("systemctl restart mongodb") count = 0 while count < 10: try: util.run_command("mongo --host 127.0.0.1") return except: util.run_command("sleep 1") count += 1 raise Exception("Failed to start mongodb service")
def configure(self): config_file = "/etc/mariadb/openstack.cnf" config = """ [mysqld] default-storage-engine = innodb innodb_file_per_table collation-server = utf8_general_ci init-connect = 'SET NAMES utf8' character-set-server = utf8 bind-address = 0.0.0.0 """ LOG.debug("configuring mariadb options in '{0}'".format(config_file)) util.write_config(config_file, config)
def create_service(self, name=None, description=None, type=None): name = name or self._name description = description or self._description type = type or self._type LOG.debug("setting up %s service" % name) try: """ test if service already exists """ util.run_command("openstack service show %s" % name, environ=self._env) except: util.run_command("openstack service create %s" " --name %s --description \"%s\"" % (type, name, description), environ=self._env)
def create_router(self, router, gw, interfaces): try: LOG.debug("checking if router '{0}' exists".format(router)) util.run_command("neutron router-show %s" % router, environ=self._env) except: LOG.debug("creating router '{0}'".format(router)) util.run_command("neutron router-create %s" % router, environ=self._env) util.run_command("neutron router-gateway-set %s %s" % (router, gw), environ=self._env) for i in interfaces: util.run_command("neutron router-interface-add %s %s" % (router, i), environ=self._env)
def create_image(self, name, format, url, public=False): LOG.debug("Creating image %s" % name) try: util.run_command("openstack image show %s" % name, environ=self._env) except: command = ("openstack image create --disk-format %s %s" % (format, name)) if os.path.isfile(url): command += " --file %s" % url else: command += " --location %s" % url if public: command += " --public" util.run_command(command, environ=self._env)
def create_user(self, user=None, password=None, domain="default", project="service", role="admin"): user = user or self._user password = password or self._password LOG.debug("setting up %s user" % user) try: """ test if user already exists """ util.run_command("openstack user show %s" % user, environ=self._env) except: util.run_command("openstack user create --domain {0}" " --password={1}" " --email {2}@example.com {2}" .format(domain, password, user), environ=self._env, debug=False) self.add_role(user, role, project, domain)
def setup_database(self, database, user, password): LOG.debug("setting up '{0}' database".format(database)) mariadb_user = CONF["CONFIG_MARIADB_USER"] mariadb_pw = CONF["CONFIG_MARIADB_PW"] util.run_command("mysql -u{0} -p{1} -e" " \"CREATE DATABASE if not exists {2};\"" .format(mariadb_user, mariadb_pw, database), debug=False) util.run_command("mysql -u{0} -p{1} -e" " \"GRANT ALL PRIVILEGES ON {2}.* TO" " '{3}'@'localhost' IDENTIFIED BY '{4}';\"" .format(mariadb_user, mariadb_pw, database, user, password), debug=False) util.run_command("mysql -u{0} -p{1} -e" " \"GRANT ALL PRIVILEGES ON {2}.* TO '{3}'@'%'" " IDENTIFIED BY '{4}';\"" .format(mariadb_user, mariadb_pw, database, user, password), debug=False)
def secure_installation(self, user, password): LOG.debug("calling mariadb secure installation") try: """ test if mysql has a password """ util.run_command("mysql -u{0} -e \"\"".format(user), debug=False) """ Secure the database service """ util.run_command('mysqladmin -u root password "{0}"' .format(password, debug=False)) util.run_command('mysql -u root -p"{0}" -e "UPDATE mysql.user ' 'SET Password=PASSWORD(\'{0}\') ' 'WHERE User=\'root\'"' .format(password, debug=False)) util.run_command('mysql -u root -p"{0}" -e "DELETE FROM ' 'mysql.user WHERE User=\'root\' AND Host ' ' NOT IN (\'localhost\', \'127.0.0.1\', ' '\'::1\')"' .format(password, debug=False)) util.run_command('mysql -u root -p"{0}" -e "DELETE FROM ' 'mysql.user WHERE User=\'\'"' .format(password, debug=False)) util.run_command('mysql -u root -p"{0}" -e "DELETE FROM mysql.db ' 'WHERE Db=\'test\' OR Db=\'test\_%\'"' .format(password, debug=False)) util.run_command('mysql -u root -p"{0}" -e ' '"FLUSH PRIVILEGES"' .format(password, debug=False)) except: pass try: """ verify the password """ util.run_command("mysql -u{0} -p{1} -e \"\"" .format(user, password), debug=False) except: LOG.error("clearstack: cannot connect to mysql database," " the password is incorrect") return sys.exit(1)
def create_endpoint(self, publicurl=None, internalurl=None, adminurl=None, region=None, type=None): publicurl = publicurl or self._public_url internalurl = internalurl or self._internal_url adminurl = adminurl or self._admin_url region = region or self._region type = type or self._type LOG.debug("creating endpoint") """ test if endpoint already exists """ out, err = util.run_command("openstack endpoint list | grep %s" % self._name, environ=self._env) if not out: cmd = ("openstack endpoint create --region {0} {1}" .format(region, type)) util.run_command(cmd + " public {0}".format(publicurl), environ=self._env) util.run_command(cmd + " internal {0}".format(internalurl), environ=self._env) util.run_command(cmd + " admin {0}".format(adminurl), environ=self._env)
def user_exists(self, user): stdout = None stderr = None try: LOG.debug("Checking if rabbitmq user '{0}' exists".format(user)) stdout, stderr = util.run_command("rabbitmqctl list_users" " | grep {0}".format(user)) except: pass if not stdout: LOG.debug("rabbitmq user '{0}' does not exists".format(user)) return False LOG.debug("rabbitmq user '{0}' does exists".format(user)) return True
def start_server(self): LOG.debug("starting services") util.run_command("systemctl enable rabbitmq-server") util.run_command("systemctl restart rabbitmq-server")
def start_server(self): LOG.debug("enabling rabbitmq-server service") self.enable_server() status = util.service_status("rabbitmq-server.service") LOG.debug("rabbitmq-server status: " + status) if status == "active": LOG.debug("rabbitmq-server service is already running") return elif status == "inactive" or status == "unknown": LOG.debug("starting rabbitmq-server service") util.run_command("systemctl restart rabbitmq-server") elif status == "failed": # try to re-run the service, catch the error if fails again try: LOG.debug("rabbitmq-server failed to start previously. " "Trying to start service...") util.run_command("systemctl restart rabbitmq-server") except: LOG.debug("rabbitmq-server.service failed to start." "Try 'rm -rf /var/lib/rabbitmq/*' and re-run" "clearstack") sys.exit(1) else: LOG.debug("Error: rabbitmq-server service status" " '{0}' unknown... Exiting clearstack".format(status)) sys.exit(1)
def add_user(self, auth_user, auth_pw): """ todo: what we do with guest """ LOG.debug("adding rabbitmq user '{0}'".format(auth_user)) if not self.user_exists(auth_user): util.run_command("rabbitmqctl add_user {0} {1}" .format(auth_user, auth_pw), debug=False)
def start_server(self): LOG.debug("starting mariadb service") util.run_command("systemctl enable mariadb") util.run_command("systemctl restart mariadb")
def delete_user(self, user): LOG.debug("deleting rabbitmq user '{0}'".format(user)) util.run_command("rabbitmqctl delete_user {1}" .format(user))
def sync_database(self): LOG.debug("populating keystone database") util.run_command("su -s /bin/sh -c" " \"keystone-manage db_sync\" keystone")
def sync_database(self): LOG.debug("populating heat database") util.run_command("su -s /bin/sh -c" " \"heat-manage db_sync\" heat")
def set_permissions(self, auth_user, permissions): LOG.debug("setting rabbitmq permissions for " "user '{0}'".format(auth_user)) util.run_command("rabbitmqctl set_permissions {0} {1}" .format(auth_user, permissions))
def sync_database(self): LOG.debug("syncing database") util.run_command("su -s /bin/sh -c \"sahara-db-manage upgrade head\" sahara")
def sync_database(self): LOG.debug("populating nova database") util.run_command("su -s /bin/sh -c \"nova-manage db sync\" nova")
def sync_database(self): LOG.debug("populating glance database") util.run_command("su -s /bin/sh -c" " \"glance-manage db_sync\" glance")
def sync_database(self): LOG.debug("syncing database") util.run_command("su -s /bin/sh -c" ' "keystone-manage db_sync" keystone')