DBServer::GetFreeDeviceName PHP Method

GetFreeDeviceName() public method

public GetFreeDeviceName ( $isHvm = false )
    public function GetFreeDeviceName($isHvm = false)
    {
        $list = $this->scalarizr->system->blockDevices();
        if (!$isHvm) {
            $map = array("f", "g", "h", "i", "j", "k", "l", "m", "n", "p");
            $n_map = array("1", "2", "3", "4", "5", "6");
        } else {
            $map = array("f", "g", "h", "i", "j", "k", "l", "m", "n", "p", "ba", "bb", "bc", "bd", "be", "bf", "bg", "ca", "cb", "cc", "cd", "ce", "cf", "cg");
            $n_map = array("");
        }
        $mapUsed = array();
        foreach ($list as $deviceName) {
            preg_match("/(sd|xvd)([a-z]{1,2}[0-9]*)/", $deviceName, $matches);
            if (!empty($matches[2]) && !in_array($matches[2], $mapUsed)) {
                array_push($mapUsed, $matches[2]);
            }
        }
        $deviceL = false;
        foreach ($n_map as $v) {
            foreach ($map as $letter) {
                if (in_array($letter, $mapUsed)) {
                    continue;
                }
                $deviceL = "{$letter}{$v}";
                if (!in_array($deviceL, $mapUsed)) {
                    break;
                } else {
                    $deviceL = false;
                }
            }
            if ($deviceL) {
                break;
            }
        }
        if (!$deviceL) {
            throw new Exception(_("There is no available device letter on instance for attaching EBS"));
        }
        return strlen($deviceL) == 2 && $isHvm ? "/dev/xvd{$deviceL}" : "/dev/sd{$deviceL}";
    }