Skip to content

Commit

Permalink
Merge branch 'master' into melliott-devel-148
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapbrasser authored Jun 21, 2019
2 parents 5ce96f0 + f191bb8 commit b6da2ad
Show file tree
Hide file tree
Showing 29 changed files with 2,670 additions and 439 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Updated Invoke-RubrikWebRequest so the HTTP status code returned from the API call is displayed when verbose logging is enabled
* Updated Submit-Request to handle `Delete` API calls differently than other calls. Previously `Delete` operations did not surface any status to the user. With this change, the HTTP response code is checked to verify it matches the expected response. If so, it returns a PSObject with the HTTP code and Status = 'Success'.

## 2019-06-18

### Added [Update-RubrikVMwareVM]

* Added new `Update-RubrikVMwareVM` cmdlet to refresh a single VMware VM's metadata. This addresses issue [305](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/305)


## 2019-06-04

### Added [Resolving Issues]

* Added Export-RubrikVM cmdlet to address [Issue 239](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/239). Since the cmdlet requires IDs for both a VMware datastore and a VMware host, 2 other cmdlets were developed, Get-RubrikVMwareDatastore and Get-RubrikVMwareHost to make the whole process easier.

### Changed [Resolved issues]

* Resolved bug in New-RubrikVMDKMount, thanks @Pierre-PvF
Expand Down
70 changes: 68 additions & 2 deletions Rubrik/Private/Get-RubrikAPIData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ function Get-RubrikAPIData($endpoint) {
Success = '202'
}
}
'Export-RubrikVM' = @{
'1.0' = @{
Description = 'Export a VMware VM to an existing vSphere environment'
URI = '/api/v1/vmware/vm/snapshot/{id}/export'
Method = 'Post'
Body = @{
vmName = 'vmName'
disableNetwork = 'disableNetwork'
removeNetworkDevices = 'removeNetworkDevices'
powerOn = 'powerOn'
hostId = 'hostId'
datastoreId = 'datastoreId'
shouldRecoverTags = 'shouldRecoverTags'
keepMacAddresses = 'keepMacAddresses'
}
Query = ''
Result = ''
Filter = ''
Success = '202'
}
}
'Export-RubrikReport' = @{
'1.0' = @{
Description = 'Get the link to a CSV file for a report.'
Expand Down Expand Up @@ -621,7 +642,38 @@ function Get-RubrikAPIData($endpoint) {
}
Success = '200'
}
}
}
'Get-RubrikVMwareDatastore' = @{
'1.0' = @{
Description = 'Retrieves all datastores known to the Rubrik cluster'
URI = '/api/internal/vmware/datastore'
Method = 'Get'
Body = ''
Query = @{}
Result = 'data'
Filter = @{
'Name' = 'name'
'dataStoreType' = 'dataStoreType'
}
Success = '200'
}
}
'Get-RubrikVMwareHost' = @{
'1.0' = @{
Description = 'Retrieves all ESXi hosts known to the Rubrik cluster'
URI = '/api/v1/vmware/host'
Method = 'Get'
Body = ''
Query = @{
primary_cluster_id = 'primary_cluster_id'
}
Result = 'data'
Filter = @{
'Name' = 'name'
}
Success = '200'
}
}
'Get-RubrikVersion' = @{
'1.0' = @{
Description = 'Retrieve public information about the Rubrik cluster'
Expand Down Expand Up @@ -1736,7 +1788,21 @@ function Get-RubrikAPIData($endpoint) {
Filter = ''
Success = '202'
}
}
}
'Update-RubrikVMwareVM' = @{
'1.0' = @{
Description = 'Refresh the metadata for the specified VMware VM'
URI = '/api/internal/vmware/vcenter/{id}/refresh_vm'
Method = 'Post'
Body = @{
vmMoid = 'vmMoid'
}
Query = ''
Result = ''
Filter = ''
Success = '204'
}
}

} # End of API

