Skip to content

Commit

Permalink
Merge pull request #63 from katmastt/main
Browse files Browse the repository at this point in the history
Sort vm selections
  • Loading branch information
eleni-adamidi authored Oct 19, 2023
2 parents 3911bea + 79c3581 commit a3a4a12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
18 changes: 10 additions & 8 deletions models/MachineComputeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ public function init()
$flavors=$response->data['flavors'];
// print_r($flavors);
// exit(0);
usort($flavors, "self::cmp");

//sort by cpu. If cpu is the same, sort by ram. If ram is the same sort by disk
usort($flavors, function ($a, $b) {
if ($a['vcpus'] !== $b['vcpus']) {
return $a['vcpus'] - $b['vcpus'];
} elseif($a['ram'] !== $b['ram']) {
return $a['ram'] - $b['ram'];
}
return $a['disk'] - $b['disk'];
});

foreach ($flavors as $flavor)
{
Expand Down Expand Up @@ -120,9 +129,6 @@ public function init()
$this->flavourIdName[$id]=$name;

}

asort($this->flavours);

}
/**
* {@inheritdoc}
Expand Down Expand Up @@ -391,8 +397,4 @@ public function getDiff($other) {

return $diff;
}

public function cmp($a, $b){
return strcmp($a['vcpus'], $b['vcpus']);
}
}
10 changes: 8 additions & 2 deletions models/ServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public function init()
if($flag)
{
$flavors=$response->data['flavors'];

//sort by cpu. If cpu is the same, sort by ram
usort($flavors, function ($a, $b) {
if ($a['vcpus'] == $b['vcpus']) {
return $a['ram'] - $b['ram'];
}
return $a['vcpus'] - $b['vcpus'];
});

foreach ($flavors as $flavor)
{
Expand Down Expand Up @@ -204,7 +212,6 @@ public function init()
}
// $this->flavour=(!empty($this->vm_flavour)) ? $this->flavourIdName[$this->vm_flavour] : '';

asort($this->flavours);
}
// print_r($this->vm_flavour);
// print_r($this->flavour);
Expand Down Expand Up @@ -575,5 +582,4 @@ public function getDiff($other) {

return $diff;
}

}
2 changes: 1 addition & 1 deletion views/project/new_machine_compute_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</div>
<div class="row">&nbsp;</div>

<?= $form->field($service,'flavour')->dropDownList(array_reverse($service->flavours))->label($flavour_label)?>
<?= $form->field($service,'flavour')->dropDownList($service->flavours)->label($flavour_label)?>
<?= $form->field($service,'num_of_vms')->dropDownList($num_vms_dropdown)?>

<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion views/project/new_service_request.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</div>
<div class="row">&nbsp;</div>

<?= $form->field($service,'flavour')->dropDownList(array_reverse($service->flavours))->label($flavour_label)?>
<?= $form->field($service,'flavour')->dropDownList($service->flavours)->label($flavour_label)?>


<div class="row">
Expand Down

0 comments on commit a3a4a12

Please sign in to comment.