Skip to content

Commit 1503c1b

Browse files
committed
v2.1 - new functions added
Cleanup and new functions.
1 parent d1e960b commit 1503c1b

File tree

2 files changed

+169
-1
lines changed

2 files changed

+169
-1
lines changed

Skytap.psm1

+169-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,35 @@ function Edit-Configuration ( [string]$configId, $configAttributes ){
167167

168168
Set-Alias Edit-Environment Edit-Configuration
169169

170+
function Edit-VM ( [string]$configId, $vmid, $vmAttributes ){
171+
<#
172+
.SYNOPSIS
173+
Change VM attributes
174+
.SYNTAX
175+
Edit-VM ConfigId VMId Attribute-Hash
176+
.EXAMPLE
177+
Edit-VM 12345 54321 @{name='my vm'; description='windows v10'}
178+
179+
Or
180+
181+
$Attrib = @{name='my vm'; description='windows v10'}
182+
Edit-Configuration 12345 54321 $Attrib
183+
184+
#>
185+
try {
186+
$uri = "$url/configurations/$configId/vms/$vmid/"
187+
188+
$body = $vmAttributes
189+
$result = Invoke-RestMethod -Uri $uri -Method PUT -Body (ConvertTo-Json $body) -ContentType "application/json" -Headers $headers
190+
$result | Add-member -MemberType NoteProperty -name requestResultCode -value 0
191+
} catch {
192+
$global:errorResponse = $_.Exception
193+
$result = Show-RequestFailure
194+
return $result
195+
}
196+
return $result
197+
}
198+
170199
function Edit-VMUserdata ( [string]$configId, $vmid, $userdata ){
171200
<#
172201
.SYNOPSIS
@@ -1202,7 +1231,7 @@ function Get-Usage ([string]$rid='0', [string]$startAt,[string]$endAt,[string]$r
12021231
Get-Usage $stype $objectId $title $scheduleActions $startAt $recurringDays $endAt $timezone $deleteAtEnd $newConfigName
12031232
Returns schedule object
12041233
.EXAMPLE
1205-
Get-Usage -rid <report Id> -scheduleActions [action hash] -startAt "2013/09/09 09:00" -endAt "2013/10/09 0900" -timezone "Central Time (US & Canada)" -deleteAtEnd $True
1234+
Get-Usage -rid <report Id> -startAt "2013/09/09 09:00" -endAt "2013/10/09 0900" -timezone "Central Time (US & Canada)" -deleteAtEnd $True
12061235
#>
12071236
if ($rid -eq '0') {
12081237
$uri = "$global:url/reports"
@@ -1256,6 +1285,84 @@ function Get-Usage ([string]$rid='0', [string]$startAt,[string]$endAt,[string]$r
12561285

12571286
}
12581287

1288+
## get audit report
1289+
function Get-AuditReport ([string]$rid='0', [string]$startAt,[string]$endAt,[string]$region="all",[string]$activity) {
1290+
<#
1291+
.SYNOPSIS
1292+
Create Audit Report
1293+
.SYNTAX
1294+
Get-AuditReport $stype $objectId $title $scheduleActions $startAt $recurringDays $endAt $timezone $deleteAtEnd $newConfigName
1295+
Returns report object
1296+
.EXAMPLE
1297+
Get-Audit -rid <report Id> -startAt "2016 09 09 09 00" -endAt "2016 10 09 09 00"
1298+
#>
1299+
if ($rid -eq '0') {
1300+
$uri = "$global:url/auditing/exports"
1301+
$yy,$mm,$dd,$hr,$min = $startAt.split()
1302+
$dstart = @{
1303+
year = $yy
1304+
month = $mm
1305+
day = $dd
1306+
hour = $hr
1307+
minute = $min
1308+
}
1309+
$yy,$mm,$dd,$hr,$min = $endAt.split()
1310+
$dend = @{
1311+
year = $yy
1312+
month = $mm
1313+
day = $dd
1314+
hour = $hr
1315+
minute = $min
1316+
}
1317+
$body = @{
1318+
date_start = $dstart
1319+
date_end = $dend
1320+
activity = $activity
1321+
#region = $region
1322+
#utc = $True
1323+
notify_by_email = $False
1324+
}
1325+
#write-host (ConvertTo-Json $body)
1326+
try {
1327+
$result = Invoke-RestMethod -Uri $uri -Method POST -Body (ConvertTo-Json $body) -ContentType "application/json" -Headers $global:headers
1328+
$result | Add-member -MemberType NoteProperty -name requestResultCode -value 0
1329+
1330+
} catch {
1331+
$global:errorResponse = $_.Exception
1332+
$result = Show-RequestFailure
1333+
return $result
1334+
}
1335+
return $result
1336+
}else{
1337+
1338+
$uri = "$global:url/auditing/exports/" + $rid
1339+
1340+
try {
1341+
$result = Invoke-RestMethod -Uri $uri -Method GET -ContentType "application/json" -Headers $global:headers
1342+
$result | Add-member -MemberType NoteProperty -name requestResultCode -value 0
1343+
1344+
} catch {
1345+
$global:errorResponse = $_.Exception
1346+
$result = Show-RequestFailure
1347+
}
1348+
if ($result.ready -eq $True) {
1349+
$uri = "$global:url/auditing/exports/" + $rid + '.csv'
1350+
try {
1351+
$result = Invoke-RestMethod -Uri $uri -Method GET -ContentType "text/csv" -Headers $global:headers
1352+
$result | Add-member -MemberType NoteProperty -name requestResultCode -value 0
1353+
1354+
} catch {
1355+
$global:errorResponse = $_.Exception
1356+
$result = Show-RequestFailure
1357+
}
1358+
}
1359+
return $result
1360+
}
1361+
1362+
}
1363+
1364+
1365+
12591366
function Get-PublicIPs ([string]$configId) {
12601367
<#
12611368
.SYNOPSIS
@@ -1484,8 +1591,69 @@ function Add-UserToGroup( [string]$groupId, [string]$userId ){
14841591

14851592
}
14861593

1594+
<#
1595+
.SYNOPSIS
1596+
Get VM metadata - only works from within a VM
1597+
.SYNTAX
1598+
Get-Metadata
1599+
1600+
.EXAMPLE
1601+
$meta = get-metadata
1602+
#>
1603+
function get-metadata
1604+
{
1605+
$uri = 'http://gw/skytap'
1606+
try {
1607+
$meta = Invoke-WebRequest $uri -Method GET -ContentType 'application/json' -UseBasicParsing
1608+
$result = $meta.Content | convertfrom-json
1609+
#$myhost = $mc.name + "-" + $mc.id
1610+
#write-output $myhost
1611+
$result | Add-member -MemberType NoteProperty -name requestResultCode -value 0
1612+
} catch {
1613+
$global:errorResponse = $_.Exception
1614+
$result = Show-RequestFailure
1615+
return $result
1616+
}
1617+
return $result
1618+
}
1619+
1620+
1621+
1622+
function Send-sharedrive([string]$localFilename, [string]$remoteFilename)
1623+
{
1624+
try {
1625+
$furl = 'ftp://ftp-uswest.skytap.com/shared_drive'
1626+
$freq = [System.Net.FtpWebRequest]::Create($furl+'/'+$remoteFilename)
1627+
if ($ftpuser) {
1628+
$freq.Credentials = New-Object System.Net.NetworkCredential($ftpuser,$ftppwd)
1629+
$freq.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
1630+
$freq.UseBinary = $True
1631+
$freq.UsePassive = $True
1632+
$freq.KeepAlive = $False
1633+
$localfile = 'c:\users\skytap\'+$localFilename
1634+
$upcontent = gc -en byte $localfile
1635+
$freq.ContentLength = $upcontent.Length
1636+
$Run = $freq.GetRequestStream()
1637+
$Run.Write($upcontent, 0, $upcontent.Length)
1638+
$Run.Close()
1639+
$Run.Dispose()
1640+
return 0
1641+
} else {
1642+
write-host "FTP User not set"
1643+
return -1
1644+
}
1645+
}
1646+
catch {
1647+
return -1
1648+
}
1649+
}
1650+
# lastline
14871651
Export-ModuleMember -function * -alias *
14881652

1653+
1654+
1655+
1656+
14891657

14901658

14911659

skytap.psd1

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)