Expand Down
92 changes: 92 additions & 0 deletions Rubrik/Public/Export-RubrikVM.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#Requires -Version 3
function Export-RubrikVM
{
<#
.SYNOPSIS
Exports a given snapshot for a VMware VM
.DESCRIPTION
The Export-RubrikVM cmdlet is used to restore a snapshot from a protected VM, copying all data to a given datastore and running the VM in an existing vSphere environment.
.NOTES
Written by Mike Preston for community usage
Twitter: @mwpreston
GitHub: mwpreston
.LINK
http://rubrikinc.github.io/rubrik-sdk-for-powershell/reference/Export-RubrikVM.html
.EXAMPLE
Export-RubrikVM -id '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -HostId (Get-RubrikVMwareHost -name esxi01 -PrimaryClusterID local).id -DatastoreId (Get-RubrikVMwareDatastore -name vSAN).id
This will mount the snapshot with an id of 7acdf6cd-2c9f-4661-bd29-b67d86ace70b to the specified host and datastore
.EXAMPLE
Get-RubrikVM 'server01' -PrimaryClusterID local | Get-RubrikSnapshot | Sort-Object -Property Date -Descending | Select -First 1 | Export-RubrikVM -HostId (Get-RubrikVMwareHost -name esxi01 -PrimaryClusterID local).id -DatastoreId (Get-RubrikVMwareDatastore -name vSAN).id
This will retreive the latest snapshot from the given VM 'server01' and export to the specified host and datastore.
#>

[CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact = 'High')]
Param(
# Rubrik id of the snapshot to export
[Parameter(Mandatory = $true,ValueFromPipelineByPropertyName = $true)]
[String]$id,
# Rubrik id of the vSphere datastore to store exported VM. (Use "Invoke-RubrikRESTCall -Endpoint 'vmware/datastore' -Method 'GET' -api 'internal'" to retrieve a list of available VMware datastores)
[Parameter(Mandatory = $true)]
[String]$DatastoreId,
# ID of host for the export to use (Use "Invoke-RubrikRESTCall -Endpoint 'vmware/host' -Method 'GET' -api '1'" to retrieve a list of available VMware hosts.)
[Parameter(Mandatory = $true)]
[String]$HostID,
# Name of the exported VM
[String]$VMName,
# Whether the network should be disabled upon restoration. This should be set true to avoid ip conflict if source VM still exists.
[Bool]$DisableNetwork,
# Whether to remove network interfaces from the restored virtual machine. Default is false.
[Bool]$RemoveNetworkDevices,
# Whether to assign MAC addresses from source virtual machine to exported virtual machine. Default is false.
[Bool]$KeepMACAddresses,
# Whether the newly restored virtual machine is unregistered from vCenter. Default is false.
[Bool]$UnregisterVM,
# Whether the VM should be powered on after restoration. Default is true.
[Bool]$PowerOn,
# Whether to recover vSphere tags
[Alias('shouldRecoverTags')]
[Bool]$RecoverTags,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
# API version
[String]$api = $global:RubrikConnection.api
)

Begin {

# The Begin section is used to perform one-time loads of data necessary to carry out the function's purpose
# If a command needs to be run with each iteration or pipeline input, place it in the Process section

# Check to ensure that a session to the Rubrik cluster exists and load the needed header data for authentication
Test-RubrikConnection

# API data references the name of the function
# For convenience, that name is saved here to $function
$function = $MyInvocation.MyCommand.Name

# Retrieve all of the URI, method, body, query, result, filter, and success details for the API endpoint
Write-Verbose -Message "Gather API Data for $function"
$resources = Get-RubrikAPIData -endpoint $function
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

}

