forked from fifthecho/CloudStack-PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloudStackCreateSecurityGroups.ps1
53 lines (45 loc) · 1.41 KB
/
CloudStackCreateSecurityGroups.ps1
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
<#
.SYNOPSIS
A CloudStack/CloudPlatform SecurityGroup Creating Scriptlet.
.DESCRIPTION
create a security group of a CloudStack Cloud.
This function return a ID matching to the securityGroup just created
.EXAMPLE
CloudStackCreateSecurityGroups.ps1
#>
# Writen by Jerome RIVIERE (www.jerome-riviere.re)
# Use CloudStackClientModule
# 2014/5/13 v1.0 created
Param(
[Parameter(Mandatory=$true)]
[String]
$name
,
[Parameter(Mandatory=$false)]
[String]
$description
)
Import-Module CloudStackClient
$parameters = Import-CloudStackConfig
if ($parameters -ne 1) {
$cloud = New-CloudStack -apiEndpoint $parameters[0] -apiPublicKey $parameters[1] -apiSecretKey $parameters[2]
$options = @("name=$name")
if($description){
$options += "description=$description"
}
$id = .\CloudStackListSecurityGroups.ps1 -name $name
if($id -eq $null){
$job = Get-CloudStack -cloudStack $cloud -command createSecurityGroup -options $options
$securityGroup = $job.createsecuritygroupresponse
$securityGroupId = $securityGroup.SecurityGroup.ID
$securityGroupName = $securityGroup.SecurityGroup.name
write-host "Security Group $securityGroupName is associated with Security Group ID $securityGroupId"
return $securityGroupId
}else{
Write-Host "The security Group with the name $name exist. the associate ID is $id"
return $id
}
}
else {
Write-Error "Please configure the $env:userprofile\cloud-settings.txt file"
}