Ejemplo n.º 1
0
def manage_cluster_setting():
    if request.method == 'GET':
        result = ""
        if list_err in session:
            result = session[list_err]
            session.pop(list_err)
            return render_template('admin/configuration/cluster_settings.html', err=result, form=request.form)
        elif list_warning in session:
            result = session[list_warning]
            session.pop(list_warning)
            return render_template('admin/configuration/cluster_settings.html', warning=result, form=request.form)
        elif list_success in session:
            result = session[list_success]
            session.pop(list_success)
            cluster_config_model = ClusterConfigForm()
            manage_configuration = ManageConfig()
            new_cephAPI = CephAPI()
            # replica_no = new_cephAPI.get_replicas()
            # cluster_config_model.replica_no = replica_no
            # compression_algorithm = manage_configuration.get_compression_algorithm()
            # cluster_config_model.compression_algorithm = compression_algorithm
            # compression_mode = manage_configuration.get_compression_mode()
            # cluster_config_model.compression_mode = compression_mode
            internet_time_server = manage_configuration.get_ntp_server()
            app_config = ManageConfig().get_app_config()
            if app_config.email_notify_smtp_server != "":
                cluster_config_model.smtp_server = app_config.email_notify_smtp_server
                cluster_config_model.smtp_port = app_config.email_notify_smtp_port
                cluster_config_model.smtp_email = app_config.email_notify_smtp_email
                cluster_config_model.smtp_passwod = app_config.email_notify_smtp_password
                cluster_config_model.authentication_value = app_config.email_notify_smtp_security
            if internet_time_server == None:
                cluster_config_model.internet_time_server = ""
            else:
                cluster_config_model.internet_time_server = internet_time_server
            return render_template('admin/configuration/cluster_settings.html', success=result,
                                   form=cluster_config_model)
        else:
            cluster_config_model = ClusterConfigForm
            manage_configuration = ManageConfig()
            new_cephAPI = CephAPI()
            # replica_no = new_cephAPI.get_replicas()
            # cluster_config_model.replica_no = replica_no
            # compression_algorithm = manage_configuration.get_compression_algorithm()
            # cluster_config_model.compression_algorithm = compression_algorithm
            # compression_mode = manage_configuration.get_compression_mode()
            # cluster_config_model.compression_mode = compression_mode
            internet_time_server = manage_configuration.get_ntp_server()
            app_config = ManageConfig().get_app_config()
            if app_config.email_notify_smtp_server != "":
                cluster_config_model.smtp_server = app_config.email_notify_smtp_server
                cluster_config_model.smtp_port = app_config.email_notify_smtp_port
                cluster_config_model.smtp_email = app_config.email_notify_smtp_email
                cluster_config_model.smtp_passwod = app_config.email_notify_smtp_password
                cluster_config_model.authentication_value = app_config.email_notify_smtp_security
            if internet_time_server == None:
                cluster_config_model.internet_time_server = ""
            else:
                cluster_config_model.internet_time_server = internet_time_server
            return render_template('/admin/configuration/cluster_settings.html', form=cluster_config_model)
