Skip to content

Commit

Permalink
upcoming: [M3-7690] - Support PlacementGroups in CLI tool (#10438)
Browse files Browse the repository at this point in the history
* upcoming: [M3-7690] - Support PlacementGroups in CLI tool

* Add changeset
  • Loading branch information
carrillo-erik authored May 7, 2024
1 parent 423d84f commit fb52207
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add support for Placement Groups in Linode CLI tool ([#10438](https://github.com/linode/manager/pull/10438))
4 changes: 4 additions & 0 deletions packages/manager/src/utilities/generate-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const linodeData = {
metadata: {
user_data: 'cmVrbmpnYmloZXVma2xkbQpqZXZia2Y=',
},
placement_group: {
id: 1234,
},
stackscript_data: {
gh_username: 'linode',
},
Expand All @@ -43,6 +46,7 @@ const linodeDataForCLI = `
--authorized_users Gritty \\
--interfaces.ipam_address null --interfaces.ipv4.nat_1_1 \"any\" --interfaces.ipv4.vpc \"123\" --interfaces.label null --interfaces.primary true --interfaces.purpose \"vpc\" --interfaces.subnet_id 8296 \\
--metadata.user_data="cmVrbmpnYmloZXVma2xkbQpqZXZia2Y=" \\
--placement_group.id 1234 \\
--stackscript_data '{"gh_username": "linode"}' \\
--stackscript_id 10079
`.trim();
Expand Down
10 changes: 10 additions & 0 deletions packages/manager/src/utilities/generate-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
UserData,
} from '@linode/api-v4/lib/linodes/types';

import type { PlacementGroup } from '@linode/api-v4';

// Credit: https://github.com/xxorax/node-shell-escape
function escapeStringForCLI(s: string): string {
if (/[^A-Za-z0-9_\/:=-]/.test(s)) {
Expand Down Expand Up @@ -78,6 +80,7 @@ const dataEntriesReduce = (acc: string[], [key, value]: JSONFieldToArray) => {
if (value === undefined || value === null) {
return acc;
}

if (Array.isArray(value)) {
if (value.length === 0) {
return acc;
Expand All @@ -89,6 +92,12 @@ const dataEntriesReduce = (acc: string[], [key, value]: JSONFieldToArray) => {
if (key === 'metadata') {
const userData = value as UserData;
acc.push(` --${key}.user_data="${userData.user_data}"`);
} else if (key === 'placement_group') {
const placementGroup = value as PlacementGroup;
acc.push(` --${key}.id ${placementGroup.id}`);
{
/* TODO VM_Placement: Add logic to include the `compliant_only` argument */
}
} else if (typeof value === 'object') {
const valueAsString = convertObjectToCLIArg(value);
acc.push(` --${key} ${valueAsString}`);
Expand All @@ -98,6 +107,7 @@ const dataEntriesReduce = (acc: string[], [key, value]: JSONFieldToArray) => {
} else {
acc.push(` --${key} ${value}`);
}

return acc;
};

Expand Down

0 comments on commit fb52207

Please sign in to comment.