VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

vcsa-update_powercle

Hi Luc,

can you please review the following function this is to get vcsa patch information .

i want to add extra logic to update vcsa also if state is not up-to-date .

can you suggest if it should be done thorough different function or it can be included in the same

function get-vcsaupdate{

   

 

    [cmdletbinding()]

    param (

        [parameter(mandatory = $true,

            valuefrompipeline = $true,

            valuefrompipelinebypropertyname = $true,

            helpmessage = "cisserver name")]

        [psobject]$cisserver,

        [parameter(mandatory = $true,

            helpmessage = "administrator@regiona.local cred ")]

        [pscredential]$cred

           

    )

 

   

    

        try {

            connect-cisserver -server $cisserver -Credential $cred

            $update=get-cisservice com.vmware.appliance.update

            $vcsaname=$global:DefaultCisServers.name

            $state=$update.get().state

            $version=$update.get().version

            $update_summary=[pscUSTOMoBJECT]@{

                vcsaname=$vcsaname

                state=$state

                version=$version

            }

            $update_summary

        } catch {

            Write-error $Error[0]

        }

    }

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is some documentation available on the VCSA update process in Updating the vCenter Server Appliance.

The difference is that this document uses the Uri for the REST calls (which you could do with for example Invoke-RestMethod ir Invoke-WebRequest).

If you use the CIS services, the calls are different (the Name you provide to Get-CisService), but the calls in the end are the same.

What is with the REST documentation an Action field in the Uri, becomes a method on the CIS service (get, list,install...)

The following blog post named PowerCLI – Update VCSA gives a good example of the process.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
17 Replies
LucD
Leadership
Leadership
Jump to solution

Some changes.
The important one is to capture the CIS server connection, this to avoid issues when there is already a connection open.

I would do a separate function for starting the update.

The main idea is to keep the functions simple and only perform one task.

I would go for a separate Invoke-VcsaUpdate function or something along those lines.

function Get-VcsaUpdate

{

    [cmdletbinding()]

    param (

        [parameter(mandatory = $true,

            valuefrompipeline = $true,

            valuefrompipelinebypropertyname = $true,

            helpmessage = "cisserver name")]

        [psobject]$CisServer,

        [parameter(mandatory = $true,

            helpmessage = "administrator@regiona.local cred ")]

        [pscredential]$Credential

    )


    try

    {

        $srv = Connect-CisServer -server $cisserver -Credential $cred


        $update = Get-CisService com.vmware.appliance.update -Server $srv


        [PSCustomObject]@{

            vcsaname = $srv.name

            state = $update.get().state

            version = $update.get().version

        }


        Disconnect-CisServer -Server $srv -Confirm:$false

    }

    catch

    {

        Write-Error $Error[0]

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

Thanks Luc,

the below statement is also been strongly pronounced in power shell community .

The main idea is to keep the functions simple and only perform one task.

i many a times think to include the action logic using if construct(vcsa-update in this discussion) along with the get logic(finding vcsa update).

will it differ tthe basic design construct of functions or powershell.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you mean that you could call the Get-VcsaUpdate function inside the Invoke-VcsaUpdate function, yes, you could do that.

But to be more 'PowerShell' like, I would prefer to do the logic outside the functions.

Something like

if(Get-VcsaUpdate){

    Invoke-VcsaUpdate

}

That way the logic is in your main script and not hidden inside a function.
Which makes it, imho, easier for others to discover what your script is doing.


Another advantage is that single action functions make it much easier to write Pester tests.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i am going to check this but right now i m searching the task for vcsa update .

iam serching under manged objects in vdc to find something related with vcsa  but could not find anything

https://vdc-repo.vmware.com/vmwb-repository/dcr-public/790263bc-bd30-48f1-af12-ed36055d718b/e5f17bfc...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Use the API Explorer.

It's stage and install or stage-and-install you want.

This is from a VCSA 6.7

pastedImage_0.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i am trying to put in powershell functions something in the form of task .

and to create that task i used to refer vdc...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

These appliance methods are only available through the REST API (just like the VCSA backup for example).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

below is what i m using and this is rest api only .however i dont see any example help .this is where i get stuck everytime ...

also am i not supposed to refer vdc repo to form find the method and corresponding arguments.

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What you call the 'vdc repo' is in fact the VMware vSphere API Reference Documentation which is part of the VMware vSphere Web Services SDK

This is all based on SOAP, not REST.

For the REST API you consult the vSphere Automation API Reference.

Including the appliance.update.pending part


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks for the clarification .

1:sorry to ask again but the below in orange is also rest api .is that correct??

    $update = Get-CisService com.vmware.appliance.update -Server $srv

2:

For the REST API you consult the vSphere Automation API Reference.

Including the appliance.update.pending part

i am not sure how to put this in powershell function the way i used get function at the start of this discussion ???

0 Kudos
LucD
Leadership
Leadership
Jump to solution

1. Yes

2. The same way, you call Get-CisService.

You assign to $vcsaVersion the version that can be installed

$upd = Get-CisService -Name 'com.vmware.appliance.update.pending'


# 2 calls


$upd.stage($vcsaVersion)

$upd.install($vcsaVersion)


# or 1


$upd.stage_and_install($vcsaVersion)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is some documentation available on the VCSA update process in Updating the vCenter Server Appliance.

The difference is that this document uses the Uri for the REST calls (which you could do with for example Invoke-RestMethod ir Invoke-WebRequest).

If you use the CIS services, the calls are different (the Name you provide to Get-CisService), but the calls in the end are the same.

What is with the REST documentation an Action field in the Uri, becomes a method on the CIS service (get, list,install...)

The following blog post named PowerCLI – Update VCSA gives a good example of the process.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks Luc ,

it is very helpful

till now iam able to do this on lab

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is only missing the install and then a loop with get to wait till it returns UP_TO_DATE or INSTALL_FAILED.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i missed that part in screenshot but install is also done .

also iam using following to check

$update=get-cisservice com.vmware.appliance.update

$update.get()

0 Kudos
LucD
Leadership
Leadership
Jump to solution

So what is missing?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

nothing is missing .that has worked thnaks.

0 Kudos