Process {

$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result

return $result

} # End of process
} # End of function
78 changes: 78 additions & 0 deletions Rubrik/Public/Get-RubrikVMwareDatastore.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#Requires -Version 3
function Get-RubrikVMwareDatastore
{
<#
.SYNOPSIS
Connects to Rubrik and retrieves a list of VMware datastores
.DESCRIPTION
The Get-RubrikVMwareDatastore cmdlet will retrieve VMware datastores known to an authenticated Rubrik cluster.
.NOTES
Written by Mike Preston for community usage
Twitter: @mwpreston
GitHub: mwpreston
.LINK
http://rubrikinc.github.io/rubrik-sdk-for-powershell/reference/Get-RubrikVMwareDatastore.html
.EXAMPLE
Get-RubrikVMwareDatastore
This will return a listing of all of the datastores known to a connected Rubrik cluster
.EXAMPLE
Get-RubrikVMwareDatastore -Name 'vSAN'
This will return a listing of all of the datastores named 'vSAN' known to a connected Rubrik cluster
.EXAMPLE
Get-RubrikVMwareDatastore -DatastoreType 'NFS'
This will return a listing of all of the NFS datastores known to a connected Rubrik cluster
#>

[CmdletBinding()]
Param(
# Datastore Name
[String]$Name,
# Filter Datastore type
[ValidateSet('VMFS', 'NFS','vSAN')]
[String]$DatastoreType,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
# API version
[ValidateNotNullorEmpty()]
[String]$api = $global:RubrikConnection.api
)

Begin {

# The Begin section is used to perform one-time loads of data necessary to carry out the function's purpose
# If a command needs to be run with each iteration or pipeline input, place it in the Process section

# Check to ensure that a session to the Rubrik cluster exists and load the needed header data for authentication
Test-RubrikConnection

# API data references the name of the function
# For convenience, that name is saved here to $function
$function = $MyInvocation.MyCommand.Name

# Retrieve all of the URI, method, body, query, result, filter, and success details for the API endpoint
Write-Verbose -Message "Gather API Data for $function"
$resources = Get-RubrikAPIData -endpoint $function
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

}

Process {

$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result

return $result

} # End of process
} # End of function
77 changes: 77 additions & 0 deletions Rubrik/Public/Get-RubrikVMwareHost.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#Requires -Version 3
function Get-RubrikVMwareHost
{
<#
.SYNOPSIS
Connects to Rubrik and retrieves a list of ESXi hosts registered
.DESCRIPTION
The Get-RubrikVMwareHost cmdlet will retrieve all of the registered ESXi hosts within the authenticated Rubrik cluster.
.NOTES
Written by Mike Preston for community usage
Twitter: @mwpreston
GitHub: mwpreston
.LINK
http://rubrikinc.github.io/rubrik-sdk-for-powershell/reference/Get-RubrikVMwareHost.html
.EXAMPLE
Get-RubrikVMwareHost
This will return a listing of all of the ESXi hosts known to the connected Rubrik cluster
Get-RubrikVMwareHost -PrimarClusterId local
This will return a listing of all of the ESXi hosts whose primary cluster is that of the connected Rubrik cluster.
.EXAMPLE
Get-RubrikVMwareHost -Name 'esxi01'
This will return a listing of all of the ESXi hosts named 'esxi01' registered with the connected Rubrik cluster
#>

[CmdletBinding()]
Param(
# ESXi Host Name
[String]$Name,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
# Filter the summary information based on the primarycluster_id of the primary Rubrik cluster. Use 'local' as the primary_cluster_id of the Rubrik cluster that is hosting the current REST API session.
[Alias('primary_cluster_id')]
[String]$PrimaryClusterID,
# API version
[ValidateNotNullorEmpty()]
[String]$api = $global:RubrikConnection.api
)

Begin {

# The Begin section is used to perform one-time loads of data necessary to carry out the function's purpose
# If a command needs to be run with each iteration or pipeline input, place it in the Process section

# Check to ensure that a session to the Rubrik cluster exists and load the needed header data for authentication
Test-RubrikConnection

# API data references the name of the function
# For convenience, that name is saved here to $function
$function = $MyInvocation.MyCommand.Name

# Retrieve all of the URI, method, body, query, result, filter, and success details for the API endpoint
Write-Verbose -Message "Gather API Data for $function"
$resources = Get-RubrikAPIData -endpoint $function
Write-Verbose -Message "Load API data for $($resources.Function)"
Write-Verbose -Message "Description: $($resources.Description)"

}

Process {

$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
$body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values)
$result = Submit-Request -uri $uri -header $Header -method $($resources.Method) -body $body
$result = Test-ReturnFormat -api $api -result $result -location $resources.Result
$result = Test-FilterObject -filter ($resources.Filter) -result $result

return $result

} # End of process
} # End of function
Loading

0 comments on commit b6da2ad

Please sign in to comment.