Commit 53e2c3db authored by Thomas Goirand's avatar Thomas Goirand

Handle RAID system devices when building the ring.

parent b6d82f16
......@@ -1100,53 +1100,72 @@ function build_swift_ring($con, $conf, $cluster_id, $verbose="no"){
exec($cmd, $output, $return_var);
$q = "SELECT machines.hostname AS hostname, INET_NTOA(ips.ip) AS ipaddr, blockdevices.name AS hddname, machines.location_id AS locationid FROM ips,machines,blockdevices WHERE machines.cluster='$cluster_id' AND machines.role='swiftstore' AND machines.id=blockdevices.machine_id AND ips.machine=machines.id AND name NOT LIKE '%da' ORDER BY ips.ip, blockdevices.name";
$q = "SELECT machines.hostname AS hostname, INET_NTOA(ips.ip) AS ipaddr, machines.location_id AS locationid FROM ips,machines WHERE machines.cluster='$cluster_id' AND machines.role='swiftstore' AND ips.machine=machines.id ORDER BY ips.ip";
$r = mysqli_query($con, $q);
$n = mysqli_num_rows($r);
$last_ip = "";
for($i=0;$i<$n;$i++){
$blockdev = mysqli_fetch_array($r);
$blockdev_locationid = $blockdev["locationid"];
$blockdev_ipaddr = $blockdev["ipaddr"];
$blockdev_devicename = $blockdev["hddname"];
$hostname = $blockdev["hostname"];
$q = "SELECT swiftregions.id AS swiftregion FROM locations,swiftregions WHERE locations.id='$blockdev_locationid' AND swiftregions.name=locations.swiftregion";
$rsw = mysqli_query($con, $q);
$nsw = mysqli_num_rows($rsw);
if($nsw == 0){
$swiftregion = "0";
$machine = mysqli_fetch_array($r);
$blockdev_locationid = $machine["locationid"];
$blockdev_ipaddr = $machine["ipaddr"];
$hostname = $machine["hostname"];
$machine_id = $machine["id"];
if($machine["install_on_raid"] == "no"){
$q = "SELECT blockdevices.name AS hddname FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '%da' ORDER BY blockdevices.name";
}else{
$asr = mysqli_fetch_array($rsw);
$swiftregion = $asr["swiftregion"] + 1;
switch($machine["raid_type"]){
case "0":
case "1":
$q = "SELECT blockdevices.name AS hddname FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."' ORDER BY blockdevices.name";
break;
case "10":
$q = "SELECT blockdevices.name AS hddname FROM blockdevices WHERE machine_id='$machine_id' AND name NOT LIKE '".$machine["raid_dev0"]."' AND name NOT LIKE '".$machine["raid_dev1"]."' AND name NOT LIKE '".$machine["raid_dev2"]."' AND name NOT LIKE '".$machine["raid_dev3"]."' ORDER BY blockdevices.name";
break;
default:
case "5":
die("Not supported yet...");
break;
}
}
# Account
$cmd = "swift-ring-builder $swift_ring_path/account.builder add --region $swiftregion --zone $blockdev_locationid --ip $blockdev_ipaddr --port 6002 --device $blockdev_devicename --weight 100";
if($verbose == "yes"){ print("Adding $hostname, $blockdev_devicename to the account ring: $cmd<br>\n"); ob_flush(); }else{ $out .= "Adding $hostname, $blockdev_devicename to the account ring:\n ===> $cmd\n";}
$output = array();
$return_var = 0;
exec($cmd, $output, $return_var);
$r = mysqli_query($con, $q);
$n = mysqli_num_rows($r);
$blockdev_object_port = 6200;
for($j=0;$j<$n;$j++){
$blockdev = mysqli_fetch_array($r);
$blockdev_devicename = $blockdev["hddname"];
# Container
$cmd = "swift-ring-builder $swift_ring_path/container.builder add --region $swiftregion --zone $blockdev_locationid --ip $blockdev_ipaddr --port 6001 --device $blockdev_devicename --weight 100";
if($verbose == "yes"){ print("Adding $hostname, $blockdev_devicename to the container ring: $cmd<br>\n"); ob_flush(); }else{ $out .= "Adding $hostname, $blockdev_devicename to the container ring:\n ===> $cmd\n";}
$output = array();
$return_var = 0;
exec($cmd, $output, $return_var);
$q = "SELECT swiftregions.id AS swiftregion FROM locations,swiftregions WHERE locations.id='$blockdev_locationid' AND swiftregions.name=locations.swiftregion";
$rsw = mysqli_query($con, $q);
$nsw = mysqli_num_rows($rsw);
if($nsw == 0){
$swiftregion = "0";
}else{
$asr = mysqli_fetch_array($rsw);
$swiftregion = $asr["swiftregion"] + 1;
}
# Account
$cmd = "swift-ring-builder $swift_ring_path/account.builder add --region $swiftregion --zone $blockdev_locationid --ip $blockdev_ipaddr --port 6002 --device $blockdev_devicename --weight 100";
if($verbose == "yes"){ print("Adding $hostname, $blockdev_devicename to the account ring: $cmd<br>\n"); ob_flush(); }else{ $out .= "Adding $hostname, $blockdev_devicename to the account ring:\n ===> $cmd\n";}
$output = array();
$return_var = 0;
exec($cmd, $output, $return_var);
# Container
$cmd = "swift-ring-builder $swift_ring_path/container.builder add --region $swiftregion --zone $blockdev_locationid --ip $blockdev_ipaddr --port 6001 --device $blockdev_devicename --weight 100";
if($verbose == "yes"){ print("Adding $hostname, $blockdev_devicename to the container ring: $cmd<br>\n"); ob_flush(); }else{ $out .= "Adding $hostname, $blockdev_devicename to the container ring:\n ===> $cmd\n";}
$output = array();
$return_var = 0;
exec($cmd, $output, $return_var);
# Object
$cmd = "swift-ring-builder $swift_ring_path/object.builder add --region $swiftregion --zone $blockdev_locationid --ip $blockdev_ipaddr --port $blockdev_object_port --device $blockdev_devicename --weight 100";
if($verbose == "yes"){ print("Adding $hostname, $blockdev_devicename to the object ring: $cmd<br>\n"); ob_flush(); }else{ $out .= "Adding $hostname, $blockdev_devicename to the object ring:\n ===> $cmd\n";}
$output = array();
$return_var = 0;
exec($cmd, $output, $return_var);
# Object
if($blockdev_ipaddr != $last_ip){
$blockdev_object_port = 6200;
}else{
$blockdev_object_port += 1;
}
$last_ip = $blockdev_ipaddr;
$cmd = "swift-ring-builder $swift_ring_path/object.builder add --region $swiftregion --zone $blockdev_locationid --ip $blockdev_ipaddr --port $blockdev_object_port --device $blockdev_devicename --weight 100";
if($verbose == "yes"){ print("Adding $hostname, $blockdev_devicename to the object ring: $cmd<br>\n"); ob_flush(); }else{ $out .= "Adding $hostname, $blockdev_devicename to the object ring:\n ===> $cmd\n";}
$output = array();
$return_var = 0;
exec($cmd, $output, $return_var);
}
# Account
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment