Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def handle(self, request, data):
        # TODO deliver a cluster id in data
        data['cluster_id'] = 1
        try:
            LOG.error("CEPH_LOG in ADD ip, %s" % str(data))
            appnodes = vsm_api.appnode_list(request)
            for appnode in appnodes:
                if data['ip'] == appnode.ip:
                    messages.error(request, "duplicate ip address")
                    return False
            body = {
                    'appnodes': [data['ip'],]
            }
            ips = [data['ip'],]
            LOG.error("CEPH_LOG in handle body %s" % str(body))
            ret = vsm_api.add_appnodes(request, ips)

            messages.success(request,
                     _('Successfully add ip: %s')
                     % data['ip'])
            return ret
        except:
            redirect = reverse("horizon:vsm:zonemgmt:index")
            exceptions.handle(request,
                              _('Unable to create zone.'),
                              redirect=redirect)
Ejemplo n.º 3
0
def get_select_data(request):
    print "===================================="
    data = json.loads(request.body)
    print data
    appnode_id  = data["appnode_id"]
    print appnode_id

    service_list = []
    data = {}
    if appnode_id:
        appnodes = vsmapi.appnode_list(request)
        print appnodes
        for appnode in appnodes:
            print appnode.id
            if int(appnode.id) == int(appnode_id):
                print "====================here=============="
                tenant_name = appnode.os_tenant_name
                username = appnode.os_username
                password = appnode.os_password
                auth_url = appnode.os_auth_url
                region_name = appnode.os_region_name
                auth_host = auth_url.split(":")[1][2:]
                try:
                    genauthtoken = GenAuthToken(tenant_name, username, password, auth_host, region_name)
                    token, tenant_id, cinder_api_host = genauthtoken.get_token()
                    cinder_service_list = list_cinder_service(cinder_api_host, token, tenant_id)

                    cinder_volume_down_list = []
                    for cinder in cinder_service_list:
                        if cinder["state"] == "down":
                            cinder_volume_down_list.append(cinder)

                    if len(cinder_volume_down_list) == 0:
                        for cinder in cinder_service_list:
                            if cinder["binary"] == "cinder-volume":
                                service_list.append(cinder["host"])
                    else:
                        for cinder in cinder_service_list:
                            if cinder["binary"] == "cinder-volume" and \
                                            "@" in cinder["host"]:
                                host = cinder["host"].split("@")[0]
                                if host not in [x["host"] for x in cinder_service_list]:
                                    service_list.append(cinder["host"])
                            elif cinder["binary"] == "cinder-volume" and \
                                            "@" not in cinder["host"]:
                                service_list.append(cinder["host"])
                    print service_list
                except:
                    service_list = []

        data = {"host": service_list}
        print data
    return HttpResponse(json.dumps(data))
Ejemplo n.º 4
0
    def get_object(self):
        LOG.info("CEPH_LOG UPDATE VIEW:%s"%self.kwargs)
        if not hasattr(self, "_object"):
            try:
                appnodes = vsmapi.appnode_list(self.request)
                for appnode in appnodes:
                    if str(appnode.id) == self.kwargs['appnode_id']:
                        self._object = appnode

            except:
                redirect = reverse("horizon:vsm:openstackconnect:index")
                exceptions.handle(self.request,
                                  _('Unable to Edit OpenStack Access.'),
                                  redirect=redirect)
        return self._object
Ejemplo n.º 5
0
def get_openstack_region_select_data(request):
    appnodes = vsmapi.appnode_list(request)
    print "================appnodes get_openstack_region_select_data=========="
    print appnodes
    appnode_list = []
    for appnode in appnodes:
        appnode_dict = {}
        auth_host = appnode.os_auth_url.split(":")[1][2:]
        appnode_dict.update({"display": auth_host + "/" + appnode.os_region_name,
                             "id": appnode.id
                             })
        appnode_list.append(appnode_dict)

    print appnode_list
    data = tuple(appnode_list)
    return HttpResponse(json.dumps(data))
Ejemplo n.º 6
0
    def get_data(self):
        _appnode_list = []
        try:
            _appnode_list = vsmapi.appnode_list(self.request)
        except:
            exceptions.handle(self.request,
                   _('Unable to retrieve openstack ip list. '))

        appnode_list = []
        for _appnode in _appnode_list:
            appnode = {"id": str(_appnode.id),
                    "ip": _appnode.ip,
                    "ssh_status": _appnode.ssh_status,
                    "log_info": _appnode.log_info}
            appnode_list.append(appnode)

        return appnode_list
