def save_conf(self, file_path=FLAGS.ceph_conf):
        utils.execute('chown',
                      '-R',
                      'vsm:vsm',
                      '/etc/ceph/',
                      run_as_root=True)

        self._parser.write(file_path)
        self._update_ceph_conf_into_db(self._parser.as_str())
    def save_conf(self, file_path=FLAGS.ceph_conf, rgw=False):
        utils.execute('chown',
                      '-R',
                      'vsm:vsm',
                      '/etc/ceph/',
                      run_as_root=True)

        self._parser.write(file_path, rgw)
        self._update_ceph_conf_into_db(self._parser.as_str(rgw))
 def _get_report(self):
     report = ""
     stderr = ""
     try:
         if self._keyring:
             (report, stderr) = utils.execute('ceph', 'report','--keyring',self._keyring, run_as_root=True)
         else:
             (report, stderr) = utils.execute('ceph', 'report', run_as_root=True)
         return json.loads(report)
     except exception.ProcessExecutionError:
         LOG.warn('Fail to get report from ceph: %s' % stderr)
 def _get_report(self):
     report = ""
     stderr = ""
     try:
         if self._keyring:
             (report, stderr) = utils.execute('ceph',
                                              'report',
                                              '--keyring',
                                              self._keyring,
                                              run_as_root=True)
         else:
             (report, stderr) = utils.execute('ceph',
                                              'report',
                                              run_as_root=True)
         return json.loads(report)
     except exception.ProcessExecutionError:
         LOG.warn('Fail to get report from ceph: %s' % stderr)
Пример #5
0
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    appnode = auth_openstack
    if not appnode:
        raise exception.AppNodeInvalidInfo()

    auth_url = appnode['os_auth_url'].strip("/")
    ssh_user = appnode['ssh_user']
    tenant_name = appnode['os_tenant_name']
    username = appnode['os_username']
    password = appnode['os_password']
    region_name = appnode['os_region_name']

    os_controller_host = auth_url.split(":")[1][2:]
    result, err = utils.execute('check_xtrust_crudini',
                                ssh_user,
                                os_controller_host,
                                run_as_root=True)
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception(
            "Please check the mutual trust between vsm controller node "
            "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    # support keystone v3 ad v2.0
    keystone_version = auth_url.split("/")[-1]
    try:
        if keystone_version == "v3":
            result = _check_v3(tenant_name, username, password, auth_url,
                               region_name)
        elif keystone_version == "v2.0":
            result = _check_v2(tenant_name, username, password, auth_url,
                               region_name)
        else:
            raise Exception("Only support keystone v3 and v2.0 now.")
        if result:
            appnode['ssh_status'] = "reachable"
        else:
            appnode['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode['ssh_status'] = "unreachable"

    ref = []
    try:
        ref.append(db.appnodes_create(contxt, appnode, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
def update(contxt, appnode_id, appnode):
    """update app node ssh status, log info or deleted"""
    if contxt is None:
        contxt = context.get_admin_context()

    id = utils.int_from_str(appnode_id)
    LOG.debug("app node id: %s " % id)

    os_tenant_name = appnode["os_tenant_name"]
    os_username = appnode["os_username"]
    os_password = appnode["os_password"]
    os_auth_url = appnode["os_auth_url"]
    os_region_name = appnode["os_region_name"]
    xtrust_user = appnode["xtrust_user"]

    novaclient = nc.Client(os_username, os_password, os_tenant_name, os_auth_url, region_name=os_region_name)
    nova_services = novaclient.services.list()
    nova_compute_hosts = []
    for nova_service in nova_services:
        if nova_service.binary == "nova-compute":
            nova_compute_hosts.append(nova_service.host)

    cinderclient = cc.Client(os_username, os_password, os_tenant_name, os_auth_url, region_name=os_region_name)
    cinder_services = cinderclient.services.list()
    cinder_volume_hosts = []
    for cinder_service in cinder_services:
        if cinder_service.binary == "cinder-volume":
            cinder_volume_hosts.append(cinder_service.host)

    hosts = list(set(nova_compute_hosts + cinder_volume_hosts))
    print hosts

    for host in hosts:
        result, err = utils.execute("check_xtrust_crudini", xtrust_user, host, run_as_root=True)
        LOG.info("==============result: %s" % result)
        LOG.info("==============result: %s" % err)
        if "command not found" in err:
            raise Exception("Command not found on %s" % host)
        if "Permission denied" in err:
            raise Exception("Please check the mutual trust between vsm nodes and openstack nodes")

    """validate openstack access info"""
    try:
        token_url_id = _get_token(os_tenant_name, os_username, os_password, os_auth_url, os_region_name)
        if token_url_id != None:
            appnode["ssh_status"] = "reachable"
        else:
            appnode["ssh_status"] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode["ssh_status"] = "unreachable"

    try:
        return db.appnodes_update(contxt, id, appnode)
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on updating Appnodes %s" % e))
        raise exception.AppNodeFailure()
Пример #7
0
    def _load_ceph_conf_from_db(self):
        if not self.cluster_id:
            if not self._get_cluster_id():
                LOG.debug('Can not get cluster_id')
                return

        ceph_conf = db.cluster_get_ceph_conf(self.context, self.cluster_id)

        if not ceph_conf:
            return

        utils.write_file_as_root(FLAGS.ceph_conf, ceph_conf, 'w')

        # We try to update fstab here.
        utils.execute('sed',
                      '-i',
                      '/forvsmosd/d',
                      '/etc/fstab',
                      run_as_root=True)

        parser = Parser()
        parser.read(FLAGS.ceph_conf)
        fs_type = parser.get('osd', 'osd mkfs type', 'xfs')
        cluster = db.cluster_get_all(self.context)[0]
        mount_option = cluster['mount_option']
        if not mount_option:
            mount_option = utils.get_fs_options(fs_type)[1]
        mount_attr = parser.get('osd', 'osd mount options %s' % fs_type,
                                mount_option)

        for sec in parser.sections():
            if sec.find('osd.') != -1:
                osd_id = sec.split('.')[1]
                mount_path = os.path.join(FLAGS.osd_data_path,
                                          "osd%s" % osd_id)
                mount_disk = parser.get(sec, 'devs')
                mount_host = parser.get(sec, 'host')
                if FLAGS.host == mount_host:
                    line = mount_disk + ' ' + mount_path
                    line = line + ' ' + fs_type
                    line = line + ' ' + mount_attr + ' 0 0'
                    line = line + ' ' + '## forvsmosd'
                    utils.write_file_as_root('/etc/fstab', line)
    def _get_report(self):
        report = ""
        stderr = ""

        try:
            (report, stderr) = utils.execute('ceph', 'report', run_as_root=True)

            return report
        except exception.ProcessExecutionError:
            LOG.warn('Fail to get report from ceph: %s' % stderr)
Пример #9
0
def qemu_img_info(path):
    """Return a object containing the parsed output from qemu-img info."""
    out, err = utils.execute('env',
                             'LC_ALL=C',
                             'LANG=C',
                             'qemu-img',
                             'info',
                             path,
                             run_as_root=True)
    return QemuImgInfo(out)
    def _load_ceph_conf_from_db(self):
        if not self.cluster_id:
            if not self._get_cluster_id():
                LOG.debug('Can not get cluster_id')
                return

        ceph_conf = db.cluster_get_ceph_conf(self.context,
                                             self.cluster_id)

        if not ceph_conf:
            return

        utils.write_file_as_root(FLAGS.ceph_conf, ceph_conf, 'w')

        # We try to update fstab here.
        utils.execute('sed',
                      '-i',
                      '/forvsmosd/d',
                      '/etc/fstab',
                      run_as_root=True)

        parser = Parser()
        parser.read(FLAGS.ceph_conf)
        fs_type = parser.get('osd', 'osd mkfs type', 'xfs')
        cluster = db.cluster_get_all(self.context)[0]
        mount_option = cluster['mount_option']
        if not mount_option:
            mount_option = utils.get_fs_options(fs_type)[1]
        mount_attr = parser.get('osd', 'osd mount options %s' % fs_type, mount_option)

        for sec in parser.sections():
            if sec.find('osd.') != -1:
                osd_id = sec.split('.')[1]
                mount_path = os.path.join(FLAGS.osd_data_path, "osd%s" % osd_id)
                mount_disk = parser.get(sec, 'devs')
                mount_host = parser.get(sec, 'host')
                if FLAGS.host == mount_host:
                    line = mount_disk + ' ' + mount_path
                    line = line + ' ' + fs_type
                    line = line + ' ' + mount_attr + ' 0 0'
                    line = line + ' ' + '## forvsmosd'
                    utils.write_file_as_root('/etc/fstab', line)
Пример #11
0
def _get_lines(fp):
    content = utils.execute('cat', fp, run_as_root=True)[0]
    lines = content.split('\n')

    temp = []
    for x in lines:
        if x.startswith('class'):
            temp.append(x)
        if x.startswith('    message = _('):
            temp.append(x)
    return temp
def _get_lines(fp):
    content = utils.execute('cat', fp, run_as_root=True)[0]
    lines = content.split('\n')

    temp = []
    for x in lines:
        if x.startswith('class'):
            temp.append(x)
        if x.startswith('    message = _('):
            temp.append(x)
    return temp
Пример #13
0
    def _get_report(self):
        report = ""
        stderr = ""

        try:
            (report, stderr) = utils.execute('ceph',
                                             'report',
                                             run_as_root=True)

            return report
        except exception.ProcessExecutionError:
            LOG.warn('Fail to get report from ceph: %s' % stderr)
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    os_controller_host = auth_openstack['os_auth_url'].split(":")[1][2:]
    result, err = utils.execute(
            'check_xtrust_crudini',
            auth_openstack['ssh_user'],
            os_controller_host,
            run_as_root = True
    )
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception("Please check the mutual trust between vsm controller node "
                        "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    ref = []

    """validate openstack access info"""
    try:
        token_url_id = _get_token(
            auth_openstack['os_tenant_name'],
            auth_openstack['os_username'],
            auth_openstack['os_password'],
            auth_openstack['os_auth_url'],
            auth_openstack['os_region_name']
        )
        if token_url_id != None:
            auth_openstack['ssh_status'] = "reachable"
        else:
            auth_openstack['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack['ssh_status'] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
Пример #15
0
def get_ceph_version():
    """

    Get the ceph version from ceph cluster.
    Run command "ceph --version" to get it.

    :return: string: version
    """

    args = ["ceph", "--version"]
    try:
        out, err = utils.execute(*args, run_as_root=True)
        version = out.split(" ")[2]
    except:
        version = ""
    return version
def update(contxt, appnode_id, appnode):
    """update app node ssh status, log info or deleted"""
    if contxt is None:
        contxt = context.get_admin_context()

    id = utils.int_from_str(appnode_id)
    LOG.debug('app node id: %s ' % id)

    os_controller_host = appnode['os_auth_url'].split(":")[1][2:]
    result, err = utils.execute(
            'check_xtrust_crudini',
            appnode['ssh_user'],
            os_controller_host,
            run_as_root = True
    )
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception("Please check the mutual trust between vsm controller node "
                        "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    """validate openstack access info"""
    try:
        token_url_id = _get_token(
            appnode['os_tenant_name'],
            appnode['os_username'],
            appnode['os_password'],
            appnode['os_auth_url'],
            appnode['os_region_name']
        )
        if token_url_id != None:
            appnode['ssh_status'] = "reachable"
        else:
            appnode['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode['ssh_status'] = "unreachable"

    try:
        return db.appnodes_update(contxt, id, appnode)
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on updating Appnodes %s" % e))
        raise exception.AppNodeFailure()
Пример #17
0
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    os_controller_host = auth_openstack['os_auth_url'].split(":")[1][2:]
    result, err = utils.execute('check_xtrust_crudini',
                                auth_openstack['ssh_user'],
                                os_controller_host,
                                run_as_root=True)
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception(
            "Please check the mutual trust between vsm controller node "
            "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    ref = []
    """validate openstack access info"""
    try:
        token_url_id = _get_token(auth_openstack['os_tenant_name'],
                                  auth_openstack['os_username'],
                                  auth_openstack['os_password'],
                                  auth_openstack['os_auth_url'],
                                  auth_openstack['os_region_name'])
        if token_url_id != None:
            auth_openstack['ssh_status'] = "reachable"
        else:
            auth_openstack['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack['ssh_status'] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
def get_ceph_version():
    """

    Get the ceph version from ceph cluster.
    Run command "ceph --version" to get it.

    :return: string: version
    """

    args = ["ceph",
            "--version"]
    try:
        out, err = utils.execute(*args, run_as_root=True)
        version = out.split(" ")[2]
    except:
        version = ""
    return version
Пример #19
0
def update(contxt, appnode_id, appnode):
    """update app node ssh status, log info or deleted"""
    if contxt is None:
        contxt = context.get_admin_context()

    id = utils.int_from_str(appnode_id)
    LOG.debug('app node id: %s ' % id)

    os_controller_host = appnode['os_auth_url'].split(":")[1][2:]
    result, err = utils.execute('check_xtrust_crudini',
                                appnode['ssh_user'],
                                os_controller_host,
                                run_as_root=True)
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception(
            "Please check the mutual trust between vsm controller node "
            "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")
    """validate openstack access info"""
    try:
        token_url_id = _get_token(appnode['os_tenant_name'],
                                  appnode['os_username'],
                                  appnode['os_password'],
                                  appnode['os_auth_url'],
                                  appnode['os_region_name'])
        if token_url_id != None:
            appnode['ssh_status'] = "reachable"
        else:
            appnode['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode['ssh_status'] = "unreachable"

    try:
        return db.appnodes_update(contxt, id, appnode)
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on updating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    def create(self, req, body):
        LOG.debug(_('Creating new pool usages %s'), body)
        LOG.info(' Creating new pool usages')

        context = req.environ['vsm.context']
        pools = body['poolusages']

        appnode_id = pools[0]['appnode_id']
        appnode = db.appnodes_get_by_id(context, appnode_id)
        xtrust_user = appnode['xtrust_user']

        cinder_volume_host_list = [pool['cinder_volume_host'] for pool in pools]
        # id_list = [pool['id'] for pool in pools]

        # check openstack access
        host_list = []
        count_crudini = 0
        count_ssh = 0
        for host in cinder_volume_host_list:
            result, err = utils.execute(
                'check_xtrust_crudini',
                xtrust_user,
                host,
                run_as_root = True
            )
            LOG.info("========" + result)
            LOG.info("========" + err)
            if "command not found" in err:
                count_crudini = count_crudini + 1
                host_list.append(host)
            if "Permission denied" in err:
                count_ssh = count_ssh + 1
                host_list.append(host)
        if count_crudini != 0:
            return {'status': 'bad', 'host': list(set(host_list))}
        elif count_ssh != 0:
            return {'status': 'unreachable', 'host': list(set(host_list))}
        else:
            info = storagepoolusage.create(context, pools)
            LOG.info(' pools_info = %s' % info)
            self.scheduler_api.present_storage_pools(context, info)
            return {'status': 'ok', 'host': host_list}
Пример #21
0
    def create(self, req, body):
        LOG.debug(_('Creating new pool usages %s'), body)
        LOG.info(' Creating new pool usages')

        context = req.environ['vsm.context']
        pools = body['poolusages']

        host_list = []
        count_crudini = 0
        count_ssh = 0
        host = []
        for pool in pools:
            appnode_id = pool['appnode_id']
            appnode = db.appnodes_get_by_id(context, appnode_id)
            auth_url = appnode['os_auth_url']
            os_controller_host = auth_url.split(":")[1][2:]
            ssh_user = appnode['ssh_user']
            if os_controller_host not in host:
                host.append(os_controller_host)
                result, err = utils.execute('check_xtrust_crudini',
                                            ssh_user,
                                            os_controller_host,
                                            run_as_root=True)
                LOG.info("==============result: %s" % result)
                LOG.info("==============err: %s" % err)
                if "command not found" in err:
                    count_crudini = count_crudini + 1
                    host_list.append(host)
                if "Permission denied" in err or "No passwd entry" in err:
                    count_ssh = count_ssh + 1
                    host_list.append(host)

        if count_crudini != 0:
            return {'status': 'bad', 'host': list(set(host_list))}
        elif count_ssh != 0:
            return {'status': 'unreachable', 'host': list(set(host_list))}
        else:
            info = storagepoolusage.create(context, pools)
            LOG.info(' pools_info = %s' % info)
            self.scheduler_api.present_storage_pools(context, info)
            return {'status': 'ok', 'host': host_list}
Пример #22
0
    def create(self, req, body):
        LOG.debug(_('Creating new pool usages %s'), body)
        LOG.info(' Creating new pool usages')

        context = req.environ['vsm.context']
        pools = body['poolusages']

        host_list = []
        count_crudini = 0
        count_ssh = 0
        host = []
        for pool in pools:
            appnode_id = pool['appnode_id']
            appnode = db.appnodes_get_by_id(context, appnode_id)
            auth_url = appnode['os_auth_url']
            os_controller_host = auth_url.split(":")[1][2:]
            ssh_user = appnode['ssh_user']
            if os_controller_host not in host:
                host.append(os_controller_host)
                result, err = utils.execute('check_xtrust_crudini',
                                            ssh_user, os_controller_host,
                                            run_as_root = True)
                LOG.info("==============result: %s" % result)
                LOG.info("==============err: %s" % err)
                if "command not found" in err:
                    count_crudini = count_crudini + 1
                    host_list.append(host)
                if "Permission denied" in err or "No passwd entry" in err:
                    count_ssh = count_ssh + 1
                    host_list.append(host)

        if count_crudini != 0:
            return {'status': 'bad', 'host': list(set(host_list))}
        elif count_ssh != 0:
            return {'status': 'unreachable', 'host': list(set(host_list))}
        else:
            info = storagepoolusage.create(context, pools)
            LOG.info(' pools_info = %s' % info)
            self.scheduler_api.present_storage_pools(context, info)
            return {'status': 'ok', 'host': host_list}
def setup(app):
    print "**Autodocumenting from %s" % os.path.abspath(os.curdir)
    rv = utils.execute('./doc/generate_autodoc_index.sh')
    print rv[0]
Пример #24
0
def update(contxt, appnode_id, appnode):
    """update app node ssh status, log info or deleted"""
    if contxt is None:
        contxt = context.get_admin_context()

    auth_url = appnode['os_auth_url'].strip("/")
    ssh_user = appnode['ssh_user']
    tenant_name = appnode['os_tenant_name']
    username = appnode['os_username']
    password = appnode['os_password']
    region_name = appnode['os_region_name']

    id = utils.int_from_str(appnode_id)
    LOG.debug('app node id: %s ' % id)

    os_controller_host = auth_url.split(":")[1][2:]
    result, err = utils.execute(
            'check_xtrust_crudini',
            ssh_user,
            os_controller_host,
            run_as_root = True
    )
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception("Please check the mutual trust between vsm controller node "
                        "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    # support keystone v3 ad v2.0
    keystone_version = auth_url.split("/")[-1]
    try:
        if keystone_version == "v3":
            result = _check_v3(tenant_name,
                               username,
                               password,
                               auth_url,
                               region_name)
        elif keystone_version == "v2.0":
            result = _check_v2(tenant_name,
                               username,
                               password,
                               auth_url,
                               region_name)
        else:
            raise Exception("Only support keystone v3 and v2.0 now.")
        if result:
            appnode['ssh_status'] = "reachable"
        else:
            appnode['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode['ssh_status'] = "unreachable"

    try:
        return db.appnodes_update(contxt, id, appnode)
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on updating Appnodes %s" % e))
        raise exception.AppNodeFailure()
Пример #25
0
def get_rsa_key():
    """Return public key of this server."""
    #TODO change the style to get rsa key.
    key, err = utils.execute("cat", FLAGS.id_rsa_pub, run_as_root=True)
    return key
Пример #26
0
def setup(app):
    print "**Autodocumenting from %s" % os.path.abspath(os.curdir)
    rv = utils.execute('./doc/generate_autodoc_index.sh')
    print rv[0]
Пример #27
0
def get_rsa_key():
    """Return public key of this server."""
    #TODO change the style to get rsa key.
    key, err = utils.execute("cat", FLAGS.id_rsa_pub, run_as_root=True)
    return key
Пример #28
0
 def get_ips(self):
     (out, err) = utils.execute('hostname', '-I')
     return out.split()
Пример #29
0
 def get_ips(self):
     (out, err) = utils.execute('hostname', '-I')
     return out.split()
Пример #30
0
    def create(self, req, body):
        """
        Create a rgw.
        :param req:
        :param body:
        {
            "rgw": {
                "rgw_info": {
                    "server_name": "rgw-node1",
                    "rgw_instance_name": "radosgw.gateway",
                    "is_ssl": False
                },
                "user_info": {
                    "uid": "johndoe",
                    "display_name": "John Doe",
                    "email": "[email protected]@example.com",
                    "sub_user": "******",
                    "access": "full",
                    "key_type": "swift"
                }
            }
        }
        :return:
        """
        context = req.environ["vsm.context"]

        # check if the server has been installed radosgw

        def _get_os():
            (distro, release, codename) = platform.dist()
            return distro

        distro = _get_os()
        if distro.lower() == "centos":
            try:
                utils.execute("ls", "/usr/bin/radosgw", run_as_root=True)
            except:
                LOG.error("Not installed ceph-radosgw")
                raise exception.VsmException()
        elif distro.lower() == "ubuntu":
            try:
                utils.execute("ls", "/usr/bin/radosgw", run_as_root=True)
            except:
                LOG.error("Not installed radosgw")
                raise exception.VsmException()

        rgw = body["rgw"]
        rgw_info = rgw["rgw_info"]
        user_info = rgw["user_info"]
        server_name = rgw_info.get("server_name", "")
        if not server_name:
            LOG.error("No server to create rgw.")
            raise exception.VsmException()
        rgw_instance_name = rgw_info.get("rgw_instance_name", "")
        if not rgw_instance_name:
            rgw_instance_name = "gateway"
            LOG.warn("rgw instance name uses default name 'rgw'")
        is_ssl = rgw_info.get("is_ssl", "")
        if is_ssl == "":
            is_ssl = False
            LOG.warn("do not use ssl")
        uid = user_info.get("uid") if user_info.get("uid", "") else "johndoe"
        display_name = user_info.get("display_name") if user_info.get("display_name", "") else "John Doe"
        email = user_info.get("email") if user_info.get("email", "") else "[email protected]@example.com"
        sub_user = user_info.get("sub_user") if user_info.get("sub_user", "") else "johndoe:swift"
        access = user_info.get("access") if user_info.get("access", "") else "full"
        key_type = user_info.get("key_type") if user_info.get("key_type", "") else "swift"

        self.scheduler_api.rgw_create(
            context, server_name, rgw_instance_name, is_ssl, uid, display_name, email, sub_user, access, key_type
        )
Пример #31
0
def convert_image(source, dest, out_format):
    """Convert image to other format"""
    cmd = ('qemu-img', 'convert', '-O', out_format, source, dest)
    utils.execute(*cmd, run_as_root=True)
Пример #32
0
def qemu_img_info(path):
    """Return a object containing the parsed output from qemu-img info."""
    out, err = utils.execute('env', 'LC_ALL=C', 'LANG=C',
                             'qemu-img', 'info', path,
                             run_as_root=True)
    return QemuImgInfo(out)
Пример #33
0
    def create(self, req, body):
        """
        Create a rgw.
        :param req:
        :param body:
        {
            "rgw": {
                "rgw_info": {
                    "server_name": "rgw-node1",
                    "rgw_instance_name": "radosgw.gateway",
                    "is_ssl": False
                },
                "user_info": {
                    "uid": "johndoe",
                    "display_name": "John Doe",
                    "email": "[email protected]@example.com",
                    "sub_user": "******",
                    "access": "full",
                    "key_type": "swift"
                }
            }
        }
        :return:
        """
        context = req.environ['vsm.context']

        # check if the server has been installed radosgw

        def _get_os():
            (distro, release, codename) = platform.dist()
            return distro

        distro = _get_os()
        if distro.lower() == "centos":
            try:
                utils.execute("ls", "/usr/bin/radosgw", run_as_root=True)
            except:
                LOG.error("Not installed ceph-radosgw")
                raise exception.VsmException()
        elif distro.lower() == "ubuntu":
            try:
                utils.execute("ls", "/usr/bin/radosgw", run_as_root=True)
            except:
                LOG.error("Not installed radosgw")
                raise exception.VsmException()

        rgw = body['rgw']
        rgw_info = rgw['rgw_info']
        user_info = rgw['user_info']
        server_name = rgw_info.get('server_name', '')
        if not server_name:
            LOG.error("No server to create rgw.")
            raise exception.VsmException()
        rgw_instance_name = rgw_info.get('rgw_instance_name', '')
        if not rgw_instance_name:
            rgw_instance_name = "gateway"
            LOG.warn("rgw instance name uses default name 'rgw'")
        is_ssl = rgw_info.get('is_ssl', '')
        if is_ssl == '':
            is_ssl = False
            LOG.warn("do not use ssl")
        uid = user_info.get('uid') if user_info.get('uid', '') else "johndoe"
        display_name = user_info.get('display_name') if user_info.get(
            'display_name', '') else "John Doe"
        email = user_info.get('email') if user_info.get(
            'email', '') else "[email protected]@example.com"
        sub_user = user_info.get('sub_user') if user_info.get(
            'sub_user', '') else "johndoe:swift"
        access = user_info.get('access') if user_info.get('access',
                                                          '') else "full"
        key_type = user_info.get('key_type') if user_info.get('key_type',
                                                              '') else "swift"

        self.scheduler_api.rgw_create(context, server_name, rgw_instance_name,
                                      is_ssl, uid, display_name, email,
                                      sub_user, access, key_type)
Пример #34
0
def convert_image(source, dest, out_format):
    """Convert image to other format"""
    cmd = ('qemu-img', 'convert', '-O', out_format, source, dest)
    utils.execute(*cmd, run_as_root=True)
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    novaclient = nc.Client(
        auth_openstack["os_username"],
        auth_openstack["os_password"],
        auth_openstack["os_tenant_name"],
        auth_openstack["os_auth_url"],
        region_name=auth_openstack["os_region_name"],
    )
    nova_services = novaclient.services.list()
    nova_compute_hosts = []
    for nova_service in nova_services:
        if nova_service.binary == "nova-compute":
            nova_compute_hosts.append(nova_service.host)

    cinderclient = cc.Client(
        auth_openstack["os_username"],
        auth_openstack["os_password"],
        auth_openstack["os_tenant_name"],
        auth_openstack["os_auth_url"],
        region_name=auth_openstack["os_region_name"],
    )
    cinder_services = cinderclient.services.list()
    cinder_volume_hosts = []
    for cinder_service in cinder_services:
        if cinder_service.binary == "cinder-volume":
            cinder_volume_hosts.append(cinder_service.host)

    hosts = list(set(nova_compute_hosts + cinder_volume_hosts))
    print hosts

    for host in hosts:
        result, err = utils.execute("check_xtrust_crudini", auth_openstack["xtrust_user"], host, run_as_root=True)
        LOG.info("==============result: %s" % result)
        LOG.info("==============result: %s" % err)
        if "command not found" in err:
            raise Exception("Command not found on %s" % host)
        if "Permission denied" in err:
            raise Exception("Please check the mutual trust between vsm nodes and openstack nodes")

    ref = []

    """validate openstack access info"""
    try:
        token_url_id = _get_token(
            auth_openstack["os_tenant_name"],
            auth_openstack["os_username"],
            auth_openstack["os_password"],
            auth_openstack["os_auth_url"],
            auth_openstack["os_region_name"],
        )
        if token_url_id != None:
            auth_openstack["ssh_status"] = "reachable"
        else:
            auth_openstack["ssh_status"] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack["ssh_status"] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref