Skip to content
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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"macadam.factory.machine.image-path": {
"type": "string",
"format": "file",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"default": "",
"description": "Image Path"
},
"macadam.factory.machine.ssh-identity-path": {
"type": "string",
"format": "file",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"default": "",
"description": "Ssh Identity Path"
},
Expand All @@ -34,7 +34,7 @@
"default": "HOST_HALF_CPU_CORES",
"minimum": 1,
"maximum": "HOST_TOTAL_CPU",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"description": "CPU(s)"
},
"macadam.factory.machine.memory": {
Expand All @@ -43,7 +43,7 @@
"minimum": 1000000000,
"default": 4000000000,
"maximum": "HOST_TOTAL_MEMORY",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"step": 500000000,
"description": "Memory"
},
Expand All @@ -54,7 +54,7 @@
"minimum": 10000000000,
"maximum": "HOST_TOTAL_DISKSIZE",
"step": 500000000,
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"description": "Disk size"
},
"macadam.factory.machine.win.provider": {
Expand All @@ -64,7 +64,7 @@
"wsl",
"hyperv"
],
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"description": "Provider Type",
"when": "macadam.wslHypervEnabled"
}
Expand Down
42 changes: 17 additions & 25 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,32 @@ async function timeout(time: number): Promise<void> {
}

async function getJSONMachineList(): Promise<MachineJSONListOutput> {
const containerMachineProviders: (string | undefined)[] = [];
const vmProviders: (string | undefined)[] = [];
let hypervEnabled = false;
if (await isWSLEnabled()) {
wslEnabled = true;
containerMachineProviders.push('wsl');
vmProviders.push('wsl');
} else {
wslEnabled = false;
}

if (await isHyperVEnabled()) {
hypervEnabled = true;
containerMachineProviders.push('hyperv');
vmProviders.push('hyperv');
}
// update context "wsl-hyperv enabled" value
updateWSLHyperVEnabledContextValue(wslEnabled && hypervEnabled);

if (containerMachineProviders.length === 0) {
// in all other cases we set undefined so that it executes normally by using the default container provider
containerMachineProviders.push(undefined);
if (vmProviders.length === 0) {
// in all other cases we set undefined so that it executes normally by using the default vm provider
vmProviders.push(undefined);
}

const list: MachineJSON[] = [];
let error = '';

try {
for (const provider of containerMachineProviders) {
for (const provider of vmProviders) {
const machineListOutput = await getJSONMachineListByProvider(provider);
list.push(...machineListOutput.list);
if (machineListOutput.error && machineListOutput.error.trim() !== '') {
Expand All @@ -157,8 +157,8 @@ async function getJSONMachineList(): Promise<MachineJSONListOutput> {
return { list, error };
}

export async function getJSONMachineListByProvider(containerMachineProvider?: string): Promise<MachineJSONListOutput> {
const { stdout, stderr } = await execMacadam(['list'], containerMachineProvider);
export async function getJSONMachineListByProvider(vmProvider?: string): Promise<MachineJSONListOutput> {
const { stdout, stderr } = await execMacadam(['list'], vmProvider);
return {
list: stdout ? (JSON.parse(stdout) as MachineJSON[]) : [],
error: stderr,
Expand Down Expand Up @@ -241,30 +241,23 @@ async function registerProviderFor(
const providerConnectionShellAccess = new ProviderConnectionShellAccessImpl(machineInfo);
context.subscriptions.push(providerConnectionShellAccess);

// we are not really working with a containerProviderConnection of type podman
// however it offers most of the things we would need, so it is good for a POC
const containerProviderConnection: extensionApi.ContainerProviderConnection = {
const vmProviderConnection: extensionApi.VmProviderConnection = {
name: 'macadam',
displayName: 'Macadam',
type: 'podman',
status: () => macadamMachinesStatuses.get(machineInfo.image) ?? 'unknown',
shellAccess: providerConnectionShellAccess,
lifecycle,
endpoint: {
socketPath: 'no-socket',
},
};

const disposable = provider.registerContainerProviderConnection(containerProviderConnection);
const disposable = provider.registerVmProviderConnection(vmProviderConnection);
provider.updateStatus('ready');

// get configuration for this connection
const containerConfiguration = extensionApi.configuration.getConfiguration('macadam', containerProviderConnection);
const vmConfiguration = extensionApi.configuration.getConfiguration('macadam', vmProviderConnection);

// Set values for the machine
await containerConfiguration.update('machine.cpus', machineInfo.cpus);
await containerConfiguration.update('machine.memory', machineInfo.memory);
await containerConfiguration.update('machine.diskSize', machineInfo.diskSize);
await vmConfiguration.update('machine.cpus', machineInfo.cpus);
await vmConfiguration.update('machine.memory', machineInfo.memory);
await vmConfiguration.update('machine.diskSize', machineInfo.diskSize);

currentConnections.set(machineInfo.image, disposable);
}
Expand Down Expand Up @@ -419,10 +412,9 @@ async function createProvider(extensionContext: extensionApi.ExtensionContext):
extensionContext.subscriptions.push(provider);

// enable factory
provider.setContainerProviderConnectionFactory({
provider.setVmProviderConnectionFactory({
create: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: { [key: string]: any },
params: { [key: string]: unknown },
logger?: extensionApi.Logger,
token?: extensionApi.CancellationToken,
) => {
Expand Down