Ejemplo n.º 2
0
def save_network():
    if request.method == 'GET' or request.method == 'POST':
        try:

            iqn_val = request.form['Iqn']
            manage_configuration = ManageConfig()
            manage_configuration.set_iqn_base(iqn_val)
            subnet1 = request.form['Subnet1']
            subnet1_ip_from = request.form['Subnet1_Ip_From']
            subnet1_ip_to = request.form['Subnet1_Ip_To']
            subnet1_vlan_id = request.form['Subnet1_Vlan_Id']
            subnet2 = request.form['Subnet2']
            subnet2_ip_from = request.form['Subnet2_Ip_From']
            subnet2_ip_to = request.form['Subnet2_Ip_To']
            subnet2_vlan_id = request.form['Subnet2_Vlan_Id']

            form1 = manage_network_form()
            form1.Subnet1_Vlan_Id = subnet1_vlan_id
            form1.Subnet1_Vlan_Id = subnet2_vlan_id
            subnet1_info = ISCSISubnet()
            subnet1_info.subnet_mask = subnet1
            subnet1_info.auto_ip_from = subnet1_ip_from
            subnet1_info.auto_ip_to = subnet1_ip_to
            subnet1_info.vlan_id = subnet1_vlan_id

            subnet2_info = ISCSISubnet()
            subnet2_info.subnet_mask = subnet2
            subnet2_info.auto_ip_from = subnet2_ip_from
            subnet2_info.auto_ip_to = subnet2_ip_to
            subnet2_info.vlan_id = subnet2_vlan_id

            manage_configuration = ManageConfig()
            manage_configuration.set_iscsi1_subnet(subnet1_info)
            manage_configuration.set_iscsi2_subnet(subnet2_info)

            session['success'] = "ui_admin_network_suc"

            return redirect(url_for('configuration_controller.manage_network'), 307)

        except Exception as e:
            session['err'] = "ui_admin_network_err_exception"
            logger.error(e)
            return redirect(url_for('configuration_controller.manage_network'), 307)



        except Exception as e:
            session['err'] = " Error in Saving."
            logger.error(e)
            return redirect(url_for('configuration_controller.manage_disk'), 307)
Ejemplo n.º 3
0
def save_cluster_setting():
    if request.method == 'POST':
        try:
            internet_time_server_val = request.form['internet_time_server']
            manage_configuration = ManageConfig()
            res = manage_configuration.save_ntp_server(internet_time_server_val)
            if res == False or res == None:
                manage_configuration.save_ntp_server("")
                logger.info("No NTP server Set")
        except Exception as e:
            session['err'] = "ui_admin_exep_err_save_NTP"
            logger.error(" error saving ntp server")
            return redirect(url_for('configuration_controller.manage_cluster_setting'), 307)
        # try:
        #     compression_mode = request.form['compression']
        #     compression_mode = int(compression_mode)
        #     if compression_mode == 2:
        #         algorithm = request.form['compression_algorithm_value']
        #         manage_configuration.set_compression_mode(compression_mode)
        #         manage_configuration.set_compression_algorithm(int(algorithm))
        #     else:
        #         manage_configuration.set_compression_mode(compression_mode)
        # except Exception as e:
        #     logger.error("Error Saving Compression")
        #     session['err'] = "ui_admin_error_set_data_compression"
        #     return redirect(url_for('configuration_controller.manage_cluster_setting'), 307)

        try:

            if 'smtp_server' in request.form:
                if request.form['smtp_server'] != "":
                    server = request.form['smtp_server']
                    port = int(request.form['port_no'])
                    email = str(request.form['email'])
                    passwod = request.form['userPassword']
                    authentication_value = int(request.form['authentication_value'])
                    manage_configuration.set_smtp_config(server, port, email, passwod, authentication_value)
                    session['success'] = "ui_admin_save_general_settings_success"
                    return redirect(url_for('configuration_controller.manage_cluster_setting'))
                else:
                    server = ""
                    port = ""
                    email = ""
                    passwod = ""
                    authentication_value = "1"
                    manage_configuration.set_smtp_config(server, port, email, passwod, authentication_value)
                    session['success'] = "ui_admin_save_general_settings_success"
                    return redirect(url_for('configuration_controller.manage_cluster_setting'))
        except Exception as e:
            logger.error("error set smtp settings")
            session['err'] = "ui_admin_error_set_smtp_settings"
            return redirect(url_for('configuration_controller.manage_cluster_setting'), 307)
Ejemplo n.º 4
0
def manage_network():
    if request.method == 'GET' or request.method == 'POST':
        result = ""

        if list_err in session:
            result = session[list_err]
            session.pop(list_err)
            return render_template('admin/configuration/network.html', err=result, form=request.form)
        elif list_warning in session:
            result = session[list_warning]
            session.pop(list_warning)
            return render_template('admin/configuration/network.html', warning=result, form=request.form)
        elif list_success in session:
            result = session[list_success]
            session.pop(list_success)
            return render_template('admin/configuration/network.html', success=result, form=request.form)
        else:
            result = "ui_admin_vlan_paths"
            form1 = manage_network_form()
            manage_configuration = ManageConfig()
            subnet1_Info = manage_configuration.get_iscsi1_subnet()
            subnet2_Info = manage_configuration.get_iscsi2_subnet()
            form1.Subnet1 = subnet1_Info.subnet_mask
            form1.Subnet1_Ip_From = subnet1_Info.auto_ip_from
            form1.Subnet1_Ip_To = subnet1_Info.auto_ip_to
            form1.Subnet1_Vlan_Id = subnet1_Info.vlan_id
            form1.Subnet2 = subnet2_Info.subnet_mask
            form1.Subnet2_Ip_From = subnet2_Info.auto_ip_from
            form1.Subnet2_Ip_To = subnet2_Info.auto_ip_to
            form1.Subnet2_Vlan_Id = subnet2_Info.vlan_id
            manage_configuration = ManageConfig()
            iqn = manage_configuration.get_iqn_base()
            form1.Iqn = iqn
            return render_template('admin/configuration/network.html', form=form1,info = result)
Ejemplo n.º 5
0
def add_target_without_auth_acl():
    api= LioAPI()
    disk =DiskMeta()
    disk.id="image00001"
    disk.ip="192.168.57.100"
    disk.ip2="192.168.57.102"
    disk.acl=""
    disk.iqn="image00001",ManageConfig().get_iqn_base()+":"+"image00001"
    api.add_target(disk)
Ejemplo n.º 6
0
def test_email():
    if request.method == 'POST':
        status = EmailStatus()
        try:
            email = request.form['email']
            password = request.form['password']
            server = request.form['server']
            port = request.form['port']
            security = request.form['security']
            status = ManageConfig().test_email(email, server, port, password, security, session['user'])
            status.exception = str(status.exception)
            return status.write_json()

        except Exception as e:
            logger.error(e)
            status.success = False
            status.err_msg = e.message
            return status.write_json()
    def add_disk(self, disk_meta, manual_ips, path_type, paths_count,
                 auth_auto, auto_ip, pool):
        """
        :type path_type: PathType
        :type manual_ips: [string]
        :type paths_count: int
        :type disk_meta: DiskMeta
        """
        cfg = ManageConfig()
        paths = []
        try:
            if not disk_meta.disk_name or not disk_meta.size or type(
                    disk_meta.size) != int:
                return ManageDiskStatus.data_missing
            elif not auth_auto and (not disk_meta.user
                                    or not disk_meta.password):
                return ManageDiskStatus.data_missing
            elif not auto_ip and int(paths_count) > 2:
                return ManageDiskStatus.wrong_data
            elif not auto_ip and int(paths_count) != len(manual_ips):
                return ManageDiskStatus.wrong_data
            elif not auto_ip:
                ip_status = cfg.validate_new_iscsi_ips(manual_ips, path_type)
                if ip_status == NewIPValidation.valid:
                    for ip in manual_ips:
                        paths.append(cfg.get_path(ip))
                elif ip_status == NewIPValidation.used_already:
                    return ManageDiskStatus.used_already
                elif ip_status == NewIPValidation.wrong_subnet:
                    return ManageDiskStatus.wrong_subnet
                else:
                    return ManageDiskStatus.wrong_data
            elif auto_ip:
                paths.extend(cfg.get_new_iscsi_ips(path_type, paths_count))
            if not paths or len(paths) == 0:
                return ManageDiskStatus.ip_out_of_range

            new_id = self.__get_next_disk_id()
            disk_meta.id = new_id
            disk_meta.paths = paths
            disk_meta.wwn = self.__get_wwn(new_id)

            if auth_auto:
                disk_meta.user = ""
                disk_meta.password = ""

            disk_meta.iqn = ":".join([cfg.get_iqn_base(), new_id])
            consul_api = ConsulAPI()
            disk_data = consul_api.find_disk(disk_meta.id)

            if disk_data is not None:
                return ManageDiskStatus.disk_exists

            ceph_api = CephAPI()
            status = ceph_api.add_disk(disk_meta, True, pool)
            if status == ManageDiskStatus.done:
                consul_api.add_disk_resource(disk_meta.id, "disk")
                consul_api.add_disk_pool(disk_meta.id, pool)
                i = 0
                for p in paths:
                    i += 1
                    consul_api.add_disk_resource(
                        "/".join(["", disk_meta.id, str(i)]), None)

        except DiskListException as e:
            status = ManageDiskStatus.disk_get__list_error
            logger.exception(e.message)
        except Exception as e:
            status = ManageDiskStatus.error
            logger.exception(e.message)
        return status
    def attach_disk(self, disk_meta, manual_ips, path_type, paths_count,
                    auth_auto, auto_ip, pool):
        """

        :type disk_meta: DiskMeta
        """
        mange_config = ManageConfig()
        paths_list = []
        do_rename = False
        none_petasan_image = ""
        try:
            if not disk_meta.disk_name or not disk_meta.size or type(
                    disk_meta.size) != int:
                return ManageDiskStatus.data_missing
            elif not auth_auto and (not disk_meta.user
                                    or not disk_meta.password):
                return ManageDiskStatus.data_missing
            elif not auto_ip and int(paths_count) > 2:
                return ManageDiskStatus.wrong_data
            elif not auto_ip and int(paths_count) != len(manual_ips):
                return ManageDiskStatus.wrong_data
            elif not auto_ip:
                ip_status = mange_config.validate_new_iscsi_ips(
                    manual_ips, path_type)
                if ip_status == NewIPValidation.valid:
                    for ip in manual_ips:
                        paths_list.append(mange_config.get_path(ip))
                elif ip_status == NewIPValidation.used_already:
                    return ManageDiskStatus.used_already
                elif ip_status == NewIPValidation.wrong_subnet:
                    return ManageDiskStatus.wrong_subnet
            elif auto_ip:
                paths_list.extend(
                    mange_config.get_new_iscsi_ips(path_type, paths_count))

            if not paths_list or len(paths_list) == 0:
                return ManageDiskStatus.ip_out_of_range

            ceph_api = CephAPI()
            consul_api = ConsulAPI()
            image_name_prefix = ConfigAPI().get_image_name_prefix()
            if not "".join([image_name_prefix,
                            str(disk_meta.id)
                            ]) in ceph_api.get_rbd_images(pool):
                new_id = self.__get_next_disk_id()
                if ceph_api.is_image_busy(disk_meta.id, pool):
                    return ManageDiskStatus.is_busy
                do_rename = True
                none_petasan_image = disk_meta.id
                disk_meta.id = new_id

            disk_meta.pool = pool
            disk_meta.iqn = ":".join(
                [mange_config.get_iqn_base(), disk_meta.id])
            disk_meta.paths = paths_list
            if auth_auto:
                disk_meta.user = ""
                disk_meta.password = ""
            disk_meta.wwn = self.__get_wwn(disk_meta.id)

            status = consul_api.find_disk(disk_meta.id)
            if status is not None:
                return ManageDiskStatus.disk_exists  # disk is running and attached
            else:
                if do_rename:
                    ceph_api.rename_image_to_petasan_index(
                        none_petasan_image, image_name_prefix + new_id, pool)
                status = ceph_api.add_disk(disk_meta, False, pool)
                if status == ManageDiskStatus.done:
                    consul_api.add_disk_resource(disk_meta.id, "disk")
                    i = 0
                    for p in paths_list:
                        i += 1
                        consul_api.add_disk_resource(
                            "/".join(["", disk_meta.id,
                                      str(i)]), None)
                else:
                    if do_rename:
                        ceph_api.rename_image_to_petasan_index(
                            image_name_prefix + new_id, none_petasan_image,
                            pool)

        except DiskListException as e:
            status = ManageDiskStatus.disk_get__list_error
            logger.exception(e.message)
        except Exception as e:
            status = ManageDiskStatus.error
            logger.exception(e.message)
        return status
conf1.iscsi1_subnet_mask = '255.255.255.0'
conf1.iscsi1_auto_ip_from = '192.168.57.1'
conf1.iscsi1_auto_ip_to = '192.168.57.200'
conf1.iscsi2_subnet_mask = '255.255.255.0'
conf1.iscsi2_auto_ip_from = '192.168.58.1'
conf1.iscsi2_auto_ip_to = '192.168.58.200'
api.write_app_config(conf1)

# read complete app configuration
conf2 = api.read_app_config()
print conf2.iscsi1_subnet_mask
print conf2.iscsi1_auto_ip_from
print conf2.iscsi1_auto_ip_to

#  -------- ManageConfig test --------------------
config = ManageConfig()

# read iscsi 1 subnet
subnet1 = config.get_iscsi1_subnet()
print subnet1.auto_ip_to

# write iscsi2 subnet
subnet2 = ISCSISubnet()
subnet2.subnet_mask = '255.255.255.0'
subnet2.auto_ip_from = '192.168.59.1'
subnet2.auto_ip_to = '192.168.59.200'
config.set_iscsi2_subnet(subnet2)

# valid new ips
ips = ['192.168.57.100', '192.168.57.101', '192.168.57.103']
# 1 = valid, -3 = invalid_count,  -2 = wrong subnet, -1 = used already
Ejemplo n.º 10
0
def get_ips():
    api= LioAPI()
    api.get_target_ips(":".join([ManageConfig().get_iqn_base(),"image00001"]))
Ejemplo n.º 11
0
def save_attach_disk(disk_id, pool):
    if request.method == 'POST':
        try:
            failed_pools = int(request.form['failed_pools'])
            activePaths = int(request.form['ActivePaths'])
            if activePaths >= 3:
                automatic_ip = "Yes"
            else:
                automatic_ip = request.form['orpUseFirstRange']
            if automatic_ip == "Yes" and failed_pools > 0:
                session['err'] = "ui_admin_add_disk_while_pool_inactive"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)
            disk = DiskMeta()
            disk.id = disk_id
            disk.size = int(request.form['diskSize'])
            disk.disk_name = request.form['diskName']
            if 'orpUseFirstRange' not in request.values:
                isAutomaticIp = "Yes"
            else:
                isAutomaticIp = request.form['orpUseFirstRange']

            activePathsCount = int(request.form['ActivePaths'])
            if activePathsCount >= 3:
                isAutomaticIp = "Yes"
            path_type = int(request.form['ISCSISubnet'])
            if path_type == 1:
                path_type = PathType.iscsi_subnet1
            elif path_type == 2:
                path_type = PathType.iscsi_subnet2
            elif path_type == 3:
                path_type = PathType.both
            manual_ips = []
            enable_rep = request.form['replication']
            if enable_rep == "yes":
                disk.is_replication_target = True

            if isAutomaticIp != "Yes":
                manual_ips.append(request.form['path1'])
                isAutomaticIp = False
                if activePathsCount == 2:
                    manual_ips.append(request.form['path2'])
            else:
                isAutomaticIp = True

            disk.orpUseFirstRange = isAutomaticIp
            disk.ISCSISubnet = int(request.form['ISCSISubnet'])

            usedACL = request.form['orpACL']
            if usedACL == "Iqn":
                disk.acl = request.form['IqnVal']
            else:
                disk.acl = ""

            usedAutentication = request.form['orpAuth']
            if usedAutentication == "Yes":
                auth_auto = False
                disk.user = request.form['UserName']
                disk.password = request.form['Password']
            else:
                auth_auto = True

            disk.data_pool = request.form['data_pool']

            manage_config = ManageConfig()
            subnet1_info = manage_config.get_iscsi1_subnet()
            subnet2_info = manage_config.get_iscsi2_subnet()
            disk.subnet1 = subnet1_info.subnet_mask
            # call method to save object
            manageDisk = ManageDisk()
            status = manageDisk.attach_disk(disk, manual_ips, path_type,
                                            activePathsCount, auth_auto,
                                            isAutomaticIp, pool)
            if status == ManageDiskStatus.done:
                # session['success'] = "ui_admin_attach_disk_success"
                return redirect(url_for('disk_controller.disk_list'))

            elif status == ManageDiskStatus.done_metaNo:
                session[
                    'success'] = "ui_admin_attach_disk_attached_with_no_metadata"
                return redirect(url_for('disk_controller.disk_list'))

            elif status == ManageDiskStatus.error:
                session['err'] = "ui_admin_attach_disk_error"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.disk_created_cant_start:
                session['warning'] = "ui_admin_attach_disk_attached_not_start"
                return redirect(url_for('disk_controller.disk_list'))

            elif status == ManageDiskStatus.data_missing:
                session['err'] = "ui_admin_manage_disk_data_missing"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.disk_meta_cant_read:
                session[
                    'warning'] = "ui_admin_attach_disk_error_attached_not_read_metadata"
                return redirect(url_for('disk_controller.disk_list'))

            elif status == ManageDiskStatus.disk_exists:
                session['err'] = "ui_admin_manage_disk_exist"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.disk_name_exists:
                session['err'] = "ui_admin_manage_disk_name_exist"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.ip_out_of_range:
                session['err'] = "ui_admin_manage_disk_no_auto_ip"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.wrong_subnet:
                session['err'] = "ui_admin_manage_disk_wrong_subnet"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.wrong_data:
                session['err'] = "ui_admin_manage_disk_wrong_data"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.used_already:
                session['err'] = "ui_admin_manage_disk_used_already"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.disk_get__list_error:
                session['err'] = "ui_admin_manage_disk_disk_get_list_error"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

            elif status == ManageDiskStatus.is_busy:
                session['err'] = "ui_admin_attach_disk_is_busy"
                return redirect(
                    url_for('disk_controller.attach_disk',
                            disk_id=disk_id,
                            pool=pool), 307)

        except Exception as e:
            session['err'] = "ui_admin_attach_disk_error"
            logger.error(e)
            return redirect(
                url_for('disk_controller.attach_disk',
                        disk_id=disk_id,
                        pool=pool), 307)
Ejemplo n.º 12
0
def attach_disk(disk_id, pool):
    if request.method == 'GET' or request.method == 'POST':
        failed_pools = 0
        manage_pool = ManagePools()
        active_pools = manage_pool.get_active_pools()
        all_pools = manage_pool.get_pools_info()
        if len(all_pools) > len(active_pools):
            failed_pools = len(all_pools) - len(active_pools)

        manage_config = ManageConfig()
        subnet1_info = manage_config.get_iscsi1_subnet()
        subnet2_info = manage_config.get_iscsi2_subnet()
        size_list_aval = [
            1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 150, 250,
            300, 400, 450, 500, 600, 700, 800, 900, 1024, 2048, 3072, 4096,
            5120, 10240, 20480, 30720, 51200, 102400
        ]

        result = ""
        if list_err in session:
            result = session[list_err]
            session.pop(list_err)
            manage_disk = ManageDisk()
            disk = manage_disk.get_disk(disk_id, pool)
            form1 = add_disk_form()
            form1.id = disk.id
            form1.diskSize = disk.size
            form1.pool = pool
            form1.data_pool = disk.data_pool
            form1.diskName = disk.disk_name
            form1.is_replication_target = disk.is_replication_target
            return render_template('admin/disk/attach_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   form=form1,
                                   failed_pools=failed_pools,
                                   size_list=size_list_aval,
                                   err=result)

        elif list_warning in session:
            result = session[list_warning]
            session.pop(list_warning)
            manage_disk = ManageDisk()
            disk = manage_disk.get_disk(disk_id, pool)
            form1 = add_disk_form()
            form1.id = disk.id
            form1.diskSize = disk.size
            form1.pool = pool
            form1.data_pool = disk.data_pool
            form1.diskName = disk.disk_name
            form1.is_replication_target = disk.is_replication_target
            return render_template('admin/disk/attach_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   form=form1,
                                   failed_pools=failed_pools,
                                   size_list=size_list_aval,
                                   warning=result)

        elif list_success in session:
            result = session[list_success]
            session.pop(list_success)
            manage_disk = ManageDisk()
            disk = manage_disk.get_disk(disk_id, pool)
            form1 = add_disk_form()
            form1.id = disk.id
            form1.diskSize = disk.size
            form1.pool = pool
            form1.data_pool = disk.data_pool
            form1.diskName = disk.disk_name
            form1.is_replication_target = disk.is_replication_target
            return render_template('admin/disk/attach_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   form=form1,
                                   failed_pools=failed_pools,
                                   size_list=size_list_aval,
                                   success=result)

        else:
            is_not_petasan_warning = ''
            manage_disk = ManageDisk()
            disk = manage_disk.get_disk(disk_id, pool)
            form1 = add_disk_form()
            if disk.is_petasan_image is not None and disk.is_petasan_image == False:
                form1.diskName = disk.id
                is_not_petasan_warning = "ui_admin_attach_disk_warning_disk_is_not_petasan"
            form1.id = disk.id
            form1.diskSize = disk.size
            form1.pool = pool
            form1.data_pool = disk.data_pool
            form1.diskName = disk.disk_name
            form1.is_replication_target = disk.is_replication_target
            if is_not_petasan_warning != '':
                result = is_not_petasan_warning
            return render_template('admin/disk/attach_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   form=form1,
                                   failed_pools=failed_pools,
                                   size_list=size_list_aval,
                                   warning=result)
