New feature modify vRa All services icons #87

Closed
laurentmas opened this Issue Dec 12, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@laurentmas

laurentmas commented Dec 12, 2016

Hi,

Since vRa 7.1 we can update All services icons using vRa api.

It will be nice if you can add this feature on PowervRa.

Here the description how to do it : http://pubs.vmware.com/vrealize-automation-71/index.jsp?topic=%2Fcom.vmware.vrealize.automation.doc%2FGUID-EEE2C14E-6C1B-4113-9001-6B2B6DB66C48.html&resultof=%22Modify%22%20%22modifi%22%20%22all%22%20%22services%22%20%22servic%22%20%22icon%22%20

Regards

@chelnak

This comment has been minimized.

Show comment
Hide comment
@chelnak

chelnak Dec 12, 2016

Contributor

Great idea. I can see this being part of something like Set-vRAServiceIcon.

We'll take a look.

Contributor

chelnak commented Dec 12, 2016

Great idea. I can see this being part of something like Set-vRAServiceIcon.

We'll take a look.

@chelnak chelnak added this to the Future milestone Dec 12, 2016

@chelnak chelnak added the enhancement label Dec 12, 2016

@laurentmas

This comment has been minimized.

Show comment
Hide comment
@laurentmas

laurentmas Dec 12, 2016

here a sample code i wrote on this subject

		#region Bypass untrusted certificates
		add-type -TypeDefinition  @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
            public bool CheckValidationResult(
                ServicePoint srvPoint, X509Certificate certificate,
                WebRequest request, int certificateProblem) {
                return true;
            }
        }

"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#endregion Bypass untrusted certificates

		try
		{
			$Response = $null
			$ResponseNewIcon = $null
							
			# --- Create Invoke-RestMethod Parameters
			$JSON = @"
		    {
		        "username":"$($username)",
		        "password":"$($password)",
		        "tenant":"$($tenant)"
		    }

"@
$Method = "POST"
$URI = "https://$($hostname)/identity/api/tokens"
$Headers = @{

				"Accept" = "application/json";
				"Content-Type" = "application/json";
			}
			$Body = $JSON
			
			# --- Run vRA REST Request
			$Response = Invoke-RestMethod -Method $Method -Uri $URI -Headers $Headers -Body $Body
			
			if ($Response.id -ne $null)
			{
				$Headers = @{
					
					"Accept" = "application/json";
					"Content-Type" = "application/json";
					"Authorization"= "Bearer $($($Response.id))"
				}
				
				#check if we need to revert to default icon
				if ($defaultIcon -ne $true)
				{
					# convert image into base 64
					$base64Icon = [convert]::ToBase64String((get-content $newxIcon -encoding byte))
					
					$Method = "POST"
					
					$JSON = @"
				    {
						"id":"cafe_default_icon_genericAllServices",
						"fileName":"allServiceIcon",
						"contentType":"image/png",
						"image":"$($base64Icon)"
				    }

"@
$URI = "https://$($hostname)/catalog-service/api/icons"
$Body = $JSON

					# --- Run vRA REST Request
					$ResponseNewIcon = Invoke-RestMethod -Method $Method -Uri $URI -Headers $Headers -Body $Body -ErrorAction Stop
				}
				else
				{
					$Method = "DELETE"
					$URI = "https://$($hostname)/catalog-service/api/icons/cafe_default_icon_genericAllServices"
					
					# --- Run vRA REST Request
					$ResponseNewIcon = Invoke-RestMethod -Method $Method -Uri $URI -Headers $Headers -ErrorAction Stop
				}
				
				
			}
			
			
		}
		catch [Exception]{
			
			throw $_.Exception.Message
			
		}

here a sample code i wrote on this subject

		#region Bypass untrusted certificates
		add-type -TypeDefinition  @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
            public bool CheckValidationResult(
                ServicePoint srvPoint, X509Certificate certificate,
                WebRequest request, int certificateProblem) {
                return true;
            }
        }

"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#endregion Bypass untrusted certificates

		try
		{
			$Response = $null
			$ResponseNewIcon = $null
							
			# --- Create Invoke-RestMethod Parameters
			$JSON = @"
		    {
		        "username":"$($username)",
		        "password":"$($password)",
		        "tenant":"$($tenant)"
		    }

"@
$Method = "POST"
$URI = "https://$($hostname)/identity/api/tokens"
$Headers = @{

				"Accept" = "application/json";
				"Content-Type" = "application/json";
			}
			$Body = $JSON
			
			# --- Run vRA REST Request
			$Response = Invoke-RestMethod -Method $Method -Uri $URI -Headers $Headers -Body $Body
			
			if ($Response.id -ne $null)
			{
				$Headers = @{
					
					"Accept" = "application/json";
					"Content-Type" = "application/json";
					"Authorization"= "Bearer $($($Response.id))"
				}
				
				#check if we need to revert to default icon
				if ($defaultIcon -ne $true)
				{
					# convert image into base 64
					$base64Icon = [convert]::ToBase64String((get-content $newxIcon -encoding byte))
					
					$Method = "POST"
					
					$JSON = @"
				    {
						"id":"cafe_default_icon_genericAllServices",
						"fileName":"allServiceIcon",
						"contentType":"image/png",
						"image":"$($base64Icon)"
				    }

"@
$URI = "https://$($hostname)/catalog-service/api/icons"
$Body = $JSON

					# --- Run vRA REST Request
					$ResponseNewIcon = Invoke-RestMethod -Method $Method -Uri $URI -Headers $Headers -Body $Body -ErrorAction Stop
				}
				else
				{
					$Method = "DELETE"
					$URI = "https://$($hostname)/catalog-service/api/icons/cafe_default_icon_genericAllServices"
					
					# --- Run vRA REST Request
					$ResponseNewIcon = Invoke-RestMethod -Method $Method -Uri $URI -Headers $Headers -ErrorAction Stop
				}
				
				
			}
			
			
		}
		catch [Exception]{
			
			throw $_.Exception.Message
			
		}
@jonathanmedd

This comment has been minimized.

Show comment
Hide comment
@jonathanmedd

jonathanmedd Mar 27, 2017

Contributor

I'll be doing the following

New functions: Get-vRAServiceIcon, Import-vRAServiceIcon, Export-vRAServiceIcon, Remove-vRAServiceIcon
Updated functions: Set-vRAService and New-vRAService with IconId parameter

Contributor

jonathanmedd commented Mar 27, 2017

I'll be doing the following

New functions: Get-vRAServiceIcon, Import-vRAServiceIcon, Export-vRAServiceIcon, Remove-vRAServiceIcon
Updated functions: Set-vRAService and New-vRAService with IconId parameter

@jonathanmedd

This comment has been minimized.

Show comment
Hide comment
@jonathanmedd

jonathanmedd Apr 3, 2017

Contributor

Closed via the above pull request

Contributor

jonathanmedd commented Apr 3, 2017

Closed via the above pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment