@controlplane/cli
Version:
Control Plane Corporation CLI
195 lines • 7.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Create = exports.MemcacheClusterCmd = void 0;
const options_1 = require("./options");
const generic_1 = require("./generic");
const resolver_1 = require("./resolver");
const command_1 = require("../cli/command");
const functions_1 = require("../util/functions");
const objects_1 = require("../util/objects");
const versions = ['1.5.22', '1.6.17'];
const memcachecluster_defaults = {
nodeCount: 1,
nodeSizeGiB: 0.25,
version: versions[0],
options: {
evictionsDisabled: true,
idleTimeoutSeconds: 600,
maxItemSizeKiB: 1024,
maxConnections: 1024,
},
};
class MemcacheClusterCmd extends command_1.Command {
constructor() {
super(...arguments);
this.command = 'memcachecluster';
this.aliases = ['memcache'];
this.describe = 'Manage a persistent volumeset within a global virtual cloud';
}
builder(yargs) {
const resolver = (0, resolver_1.kindResolver)('memcachecluster');
const opts = [options_1.withStandardOptions, options_1.withOrgOptions];
const commandName = 'memcache cluster';
const commandNamePlural = 'memcache clusters';
const commandNameA = 'a memcache cluster';
return (yargs
.demandCommand()
.version(false)
.help()
// generic
.command(new generic_1.Get(commandName, resolver, ...opts).toYargs())
.command(new generic_1.Edit(commandName, resolver, ...opts).toYargs())
.command(new generic_1.Patch(commandName, resolver, ...opts).toYargs())
.command(new generic_1.Query(commandNamePlural, resolver, undefined, ...opts).toYargs())
.command(new generic_1.Delete(commandNamePlural, resolver, ...opts).toYargs())
.command(new generic_1.Eventlog(commandName, resolver, ...opts).toYargs())
.command(new generic_1.Tag(commandNamePlural, resolver, ...opts).toYargs())
.command(new generic_1.ListPermissions(commandNameA, resolver, ...opts).toYargs())
.command(new generic_1.ViewAccessReport(commandName, resolver, ...opts).toYargs())
.command(new generic_1.Clone(commandName, resolver, ...opts).toYargs())
.command(new generic_1.Update(commandName, resolver, [
{
path: 'description',
},
{
path: 'tags.<key>',
},
{
path: 'spec.nodeCount',
type: 'number',
},
{
path: 'spec.nodeSizeGiB',
type: 'number',
},
{
path: 'spec.version',
choices: versions,
},
{
path: 'spec.options.evictionsDisabled',
type: 'boolean',
},
{
path: 'spec.options.idleTimeoutSeconds',
type: 'number',
},
{
path: 'spec.options.maxItemSizeKiB',
type: 'number',
},
{
path: 'spec.options.maxConnections',
type: 'number',
},
], ...opts).toYargs())
// specific
.command(new Create(resolver).toYargs()));
}
handle() { }
}
exports.MemcacheClusterCmd = MemcacheClusterCmd;
class Create extends command_1.Command {
constructor(resolve) {
super();
this.resolve = resolve;
this.command = 'create';
this.describe = 'Create a new memcache cluster';
}
builder(yargs) {
return (0, functions_1.pipe)(
//
(yargs) => {
return yargs.options({
name: {
describe: 'Name of the new memcache cluster',
requiresArg: true,
demandOption: true,
},
description: {
alias: 'desc',
describe: 'Optional description, defaults to the name if not set',
},
location: {
describe: 'One or more locations to associate with this new memcache cluster',
requiresArg: true,
multiple: true,
demandOption: true,
},
'node-count': {
describe: 'Node count',
default: memcachecluster_defaults.nodeCount,
requiresArg: true,
number: true,
},
'node-size': {
describe: 'Node size in GiB',
default: memcachecluster_defaults.nodeSizeGiB,
requiresArg: true,
number: true,
},
version: {
describe: 'Version',
default: memcachecluster_defaults.version,
choices: versions,
requiresArg: true,
},
'evictions-disabled': {
describe: 'Evictions Disabled',
default: memcachecluster_defaults.options.evictionsDisabled,
requiresArg: true,
boolean: true,
},
'idle-timeout-seconds': {
describe: 'Idle timeout seconds',
default: memcachecluster_defaults.options.idleTimeoutSeconds,
requiresArg: true,
number: true,
},
'max-item-size': {
describe: 'Max item size in KiB',
default: memcachecluster_defaults.options.maxItemSizeKiB,
requiresArg: true,
number: true,
},
'max-connections': {
describe: 'Max Connections',
default: memcachecluster_defaults.options.maxConnections,
requiresArg: true,
number: true,
},
});
}, generic_1.withTagOptions, options_1.withAllOptions)(yargs);
}
async handle(args) {
const locationLinks = (0, objects_1.toArray)(args.location).map((loc) => (0, resolver_1.resolveToLink)('location', loc, this.session.context));
const req = toCreateMemcacheClusterRequest(args);
req.spec.locations = locationLinks;
const link = this.resolve.parentLink(this.session.context);
const body = await this.client.create(link, req);
this.session.outFormat(body);
}
}
exports.Create = Create;
function toCreateMemcacheClusterRequest(args) {
var _a;
const req = {
name: args.name,
description: (_a = args.description) !== null && _a !== void 0 ? _a : args.name,
tags: (0, generic_1.fromTagOptions)(args),
spec: {},
};
req.spec = {
nodeCount: args.nodeCount,
nodeSizeGiB: args.nodeSize,
version: args.version,
options: {
evictionsDisabled: args.evictionsDisabled,
idleTimeoutSeconds: args.idleTimeoutSeconds,
maxItemSizeKiB: args.maxItemSizeKiB,
maxConnections: args.maxConnections,
},
};
return req;
}
//# sourceMappingURL=memcachecluster.js.map