Ejemplo n.º 13
0
def add_disk():
    if request.method == 'GET' or request.method == 'POST':
        manage_config = ManageConfig()
        subnet1_info = manage_config.get_iscsi1_subnet()
        subnet2_info = manage_config.get_iscsi2_subnet()
        size_list_aval = [
            1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 150, 250,
            300, 400, 450, 500, 600, 700, 800, 900, 1024, 2048, 3072, 4096,
            5120, 10240, 20480, 30720, 51200, 102400
        ]
        active_pools = []
        replicated_pools = []
        erasure_pools = []
        result = ""
        failed_pools = 0
        try:
            manage_pool = ManagePools()
            active_pools = manage_pool.get_active_pools()
            all_pools = manage_pool.get_pools_info()
            for pool in all_pools:
                if pool.name in active_pools and pool.type == 'replicated':
                    replicated_pools.append(pool.name)
                elif pool.name in active_pools and pool.type == 'erasure':
                    erasure_pools.append(pool.name)
            if len(all_pools) > len(active_pools):
                failed_pools = len(all_pools) - len(active_pools)
        except CephException as e:
            if e.id == CephException.CONNECTION_TIMEOUT:
                result = "Ceph connection timeout"
            elif e.id == CephException.GENERAL_EXCEPTION:
                result = "Ceph general exception"
            logger.error(e)
            form1 = add_disk_form()
            return render_template('admin/disk/add_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   size_list=size_list_aval,
                                   err=result,
                                   form=form1,
                                   failed_pools=failed_pools,
                                   erasure_pools=sorted(erasure_pools),
                                   replicated_pools=sorted(replicated_pools),
                                   pools=sorted(active_pools))
        if list_err in session:
            result = session[list_err]
            session.pop(list_err)
            return render_template('admin/disk/add_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   size_list=size_list_aval,
                                   err=result,
                                   form=request.form,
                                   failed_pools=failed_pools,
                                   erasure_pools=sorted(erasure_pools),
                                   replicated_pools=sorted(replicated_pools),
                                   pools=sorted(active_pools))
        elif list_warning in session:
            result = session[list_warning]
            session.pop(list_warning)
            return render_template('admin/disk/add_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   size_list=size_list_aval,
                                   warning=result,
                                   form=request.form,
                                   failed_pools=failed_pools,
                                   erasure_pools=sorted(erasure_pools),
                                   replicated_pools=sorted(replicated_pools),
                                   pools=sorted(active_pools))
        elif list_success in session:
            result = session[list_success]
            session.pop(list_success)
            return render_template('admin/disk/add_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   size_list=size_list_aval,
                                   success=result,
                                   form=request.form,
                                   failed_pools=failed_pools,
                                   erasure_pools=sorted(erasure_pools),
                                   replicated_pools=sorted(replicated_pools),
                                   pools=sorted(active_pools))
        else:
            form1 = add_disk_form()
            return render_template('admin/disk/add_disk.html',
                                   subnet1=subnet1_info,
                                   subnet2=subnet2_info,
                                   size_list=size_list_aval,
                                   form=form1,
                                   failed_pools=failed_pools,
                                   erasure_pools=sorted(erasure_pools),
                                   replicated_pools=sorted(replicated_pools),
                                   pools=sorted(active_pools))