Ejemplo n.º 7
0
def get_select_data(request):
    appnode = vsmapi.appnode_list(request)[0]
    tenant_name = appnode.os_tenant_name
    username = appnode.os_username
    password = appnode.os_password
    auth_url = appnode.os_auth_url
    region_name = appnode.os_region_name
    auth_host = auth_url.split(":")[1][2:]
    cinder_service = []
    try:
        genauthtoken = GenAuthToken(tenant_name, username, password, auth_host, region_name)
        token, tenant_id = genauthtoken.get_token()
        cinder_service_list = list_cinder_service(auth_host, token, tenant_id)

        cinder_volume_down_list = []
        for cinder in cinder_service_list:
            if cinder["state"] == "down":
                cinder_volume_down_list.append(cinder)

        value = 0
        if len(cinder_volume_down_list) == 0:
            for cinder in cinder_service_list:
                if cinder["binary"] == "cinder-volume":
                    cinder.update({"value": value})
                    value = value + 1
                    cinder_service.append(cinder)
        else:
            for cinder in cinder_service_list:
                if cinder["binary"] == "cinder-volume" and \
                                "@" in cinder["host"]:
                    host = cinder["host"].split("@")[0]
                    if host not in [x["host"] for x in cinder_service_list]:
                        cinder.update({"value": value})
                        value = value + 1
                        cinder_service.append(cinder)
                elif cinder["binary"] == "cinder-volume" and \
                                "@" not in cinder["host"]:
                    cinder.update({"value": value})
                    value = value + 1
                    cinder_service.append(cinder)
    except:
        cinder_service = []

    data = tuple(cinder_service)
    return HttpResponse(json.dumps(data))
Ejemplo n.º 8
0
    def get_data(self):
        _appnode_list = []
        try:
            _appnode_list = vsmapi.appnode_list(self.request)
        except:
            exceptions.handle(self.request,
                   _('Unable to retrieve openstack ip list. '))

        appnode_list = []
        for _appnode in _appnode_list:
            appnode = {
                "id": str(_appnode.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,
                "ssh_status": _appnode.ssh_status,
                "log_info": _appnode.log_info
            }
            appnode_list.append(appnode)

        return appnode_list
Ejemplo n.º 9
0
def get_select_data(request):
    print "===================================="
    data = json.loads(request.body)
    print data
    appnode_id  = data["appnode_id"]
    print appnode_id

    service_list = []
    data = {}
    if appnode_id:
        appnodes = vsmapi.appnode_list(request)
        print appnodes
        for appnode in appnodes:
            print appnode.id
            if int(appnode.id) == int(appnode_id):
                print "====================here=============="
                tenant_name = appnode.os_tenant_name
                username = appnode.os_username
                password = appnode.os_password
                auth_url = appnode.os_auth_url
                region_name = appnode.os_region_name
                try:
                    keystone_version = auth_url.strip("/").split("/")[-1]
                    if keystone_version == "v3":
                        tenant_id = tenant_name
                        token, cinder_api_host = from_keystone_v3(tenant_name,
                                                                  username,
                                                                  password,
                                                                  auth_url,
                                                                  region_name)
                    else:
                        token, tenant_id, cinder_api_host = \
                            from_keystone_v2(tenant_name, username, password,
                                             auth_url, region_name)
                    cinder_service_list = list_cinder_service(cinder_api_host, token, tenant_id)

                    cinder_volume_down_list = []
                    for cinder in cinder_service_list:
                        if cinder["state"] == "down":
                            cinder_volume_down_list.append(cinder)

                    if len(cinder_volume_down_list) == 0:
                        for cinder in cinder_service_list:
                            if cinder["binary"] == "cinder-volume":
                                service_list.append(cinder["host"])
                    else:
                        for cinder in cinder_service_list:
                            if cinder["binary"] == "cinder-volume" and \
                                            "@" in cinder["host"]:
                                host = cinder["host"].split("@")[0]
                                if host not in service_list:
                                    service_list.append(host)
                            elif cinder["binary"] == "cinder-volume" and \
                                            "@" not in cinder["host"]:
                                service_list.append(cinder["host"])
                    print service_list
                except:
                    service_list = []

        data = {"host": service_list}
        print data
    return HttpResponse(json.dumps(data))
Ejemplo n.º 10
0
 def allowed(self, request, datum):
     return not len(vsmapi.appnode_list(request))