Skip to content

Commit

Permalink
fix(instance) create instance from custom image needs fingerprint in …
Browse files Browse the repository at this point in the history
…payload.source

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Apr 4, 2024
1 parent 8cfaae6 commit a067da1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/pages/instances/forms/InstanceCreateDetailsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
} from "@canonical/react-components";
import ProfileSelect from "pages/profiles/ProfileSelector";
import SelectImageBtn from "pages/images/actions/SelectImageBtn";
import { isContainerOnlyImage, isVmOnlyImage, LOCAL_ISO } from "util/images";
import {
isContainerOnlyImage,
isVmOnlyImage,
LOCAL_IMAGE,
LOCAL_ISO,
} from "util/images";
import { instanceCreationTypes } from "util/instanceOptions";
import { FormikProps } from "formik/dist/types";
import { CreateInstanceFormValues } from "pages/instances/CreateInstance";
Expand Down Expand Up @@ -46,6 +51,15 @@ export const instanceDetailPayload = (values: CreateInstanceFormValues) => {
},
};

if (values.image?.server === LOCAL_IMAGE) {
payload.source = {
type: "image",
certificate: "",
fingerprint: values.image?.fingerprint,
allow_inconsistent: false,
};
}

if (values.image?.server === LOCAL_ISO) {
payload.source = {
type: "none",
Expand Down
1 change: 1 addition & 0 deletions src/types/image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface RemoteImage {
server?: string;
volume?: LxdStorageVolume;
type?: LxdImageType;
fingerprint?: string;
}

export interface RemoteImageList {
Expand Down
7 changes: 5 additions & 2 deletions src/util/images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ export const isoToRemoteImage = (volume: LxdStorageVolume): RemoteImage => {
};
};

export const LOCAL_IMAGE = "local-image";

export const localLxdToRemoteImage = (image: LxdImage): RemoteImage => {
return {
aliases: image.update_source?.alias ?? image.fingerprint,
aliases: image.update_source?.alias ?? image.aliases?.[0]?.name ?? "",
fingerprint: image.fingerprint,
arch: image.architecture === "x86_64" ? "amd64" : image.architecture,
os: image.properties?.os ?? "",
created_at: new Date(image.uploaded_at).getTime(),
release: image.properties?.release ?? "",
server: image.update_source?.server,
server: LOCAL_IMAGE,
type: image.type,
};
};
Expand Down

0 comments on commit a067da1

Please sign in to comment.