Exemple #1
0
    def get_data(self):
        pools = []
        pool_usages = []
        # TODO pools status
        try:
            pools = vsmapi.pool_list(self.request,)
            pool_usages = vsmapi.pool_usages(self.request)
            logging.debug("resp body in view: %s" % pools)
        except:
            exceptions.handle(self.request,
                              _('Unable to retrieve storage pool list. '))
        pool_usage_dict = {}
        for usage in pool_usages:
            pool_usage_dict.setdefault(str(usage.pool_id), usage)

        for pool in pools:
            pool['id'] = str(pool['id'])
            if pool['id'] in pool_usage_dict:
                pool['attach_status'] = pool_usage_dict[pool['id']].attach_status
            else:
                pool['attach_status'] = "no"

        pools = [x for x in pools if x['tag'] != "SYSTEM"]
        pools = [x for x in pools if x['attach_status'] == "no"]
        pools = [x for x in pools if x['tag'] != "SYSTEM" and not x['erasure_code_status']
             and not str(x['cache_tier_status']).startswith("Cache pool for")]
        return pools
    def allowed(self, request, datum):
        #LOG.error("CEPH_LOG PRESENTPOOL: ALLOW <")
        LOG.info("CEPH_LOG PRESENTPOOL: datum %s" % datum)
        if datum:
            for data in self.table.data:
                if not (data['status'] in ("running", "whatever")):
                    raise ValueError("Some Pools' status is not correct!")

            appnodes = vsmapi.appnode_list(request)
            if len(appnodes) < 1:
                raise ValueError("No Openstack Node!!")

            for appnode in appnodes:
                if appnode.ssh_status != "reachable":
                    messages.error(request, "Can't SSH to AppNode %s" % appnode.ip)
                    raise Exception("abc")

            if datum['status'] not in ("running", "whatever"):
                raise ValueError("Pool %s status is not correct!" % datum['name'])

            pool_usages = vsmapi.pool_usages(request)
            if datum['id'] in [str(p.pool_id) for p in pool_usages]:
                raise ValueError("Pool %s already Connected to Openstack" % datum['name'])

        #LOG.error("CEPH_LOG PRESENTPOOL: ALLOW >")
        return True
    def allowed(self, request, datum):
        #LOG.error("CEPH_LOG PRESENTPOOL: ALLOW <")
        LOG.info("CEPH_LOG PRESENTPOOL: datum %s" % datum)
        if datum:
            for data in self.table.data:
                if not (data['status'] in ("running", "whatever")):
                    raise ValueError("Some Pools' status is not correct!")

            appnodes = vsmapi.appnode_list(request)
            if len(appnodes) < 1:
                raise ValueError("No Openstack Node!!")

            for appnode in appnodes:
                if appnode.ssh_status != "reachable":
                    messages.error(request,
                                   "Can't SSH to AppNode %s" % appnode.ip)
                    raise Exception("abc")

            if datum['status'] not in ("running", "whatever"):
                raise ValueError("Pool %s status is not correct!" %
                                 datum['name'])

            pool_usages = vsmapi.pool_usages(request)
            if datum['id'] in [str(p.pool_id) for p in pool_usages]:
                raise ValueError("Pool %s already Connected to Openstack" %
                                 datum['name'])

        #LOG.error("CEPH_LOG PRESENTPOOL: ALLOW >")
        return True
def ceph_upgrade(request):
    data = json.loads(request.body)
    code,msg = vsmapi.ceph_upgrade(request, data[0])
    status = "info"
    msg = msg.get('message')

    poolusages = vsmapi.pool_usages(request)
    host_list = []
    if poolusages:
        for pool_usage in poolusages:
            volume_host = pool_usage.get("cinder_volume_host")
            if volume_host not in host_list:
                host_list.append(volume_host)
        hosts = ", ".join(host_list)
        msg = msg + "\nPlease upgrade ceph on volume hosts: %s" % hosts

    resp = dict(message=msg, status=status, data="")
    resp = json.dumps(resp)
    return HttpResponse(resp)
Exemple #5
0
def ceph_upgrade(request):
    data = json.loads(request.body)
    code, msg = vsmapi.ceph_upgrade(request, data[0])
    status = "info"
    msg = msg.get('message')

    poolusages = vsmapi.pool_usages(request)
    host_list = []
    if poolusages:
        for pool_usage in poolusages:
            volume_host = pool_usage.get("cinder_volume_host")
            if volume_host not in host_list:
                host_list.append(volume_host)
        hosts = ", ".join(host_list)
        msg = msg + "\nPlease upgrade ceph on volume hosts: %s" % hosts

    resp = dict(message=msg, status=status, data="")
    resp = json.dumps(resp)
    return HttpResponse(resp)
 def allowed(self, request, datum):
     return len([x for x in vsmapi.pool_usages(request) if x.attach_status=="success"]) == 0
 def allowed(self, request, datum):
     return len([x for x in vsmapi.pool_usages(request) if x.attach_status=="success"]) == 0
Exemple #8
0
def PoolsAction(request, action):
    data = json.loads(request.body)
    msg = ""
    status = ""
    # glance only need to present one pool
    as_glance_store_pool_num = 0
    for info in data:
        if info["as_glance_store_pool"] == True:
            as_glance_store_pool_num += 1
    if as_glance_store_pool_num > 1:
        msg = "more than one pool as glance backend"
        status = "error"
        resp = dict(message=msg, status=status, data="")
        resp = json.dumps(resp)
        return HttpResponse(resp)

    if as_glance_store_pool_num:
        pool_usages = vsmapi.pool_usages(request)
        for pool_usage in pool_usages:
            print pool_usage.as_glance_store_pool
            if pool_usage.as_glance_store_pool:
                msg = "there is one pool as glance backend now"
                status = "error"
                resp = dict(message=msg, status=status, data="")
                resp = json.dumps(resp)
                return HttpResponse(resp)

    if not len(data):
        status = "error"
        msg = "No pool selected"
    else:
        # TODO add cluster_id in data

        if action == "present":
            print data
            pools = []
            for x in data:
                cinder_volume_host = x['cinder_volume_host']
                if (cinder_volume_host == "" or cinder_volume_host == None) and \
                        (x['as_glance_store_pool'] == "" or x['as_glance_store_pool'] == None):
                    status = "error"
                    msg = "The Cinder Volume Host and As Glance Store Pool are all null"
                pools.append({'pool_id': x['id'],
                              'cinder_volume_host': cinder_volume_host,
                              'appnode_id': x['appnode_id'],
                              'as_glance_store_pool': x['as_glance_store_pool']})
            if msg == "" and status == "":
                print "========Start Present Pools==========="
                result = vsmapi.present_pool(request, pools)
                print result
                host_list = ""
                for host in result['host']:
                    host_list = host + "," + host_list
                if result['status'] == "bad":
                    status = "warning"
                    msg = "Not found crudini commmand in host: %s" % host_list
                elif result['status'] == "unreachable":
                    status = "warning"
                    msg = "Please check ssh with no password between vsm controller and host: %s" % host_list
                else:
                    status = "info"
                    msg = "Begin to Present Pools!"
                print "========End Present Pools==========="

    resp = dict(message=msg, status=status, data="")
    resp = json.dumps(resp)
    return HttpResponse(resp)