Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort vm selections #63

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading