-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAGMPowerCLINewFunctions.ps1
More file actions
873 lines (724 loc) · 24.3 KB
/
AGMPowerCLINewFunctions.ps1
File metadata and controls
873 lines (724 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
# Copyright 2022 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Function New-AGMAppDiscovery ([string]$hostid,[string]$ipaddress,[string]$applianceid)
{
<#
.SYNOPSIS
Runs discovery against a host
.EXAMPLE
New-AGMAppDiscovery -hostid 5678 -applianceid 1415071155
Runs application discovery against the host with ID 5678 for appliance with ID 1415071155
.DESCRIPTION
A function to run application discovery
#>
if ((!($hostid)) -and (!($ipaddress)))
{
[string]$hostid = Read-Host "Host to perform discovery on (press enter to use IP)"
if (!($hostid))
{
[string]$ipaddress = Read-Host "Host IP to perform discovery on"
}
}
if (!($applianceid))
{
[string]$applianceid = Read-Host "Appliance to perform discovery on"
}
if ($hostid)
{
$body = [ordered]@{
host = [ordered]@{
id=$hostid
sources= @(
@{
clusterid=$applianceid
}
)
}
}
}
if ($ipaddress)
{
$body = [ordered]@{
cluster=$applianceid;
type="standard";
ipaddress=$ipaddress
}
}
$jsonbody = $body | ConvertTo-Json -depth 4
Post-AGMAPIData -endpoint /host/discover -body $jsonbody
}
Function New-AGMAppliance ([string]$ipaddress,[string]$username,[string]$password,[SecureString]$passwordenc,[switch]$dryrun)
{
<#
.SYNOPSIS
Adds a new appliance to AGM
.EXAMPLE
New-AGMAppliance ipaddress 10.194.0.38 -username admin -password password -dryrun | select-object approvaltoken,cluster,report
This performs a dryrun to test if Appliance add will work. Pay close attention to the errcode in the report field and that the cluster field contains a clusterid.
You also need to see an approval token. If everything looks good, run the command again without specifying -dryrun
If you are feeling lucky you can choose to skip running the command without -dryrun
.EXAMPLE
New-AGMAppliance ipaddress 10.194.0.38 -username admin -password password
This adds the Appliance and includes a dryrun.
After it runs, then run Get-AGMAppliance to confirm the appliance has been added.
.DESCRIPTION
A function to add Appliances
For password handling there are two parameters you can use:
-password This is the Appliance password in plain text
-passwordenc This is the Appliance password as a secure string. This can be used with Powershell 7
If you don't use either parameter you will be prompted to enter the password in a secure fashion. This can be used with Powershell 7
#>
if (!($ipaddress))
{
[string]$ipaddress = Read-Host "Appliance IP Address"
}
if (!($username))
{
[string]$username = Read-Host "Appliance username"
}
if ((!($password)) -and (!($passwordenc)))
{
# prompt for a password
[SecureString]$passwordenc = Read-Host "Password" -AsSecureString
[string]$password = (Convertfrom-SecureString $passwordenc -AsPlainText)
}
if ($passwordenc)
{
[string]$password = (Convertfrom-SecureString $passwordenc -AsPlainText)
}
$body = [ordered]@{
ipaddress=$ipaddress;
username=$username;
password=$password
}
$jsonbody = $body | ConvertTo-Json
$dryrungrab = Post-AGMAPIData -endpoint /cluster/dryrun -body $jsonbody
if ($dryrun)
{
$dryrungrab
return
}
if ($dryrungrab.approvaltoken)
{
$body = [ordered]@{
ipaddress=$ipaddress;
username=$username;
password=$password;
approvaltoken=$dryrungrab.approvaltoken
}
$jsonbody = $body | ConvertTo-Json
Post-AGMAPIData -endpoint /cluster -body $jsonbody
}
else {
$dryrun
}
}
Function New-AGMCloudVM ([string]$zone,[string]$id,[string]$credentialid,[string]$clusterid,[string]$applianceid,[string]$projectid,[string]$instanceid)
{
<#
.SYNOPSIS
Adds new Cloud VMs
.EXAMPLE
New-AGMCloudVM -credentialid 1234 -zone australia-southeast1-c -clusterid 144292692833 -instanceid 4240202854121875692
Adds VM with ID 4240202854121875692 to specified appliance
.DESCRIPTION
A function to add Cloud VMs
Multiple vmids should be comma separated
#>
if (($applianceid) -and ($clusterid))
{
Get-AGMErrorMessage -messagetoprint "Do not specify both applianceid and clusterid. Only clusterid is neeeed."
return
}
if ($id) { $credentialid = $id }
if (!($credentialid))
{
[string]$credentialid = Read-Host "Credential ID"
}
if ($applianceid) { [string]$clusterid = $applianceid}
if (!($clusterid))
{
$clusterid = Read-Host "Cluster ID"
}
if (!($projectid))
{
[string]$projectid = Read-Host "Project ID"
}
#if user doesn't specify name and zone, then learn them
$credentialgrab = Get-AGMCredential -credentialid $credentialid
if (!($credentialgrab.id))
{
if ($credentialgrab.errormessage)
{
$credentialgrab
}
else
{
Get-AGMErrorMessage -messagetoprint "The credential ID $credentialid could not be found using Get-AGMCredential"
}
return
} else {
if (!($zone))
{
$zone = $credentialgrab.region
}
}
if (!($zone))
{
[string]$zone = Read-Host "Zone Name"
}
if (!($instanceid))
{
[string]$instanceid = Read-Host "Instance IDs (Comma separated)"
}
$cluster = @{ clusterid = $clusterid}
$body = [ordered]@{}
if ($AGMToken)
{
$body += @{ cluster = $cluster;
region = $zone;
listonly = $false;
vmids = $($instanceid.Split(","))
projectid = $projectid;
}
}
else
{
$body += @{ cluster = $cluster;
region = $zone;
listonly = $false;
vmids = $($instanceid.Split(","))
project = $projectid;
}
}
$json = $body | ConvertTo-Json
Post-AGMAPIData -endpoint /cloudcredential/$credentialid/discovervm/addvm -body $json
}
Function New-AGMConsistencyGroup ([string]$clusterid,[string]$applianceid,[string]$hostid,[string]$description,[string]$groupname)
{
<#
.SYNOPSIS
Adds new Consistency Group (CG)
.EXAMPLE
New-AGMConsistencyGroup -clusterid 144292692833 -groupname "prodhost1" -description "this is a CG" -hostid 12344
To learn applianceid, use this command: Get-AGMAppliance and use the clusterid as clusterid.
To learn host ID, use this command: Get-AGMHost
Once you have created the Consistency Group you can add applications to it with Set-AGMConsistencyGroupMember
Once you have created the Consistency Group you can change the name and description with Set-AGMConsistencyGroup
.DESCRIPTION
A function to add a Consistency Group
#>
if (($applianceid) -and ($clusterid))
{
Get-AGMErrorMessage -messagetoprint "Do not specify both applianceid and clusterid. Only clusterid is needed."
return
}
if ($applianceid) { [string]$clusterid = $applianceid}
if (!($clusterid))
{
$clusterid = Read-Host "Cluster ID"
}
if (!($hostid))
{
[string]$hostid = Read-Host "Host ID"
}
if (!($groupname))
{
[string]$groupname = Read-Host "Group Name"
}
# cluster needs to be like: sources":[{"clusterid":"144488110379"},{"clusterid":"143112195179"}]
$sources = @()
foreach ($cluster in $clusterid.Split(","))
{
$sources += [ordered]@{ id = $cluster }
}
# {"groupname":"testme","description":"description","cluster":{"id":"70194"},"host":{"id":"70631"}}
$body = [ordered]@{}
$body += [ordered]@{ groupname = $groupname;
cluster = $sources;
host = [ordered]@{ id = $hostid }
}
if ($description)
{
$body += @{ description = $description }
}
$json = $body | ConvertTo-Json
Post-AGMAPIData -endpoint /consistencygroup -body $json
}
Function New-AGMCredential ([string]$name,[string]$zone,[string]$clusterid,[string]$applianceid,$filename,[string]$projectid,[string]$organizationid,[string]$udsuid)
{
<#
.SYNOPSIS
Creates a cloud credential
.EXAMPLE
This is an example for release 11.0.1
New-AGMCredential -name cred1 -zone australia-southeast1-c -clusterid 144292692833 -filename keyfile.json
.EXAMPLE
This is an example for release 11.0.2
New-AGMCredential -name cred1 -zone australia-southeast1-c -clusterid 145666187717 -udsuid 1196377951
To learn the Cluster ID, use this command and use the clusterid value: Get-AGMAppliance | select clusterid,name
Comma separate the Cluster IDs if you have multiple appliances. Note you cannot specify multiple appliances from release 11.0.2 or higher
You can add org IDs with -organizationid To learn the Org IDs, use this command:
Get-AGMOrg | select-object id,name
Comma separate the Org IDs if you have multiple orgs
To add an onvault pool, use -udsuid
To learn the udsid use this command:
Get-AGMDiskPool -filtervalue pooltype=vault | select-object name,udsuid,@{N='appliancename'; E={$_.cluster.name}},@{N='applianceid'; E={$_.cluster.clusterid}}
Ensure the pool exists on all the appliances you are adding the credential to.
.DESCRIPTION
A function to create cloud credentials
#>
if (($applianceid) -and ($clusterid))
{
Get-AGMErrorMessage -messagetoprint "Do not specify both applianceid and clusterid. Only clusterid is needed."
return
}
if (!($name))
{
[string]$name = Read-Host "Credential Name"
}
if (!($zone))
{
[string]$zone = Read-Host "Default zone"
}
if ($applianceid) { [string]$clusterid = $applianceid}
if (!($clusterid))
{
[string]$clusterid = Read-Host "Cluster IDs (comma separated)"
}
if ($filename)
{
if ( Test-Path $filename )
{
$jsonkey = Get-Content -Path $filename -raw
$jsonkey = $jsonkey.replace("\n","\\n")
$jsonkey = $jsonkey.replace("`n","\n ")
$jsonkey = $jsonkey.replace('"','\"')
}
else
{
Get-AGMErrorMessage -messagetoprint "The file named $filename could not be found."
return
}
if (!($projectid))
{
$jsongrab = Get-Content -Path $filename | ConvertFrom-Json
if (!($jsongrab.project_id))
{
Get-AGMErrorMessage -messagetoprint "The file named $filename does not contain a valid project ID."
return
} else {
$projectid = $jsongrab.project_id
}
}
}
# cluster needs to be like: sources":[{"clusterid":"144488110379"},{"clusterid":"143112195179"}] or "appliance":{"clusterid":"145666187717"}
if ($filename)
{
$sources = @()
foreach ($cluster in $clusterid.Split(","))
{
$sources += [ordered]@{ clusterid = $cluster }
}
}
else
{
if ($clusterid.Split(",").count -gt 1)
{
Get-AGMErrorMessage -messagetoprint "From release 11.0.2 and higher please specify only one appliance at a time"
return
}
$clusterdetails += [ordered]@{ clusterid = $clusterid }
}
$orglist = @()
if ($organizationid)
{
foreach ($org in $organizationid.Split(","))
{
$orglist += [ordered]@{ id = $org }
}
}
$body = [ordered]@{}
$body += [ordered]@{ name = $name;
cloudtype = "GCP";
region = $zone;
endpoint = "";
orglist = $orglist
}
if ($sources)
{
$body += [ordered]@{ $projectid = $projectid }
$body += [ordered]@{ sources = $sources }
}
if ($clusterdetails)
{
$body += [ordered]@{ appliance = $clusterdetails }
}
if ($udsuid)
{
$body += [ordered]@{ vault_udsuid = $udsuid }
}
$json = $body | ConvertTo-Json -compress
# this section is post editing the JSON to add in the credential. Ideally we should do this using a PS Object rather than an edit like this.
if ($jsonkey)
{
$json = $json.Substring(0,$json.Length-1)
$json = $json + ',"credential":"' + $jsonkey +'"}'
}
# first we test it
$testcredential = Post-AGMAPIData -endpoint /cloudcredential/testconnection -body $json
if ($testcredential.errors)
{
$testcredential
return
}
Post-AGMAPIData -endpoint /cloudcredential -body $json
return
}
Function New-AGMHost ([string]$clusterid,[string]$applianceid,[string]$hostname,[string]$friendlyname,[string]$description,[string]$ipaddress,[string]$alternateip,[string]$hosttype,[string]$organizationid,[string]$secret)
{
<#
.SYNOPSIS
Adds new Hosts
.EXAMPLE
New-AGMHost -clusterid 144292692833 -hostname "prodhost1" -ipaddress "10.0.0.1"
Adds Host with name prodhost1 and IP address 10.0.0.1 to specified appliance
.EXAMPLE
New-AGMHost -clusterid "143112195179,144488110379" -hostname "prodhost1" -ipaddress "10.0.0.1" -friendlyname "mainprod" -description "this is prod, be nice" -alternateip "20.0.0.1,30.0.0.1"
Adds Host with name prodhost1 and IP address 10.0.0.1 to two specified appliances, with a friendlyname, text description and two alternate IPs.
To learn applianceid, use this command: Get-AGMAppliance and use the clusterid as clusterid. If you have multiple clusterids, comma separate them
alternateip needs to be a comma separated list of IPs
.DESCRIPTION
A function to add Hosts
#>
if (($applianceid) -and ($clusterid))
{
Get-AGMErrorMessage -messagetoprint "Do not specify both applianceid and clusterid. Only clusterid is needed."
return
}
if ($applianceid) { [string]$clusterid = $applianceid}
if (!($clusterid))
{
$clusterid = Read-Host "Cluster ID"
}
$clustergrab = Get-AGMAppliance -filtervalue clusterid=$clusterid
if ($clustergrab.count -eq 0)
{
Get-AGMErrorMessage -messagetoprint "Clusterid $clusterid could not be found. Validate clusterid with Get-AGMAppliance"
return
}
if (!($hostname))
{
[string]$hostname = Read-Host "Host name"
}
if (!($ipaddress))
{
[string]$ipaddress = Read-Host "IP Address"
}
if (!($hostype))
{
$hosttype = "generic"
}
# cluster needs to be like: sources":[{"clusterid":"144488110379"},{"clusterid":"143112195179"}]
$sources = @()
foreach ($cluster in $clusterid.Split(","))
{
$sources += [ordered]@{ clusterid = $cluster }
}
if ($organizationid)
{
$orglist = @()
foreach ($org in $organizationid.Split(","))
{
$orglist += [ordered]@{ id = $org }
}
}
# alternate IP format needs to be like: "alternateip":["10.20.0.1","10.30.0.1"],
if ($alternateip)
{
$alternateipaddresses = @( $($alternateip.Split(",")) )
}
else
{
$alternateipaddresses = @()
}
$udsagent = [ordered]@{}
if ($secret)
{
$udsagent += [ordered]@{ shared_secret = $secret }
}
$body = [ordered]@{}
$body += [ordered]@{ hosttype = $hosttype;
hostname = $hostname;
ipaddress = $ipaddress;
alternateip = $alternateipaddresses;
sources = $sources;
}
if ($orglist)
{
$body += @{ orglist = $orglist }
}
if ($description)
{
$body += @{ description = $description }
}
if ($friendlyname)
{
$body += @{ friendlypath = $friendlyname }
}
if ($secret)
{
$body += @{ udsagent = $udsagent }
}
$json = $body | ConvertTo-Json -compress
Post-AGMAPIData -endpoint /host -body $json
}
Function New-AGMMount ([string]$imageid,[string]$targethostid,[string]$jsonbody,[string]$label)
{
<#
.SYNOPSIS
Mounts an Image
.EXAMPLE
New-AGMMount -imageid 1234 -targethostid 5678
Mounts image ID 1234 to target host with ID 5678
.EXAMPLE
New-AGMMount -imageid 53776703 -jsonbody '{"@type":"mountRest","label":"test mount","host":{"id":"43673548"},"poweronvm":false,"migratevm":false}'
Mounts image ID 53776703 to target host with ID 43673548 with Label "test mount".
The jsonbody field needs to be well formed JSON. You can get this by running a mount job in the AGM GUI and then immediately displaying the audit log with:
Get-AGMAudit -filtervalue "command~POST https" -limit 1 -sort id:desc
.DESCRIPTION
A function to mount an Image
#>
if (!($imageid))
{
[string]$imageid = Read-Host "ImageID to mount"
}
if ( (!($jsonbody)) -and (!($targethostid)) )
{
[string]$targethostid = Read-Host "Target host ID to mount $imageid to"
if (!($label))
{
[string]$label = Read-Host "Label to apply to newly mounted image"
}
}
if ($targethostid)
{
$body = @{
label = $label;
host = @{id=$targethostid}
}
$jsonbody = $body | ConvertTo-Json
}
Post-AGMAPIData -endpoint /backup/$imageid/mount -body $jsonbody
}
Function New-AGMSLA ([string]$appid,[string]$slpid,[string]$sltid,[string]$jsonbody,[string]$scheduler)
{
<#
.SYNOPSIS
Creates an SLA
.EXAMPLE
New-AGMSLA -appid 1234 -sltid 5678 -slpid 9012 -scheduler disabled
Creates a new SLA using APPID, SLT ID and SLP ID with scheduler disabled.
Details about the new SLA will be returned.
The scheduler is disabled so options can be set.
You can enable the scheduler with Set-AGMSLA
If no options are needed, you don't need to specify scheduler state
.DESCRIPTION
A function to create an SLA
#>
if (($id) -and (!($appid)) )
{
$appid = $id
}
if (!($sltid))
{
$sltid = Read-Host "SLT ID"
}
if (!($slpid))
{
$slpid = Read-Host "SLP ID"
}
if (!($jsonbody))
{
$application = New-Object -TypeName psobject
$application | Add-Member -MemberType NoteProperty -Name id -Value $appid
$slp = New-Object -TypeName psobject
$slp | Add-Member -MemberType NoteProperty -Name id -Value $slpid
$slt = New-Object -TypeName psobject
$slt | Add-Member -MemberType NoteProperty -Name id -Value $sltid
$body = New-Object -TypeName psobject
$body | Add-Member -MemberType NoteProperty -name application -Value $application
if (!($scheduler))
{
$body | Add-Member -MemberType NoteProperty -Name scheduleoff -Value "false"
}
if ($scheduler.ToLower() -eq "enable")
{
$body | Add-Member -MemberType NoteProperty -Name scheduleoff -Value "false"
}
if ($scheduler.ToLower() -eq "disable")
{
$body | Add-Member -MemberType NoteProperty -Name scheduleoff -Value "true"
}
$body | Add-Member -MemberType NoteProperty -name slp -Value $slp
$body | Add-Member -MemberType NoteProperty -name slt -Value $slt
$jsonbody = $body | ConvertTo-Json
}
Post-AGMAPIData -endpoint /sla -body $jsonbody
}
Function New-AGMUser ([string]$name,[string]$timezone,[string]$rolelist,[string]$orglist)
{
<#
.SYNOPSIS
Creates a User
.EXAMPLE
New-AGMUser -name "user@user.user" -rolelist "2,3" -orglist "4,5"
Creates a new user
.DESCRIPTION
A function to create a User
#>
if (!($name))
{
Get-AGMErrorMessage -messagetoprint "Specify a username in email format with -name"
return
}
if ($AGMToken)
{
if ($name -notlike "*@*")
{
Get-AGMErrorMessage -messagetoprint "Specify a username in email format with -name"
return
}
}
if (!($rolelist))
{
Get-AGMErrorMessage -messagetoprint "Specify a comma separated rolelist with -rolelist"
return
}
if ($rolelist)
{
$rolebody = @()
foreach ($role in $rolelist.Split(","))
{
$rolebody += New-Object -TypeName psobject -Property @{id="$role"}
}
}
if ($orglist)
{
$orgbody = @()
foreach ($org in $orglist.Split(","))
{
$orgbody += New-Object -TypeName psobject -Property @{id="$org"}
}
}
$body = [ordered]@{
name = $name;
dataaccesslevel = "0";
timezone = $timezone;
rolelist = $rolebody
orglist = $orgbody
}
$jsonbody = $body | ConvertTo-Json
Post-AGMAPIData -endpoint /user -body $jsonbody
}
<#
.SYNOPSIS
Discover VMWare VMs through AGM
.EXAMPLE
New-AGMVMDiscovery -vCenterId 6880886
#>
function New-AGMVMDiscovery {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[int]
$vCenterId
)
Get-AGMAPIData -endpoint "/host/$vCenterId/discovervm"
}
<#
.SYNOPSIS
Create a new application for a VMWare VM.
.EXAMPLE
New-AGMVMApp -vCenterId 7550156 -Cluster 6019 -ClusterName cluster_foo -VmUuids ["91cd1ae2-9fbe-16bf-de71-f1577ab0a1b3"]
#>
function New-AGMVMApp {
[CmdletBinding()]
param (
# The `id` of the vCenter host, you can find the `id` by `(Get-AGMHost -filtervalue "isvcenterhost=true") | Select-Object id,name`
[Parameter(Mandatory = $true)]
[int]
$vCenterId,
# The `id` of an appliance, it is NOT the `appliance_id`, you can get the appliance by `Get-AGMAppliance`
[Parameter(Mandatory = $true)]
[int]
$Cluster,
# The `clustername` of a cluster, you can get the cluster name by `Get-AGMClusterName -vCenterId <your-vcenter-id>`
[Parameter(Mandatory = $true)]
[string]
$ClusterName,
# The UUIDs of those VMs to be protected, UUIDs are included in the response of `New-AGMVMDiscovery`
[Parameter(Mandatory = $true)]
[string[]]
$VmUuids
)
$body = [ordered]@{
cluster=$Cluster;
addvms=$true;
vms=$VmUuids;
}
$json = $body | ConvertTo-Json
Write-Verbose "New-AGMVMApp"
Write-Verbose "/host/$vCenterId/host/$ClusterName/addvms"
Write-Verbose $json
Post-AGMAPIData -endpoint "/host/$vCenterId/host/$ClusterName/addvms" -body $json
}
Function New-AGMLogicalGroup ([string]$name,[string]$clusterid,[string]$description)
{
<#
.SYNOPSIS
Creates a new Logical Group (LG) in the AGM system.
.EXAMPLE
New-AGMLogicalGroup -name "GCP-VM-Group" -clusterid "28075556" -description "Logical Group for GCP VMs"
Creates a Logical Group named 'GCP-VM-Group' associated with the specified cluster ID.
.EXAMPLE
New-AGMLogicalGroup -name "TestGroup" -clusterid "28075556"
Creates a Logical Group with only a name and cluster ID.
.DESCRIPTION
A function to create a Logical Group. Logical Groups are used to organize applications
that are protected by the same appliance (cluster).
To learn the Cluster ID, use the 'Get-AGMAppliance' command.
#>
if (!($name))
{
[string]$name = Read-Host "Logical Group Name"
}
if (!($clusterid))
{
[string]$clusterid = Read-Host "Cluster ID"
}
# 1. Construct the Main JSON Body
$body = [ordered]@{
name = $name;
description = $description; # PowerShell sends empty string if not provided
cluster = [ordered]@{
id = $clusterid
}
}
$json = $body | ConvertTo-Json -Compress
Write-Verbose "New-AGMLogicalGroup: JSON Payload: $json"
# 2. Call the AGM API
# The endpoint is /logicalgroup and the method is POST for creation.
Post-AGMAPIData -endpoint "/logicalgroup" -body $json
}