コード例 #1
0
ファイル: neutron.py プロジェクト: clearlinux/clearstack
 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)
コード例 #2
0
ファイル: neutron.py プロジェクト: clearlinux/clearstack
 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)
コード例 #3
0
ファイル: openstack.py プロジェクト: clearlinux/clearstack
 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)
コード例 #4
0
ファイル: openstack.py プロジェクト: clearlinux/clearstack
 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)
コード例 #5
0
ファイル: neutron.py プロジェクト: clearlinux/clearstack
 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"')
コード例 #6
0
ファイル: openstack.py プロジェクト: clearlinux/clearstack
 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)
コード例 #7
0
ファイル: keystone.py プロジェクト: jlrivera28/clearstack
 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,
         )
コード例 #8
0
ファイル: keystone.py プロジェクト: clearlinux/clearstack
 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)
コード例 #9
0
ファイル: mongodb.py プロジェクト: clearlinux/clearstack
 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")
コード例 #10
0
ファイル: mariadb.py プロジェクト: clearlinux/clearstack
 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)
コード例 #11
0
ファイル: neutron.py プロジェクト: clearlinux/clearstack
 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)
コード例 #12
0
ファイル: openstack.py プロジェクト: clearlinux/clearstack
 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)
コード例 #13
0
ファイル: glance.py プロジェクト: jlrivera28/clearstack
 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)
コード例 #14
0
ファイル: openstack.py プロジェクト: clearlinux/clearstack
 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)
コード例 #15
0
ファイル: mariadb.py プロジェクト: clearlinux/clearstack
 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)
コード例 #16
0
ファイル: mariadb.py プロジェクト: clearlinux/clearstack
    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)
コード例 #17
0
ファイル: openstack.py プロジェクト: clearlinux/clearstack
    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)
コード例 #18
0
ファイル: rabbitmq.py プロジェクト: clearlinux/clearstack
    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
コード例 #19
0
ファイル: swupd.py プロジェクト: clearlinux/clearstack
    def install(bundle):
        if not os.path.isfile("/usr/share/clear/bundles/" + str(bundle)) and \
            not os.path.isfile("/usr/share/clear/bundles/"
                               "openstack-all-in-one"):
            LOG.info("Installing {0} bundle".format(bundle))
            cmd = "clr_bundle_add -V {0}".format(bundle)
            if(os.path.isfile("/bin/swupd")):
                cmd = "swupd bundle-add -V {0}".format(bundle)

            try:
                stdout, stderr = util.run_command(cmd)
                if stderr:
                    LOG.error("swupd bundle-add: {0}\n{1}"
                              .format(stdout, stderr))
            except Exception:
                LOG.error("clearstack: cannot install"
                          " {0} bundle".format(bundle))
コード例 #20
0
ファイル: glance.py プロジェクト: clearlinux/clearstack
 def sync_database(self):
     LOG.debug("populating glance database")
     util.run_command("su -s /bin/sh -c"
                      " \"glance-manage db_sync\" glance")
コード例 #21
0
ファイル: rabbitmq.py プロジェクト: clearlinux/clearstack
 def delete_user(self, user):
     LOG.debug("deleting rabbitmq user '{0}'".format(user))
     util.run_command("rabbitmqctl delete_user {1}"
                      .format(user))
コード例 #22
0
ファイル: rabbitmq.py プロジェクト: clearlinux/clearstack
 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))
コード例 #23
0
ファイル: mariadb.py プロジェクト: clearlinux/clearstack
 def start_server(self):
     LOG.debug("starting mariadb service")
     util.run_command("systemctl enable mariadb")
     util.run_command("systemctl restart mariadb")
コード例 #24
0
ファイル: sahara.py プロジェクト: jlrivera28/clearstack
 def sync_database(self):
     LOG.debug("syncing database")
     util.run_command("su -s /bin/sh -c \"sahara-db-manage upgrade head\" sahara")
コード例 #25
0
ファイル: keystone.py プロジェクト: clearlinux/clearstack
 def sync_database(self):
     LOG.debug("populating keystone database")
     util.run_command("su -s /bin/sh -c"
                      " \"keystone-manage db_sync\" keystone")
コード例 #26
0
ファイル: heat.py プロジェクト: clearlinux/clearstack
 def sync_database(self):
     LOG.debug("populating heat database")
     util.run_command("su -s /bin/sh -c"
                      " \"heat-manage db_sync\" heat")
コード例 #27
0
ファイル: nova.py プロジェクト: clearlinux/clearstack
 def sync_database(self):
     LOG.debug("populating nova database")
     util.run_command("su -s /bin/sh -c \"nova-manage db sync\" nova")
コード例 #28
0
ファイル: mariadb.py プロジェクト: jlrivera28/clearstack
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from common.util import LOG
from common import util
from modules.conf import CONF
from modules.mariadb import MariaDB

conf = CONF
mariadb = MariaDB.get()
mariadb_user = CONF["CONFIG_MARIADB_USER"]
mariadb_pw = CONF["CONFIG_MARIADB_PW"]

if util.str2bool(conf['CONFIG_MARIADB_INSTALL']):
    mariadb.install()
    mariadb.configure()
    mariadb.start_server()
    mariadb.secure_installation(mariadb_user, mariadb_pw)

databases = ['keystone', 'glance', 'nova', 'neutron', 'heat', 'sahara']

for database in databases:
    if database == 'keystone' or util.str2bool(conf['CONFIG_%s_INSTALL'
                                               % database.upper()]):
        LOG.info("Setting up mariadb for %s" % database)
        password = CONF['CONFIG_%s_DB_PW' % database.upper()]
        mariadb.setup_database(database, database, password)
コード例 #29
0
ファイル: rabbitmq.py プロジェクト: clearlinux/clearstack
 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)
コード例 #30
0
ファイル: keystone.py プロジェクト: jlrivera28/clearstack
 def sync_database(self):
     LOG.debug("syncing database")
     util.run_command("su -s /bin/sh -c" ' "keystone-manage db_sync" keystone')