Attaches device of any type
()
| 654 | @APP.route("/scsi/attach", methods=["POST"]) |
| 655 | @login_required |
| 656 | def attach_device(): |
| 657 | """ |
| 658 | Attaches device of any type |
| 659 | """ |
| 660 | scsi_id = request.form.get("scsi_id") |
| 661 | unit = request.form.get("unit") |
| 662 | device_type = request.form.get("type") |
| 663 | drive_name = request.form.get("drive_name") |
| 664 | file_name = request.form.get("file_name") |
| 665 | |
| 666 | if not scsi_id: |
| 667 | return response(error=True, message=_("No SCSI ID specified")) |
| 668 | |
| 669 | # Attempt to fetch the drive properties based on drive name |
| 670 | drive_props = None |
| 671 | if drive_name: |
| 672 | for drive in APP.config["PISCSI_DRIVE_PROPERTIES"]: |
| 673 | if drive["name"] == drive_name: |
| 674 | drive_props = drive |
| 675 | break |
| 676 | |
| 677 | # Collect device parameters into a dictionary |
| 678 | PARAM_PREFIX = "param_" |
| 679 | params = {} |
| 680 | for item in request.form: |
| 681 | if item.startswith(PARAM_PREFIX): |
| 682 | param = request.form.get(item) |
| 683 | if param: |
| 684 | params.update({item.replace(PARAM_PREFIX, ""): param}) |
| 685 | |
| 686 | return_message = "Attached %(device_type)s to SCSI ID %(id_number)s LUN %(unit_number)s" |
| 687 | if "interface" in params.keys(): |
| 688 | bridge_status = is_bridge_configured(params["interface"]) |
| 689 | if not bridge_status["status"]: |
| 690 | return response(error=True, message=bridge_status["msg"]) |
| 691 | return_message = return_message + " - " + bridge_status["msg"] |
| 692 | |
| 693 | kwargs = { |
| 694 | "unit": int(unit), |
| 695 | "device_type": device_type, |
| 696 | "params": params, |
| 697 | } |
| 698 | |
| 699 | if file_name: |
| 700 | kwargs["params"]["file"] = file_name |
| 701 | |
| 702 | # If drive_props is defined use properies from this dict, |
| 703 | # otherwise fall back to the properties file if it exists |
| 704 | if drive_props: |
| 705 | kwargs["vendor"] = drive_props["vendor"] |
| 706 | kwargs["product"] = drive_props["product"] |
| 707 | kwargs["revision"] = drive_props["revision"] |
| 708 | kwargs["block_size"] = drive_props["block_size"] |
| 709 | else: |
| 710 | drive_properties = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}" |
| 711 | if drive_properties.is_file(): |
| 712 | process = file_cmd.read_drive_properties(drive_properties) |
| 713 | process = ReturnCodeMapper.add_msg(process) |
nothing calls this directly
no test coverage detected