1
- import type {
2
- Images ,
3
- State ,
4
- GoogleCloudConfiguration as GoogleCloudConfigurationType ,
5
- ComputeServerTemplate ,
6
- GoogleCloudAcceleratorType ,
7
- } from "@cocalc/util/db-schema/compute-servers" ;
8
- import { reloadImages , useImages , useGoogleImages } from "./images-hook" ;
9
- import { GOOGLE_CLOUD_DEFAULTS } from "@cocalc/util/db-schema/compute-servers" ;
10
- import {
11
- getMinDiskSizeGb ,
12
- getArchitecture ,
13
- } from "@cocalc/util/db-schema/compute-servers" ;
14
1
import {
15
2
Alert ,
16
3
Button ,
@@ -25,44 +12,60 @@ import {
25
12
Tooltip ,
26
13
Typography ,
27
14
} from "antd" ;
28
- import { currency , cmp , plural } from "@cocalc/util/misc" ;
15
+ import { isEqual } from "lodash" ;
16
+ import { useEffect , useState } from "react" ;
17
+
18
+ import { useTypedRedux } from "@cocalc/frontend/app-framework" ;
19
+ import { A } from "@cocalc/frontend/components/A" ;
20
+ import ShowError from "@cocalc/frontend/components/error" ;
21
+ import { Icon } from "@cocalc/frontend/components/icon" ;
22
+ import Disk from "@cocalc/frontend/compute/cloud/common/disk" ;
23
+ import DNS from "@cocalc/frontend/compute/cloud/common/dns" ;
24
+ import Template from "@cocalc/frontend/compute/cloud/common/template" ;
25
+ import { displayAcceleratorType } from "@cocalc/frontend/compute/cloud/google-cloud/accelerator" ;
26
+ import Specs , {
27
+ RamAndCpu ,
28
+ } from "@cocalc/frontend/compute/cloud/google-cloud/specs" ;
29
+ import ExcludeFromSync from "@cocalc/frontend/compute/exclude-from-sync" ;
30
+ import { filterOption } from "@cocalc/frontend/compute/util" ;
29
31
import computeCost , {
30
- GoogleCloudData ,
31
- EXTERNAL_IP_COST ,
32
- DATA_TRANSFER_OUT_COST_PER_GiB ,
33
- markup ,
34
32
computeAcceleratorCost ,
35
- computeInstanceCost ,
36
33
computeDiskCost ,
34
+ computeInstanceCost ,
35
+ DATA_TRANSFER_OUT_COST_PER_GiB ,
36
+ EXTERNAL_IP_COST ,
37
+ GoogleCloudData ,
38
+ markup ,
37
39
} from "@cocalc/util/compute/cloud/google-cloud/compute-cost" ;
40
+ import type {
41
+ Architecture ,
42
+ ComputeServerTemplate ,
43
+ GoogleCloudAcceleratorType ,
44
+ GoogleCloudConfiguration as GoogleCloudConfigurationType ,
45
+ Images ,
46
+ State ,
47
+ } from "@cocalc/util/db-schema/compute-servers" ;
48
+ import {
49
+ getArchitecture ,
50
+ getMachineTypeArchitecture ,
51
+ getMinDiskSizeGb ,
52
+ GOOGLE_CLOUD_DEFAULTS ,
53
+ } from "@cocalc/util/db-schema/compute-servers" ;
54
+ import { cmp , currency , plural } from "@cocalc/util/misc" ;
55
+ import AllowCollaboratorControl from "./allow-collaborator-control" ;
38
56
import {
39
57
getGoogleCloudPriceData ,
40
58
setImageTested ,
41
59
setServerConfiguration ,
42
60
} from "./api" ;
43
- import { useEffect , useState } from "react" ;
44
- import { A } from "@cocalc/frontend/components/A" ;
45
- import { Icon } from "@cocalc/frontend/components/icon" ;
46
- import { isEqual } from "lodash" ;
47
- import { useTypedRedux } from "@cocalc/frontend/app-framework" ;
48
- import SelectImage , { ImageLinks , ImageDescription } from "./select-image" ;
49
- import Ephemeral from "./ephemeral" ;
50
61
import AutoRestart from "./auto-restart" ;
51
- import AllowCollaboratorControl from "./allow-collaborator-control" ;
62
+ import { availableClouds } from "./config" ;
63
+ import CostOverview from "./cost-overview" ;
64
+ import Ephemeral from "./ephemeral" ;
65
+ import { reloadImages , useGoogleImages , useImages } from "./images-hook" ;
52
66
import NestedVirtualization from "./nested-virtualization" ;
53
- import ShowError from "@cocalc/frontend/components/error" ;
54
67
import Proxy from "./proxy" ;
55
- import CostOverview from "./cost-overview" ;
56
- import Disk from "@cocalc/frontend/compute/cloud/common/disk" ;
57
- import DNS from "@cocalc/frontend/compute/cloud/common/dns" ;
58
- import ExcludeFromSync from "@cocalc/frontend/compute/exclude-from-sync" ;
59
- import { availableClouds } from "./config" ;
60
- import Template from "@cocalc/frontend/compute/cloud/common/template" ;
61
- import Specs , {
62
- RamAndCpu ,
63
- } from "@cocalc/frontend/compute/cloud/google-cloud/specs" ;
64
- import { displayAcceleratorType } from "@cocalc/frontend/compute/cloud/google-cloud/accelerator" ;
65
- import { filterOption } from "@cocalc/frontend/compute/util" ;
68
+ import SelectImage , { ImageDescription , ImageLinks } from "./select-image" ;
66
69
67
70
export const SELECTOR_WIDTH = "350px" ;
68
71
@@ -794,9 +797,7 @@ function Provisioning({ priceData, setConfig, configuration, disabled }) {
794
797
</ Radio . Button >
795
798
< Radio . Button value = "standard" >
796
799
Standard{ " " }
797
- { prices != null
798
- ? `${ currency ( prices . standard ) } /hour`
799
- : undefined } { " " }
800
+ { prices != null ? `${ currency ( prices . standard ) } /hour` : undefined } { " " }
800
801
</ Radio . Button >
801
802
</ Radio . Group >
802
803
< div style = { { color : "#666" , marginTop : "5px" } } >
@@ -939,17 +940,19 @@ function Zone({ priceData, setConfig, configuration, disabled }) {
939
940
}
940
941
941
942
function MachineType ( { priceData, setConfig, configuration, disabled, state } ) {
942
- const [ archType , setArchType ] = useState < "x86_64" | "arm64" > (
943
+ const [ archType , setArchType ] = useState < Architecture > (
943
944
getArchitecture ( configuration ) ,
944
945
) ;
945
946
const [ sortByPrice , setSortByPrice ] = useState < boolean > ( true ) ;
946
947
const [ newMachineType , setNewMachineType ] = useState < string > (
947
948
configuration . machineType ?? "" ,
948
949
) ;
950
+
949
951
useEffect ( ( ) => {
950
952
setNewMachineType ( configuration . machineType ) ;
951
953
setArchType ( getArchitecture ( configuration ) ) ;
952
954
} , [ configuration . machineType ] ) ;
955
+
953
956
useEffect ( ( ) => {
954
957
if ( archType == "arm64" && getArchitecture ( configuration ) != "arm64" ) {
955
958
setNewMachineType ( "t2a-standard-4" ) ;
@@ -964,17 +967,19 @@ function MachineType({ priceData, setConfig, configuration, disabled, state }) {
964
967
} , [ archType , configuration . machineType ] ) ;
965
968
966
969
const machineTypes = Object . keys ( priceData . machineTypes ) ;
967
- let allOptions = machineTypes
970
+ const allOptions = machineTypes
968
971
. filter ( ( machineType ) => {
969
972
const { acceleratorType } = configuration ;
970
973
if ( ! acceleratorType ) {
971
974
if ( machineType . startsWith ( "g" ) || machineType . startsWith ( "a" ) ) {
972
975
return false ;
973
976
}
974
- if ( archType == "arm64" && getArchitecture ( configuration ) != "arm64" ) {
977
+ // Check if the machine type's architecture matches the selected architecture
978
+ const machineArch = getMachineTypeArchitecture ( machineType ) ;
979
+ if ( archType == "arm64" && machineArch != "arm64" ) {
975
980
return false ;
976
981
}
977
- if ( archType == "x86_64" && getArchitecture ( configuration ) == "arm64 ") {
982
+ if ( archType == "x86_64" && machineArch != "x86_64 ") {
978
983
return false ;
979
984
}
980
985
} else {
@@ -1049,8 +1054,8 @@ function MachineType({ priceData, setConfig, configuration, disabled, state }) {
1049
1054
( state ?? "deprovisioned" ) != "deprovisioned"
1050
1055
? "Can only be changed when machine is deprovisioned"
1051
1056
: archType == "x86_64"
1052
- ? "Intel or AMD X86_64 architecture machines"
1053
- : "ARM64 architecture machines"
1057
+ ? "Intel or AMD X86_64 architecture machines"
1058
+ : "ARM64 architecture machines"
1054
1059
}
1055
1060
>
1056
1061
< Radio . Group
0 commit comments