vmware-archive / powernsx

PowerShell module that abstracts the VMware NSX-v API to a set of easily used PowerShell functions
173 stars 89 forks source link

Move ESG from one NSX to another #527

Open inetman opened 6 years ago

inetman commented 6 years ago

Hello!

I want to migrate ESG with all configuration from one NSX Manager to another NSX Manager and cannot do it. I tried use as you can see commands below:

# export from one vCenter (vCSA-1)
Get-NsxEdge esg1 | Export-NsxObject C:\Temp\esg1.xml

# import to another vCenter (vCSA-2)
Import-NsxObject C:\Temp\esg1.xml | Copy-NsxEdge

And I get follow error:

Invoke-NsxRestMethod : The NSX API response received indicates a failure. 404 : Not Found : Response Body: <?xml versio
n="1.0" encoding="UTF-8"?>
<error><details>The requested object : edge-10 could not be found. Object identifiers are case sensitive.</details><err
orCode>202</errorCode><moduleName>core-services</moduleName></error>
C:\Users\r.volodin\Documents\WindowsPowerShell\Modules\PowerNSX\3.0.1110\PowerNSX.psm1:4031 знак:13
+             throw $ErrorString
+             ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Invoke-NsxRestM...leName></error>:String) [], RuntimeException
    + FullyQualifiedErrorId : Invoke-NsxRestMethod : The NSX API response received indicates a failure. 404 : Not Foun
   d : Response Body: <?xml version="1.0" encoding="UTF-8"?>
    <error><details>The requested object : edge-10 could not be found. Object identifiers are case sensitive.</details
   ><errorCode>202</errorCode><moduleName>core-services</moduleName></error>

Maybe you can offer any way to migrate ESG beetwen NSX Managers?

dcoghlan commented 6 years ago

Hi @inetman

The original use case for Copy-NsxEdge was to do it within the same NSX Manager, and as such, the scenario your trying is not one that has been tested.

In saying this, if you could turn on debug logging with the following command: $DebugPreference="Continue"

Run the commands again. and then post the output, we might be able to see where its failing for you

Regards Dale

chachet commented 5 years ago

I have a similar situation and I'm running into the same thing. In my case, rather than trying to pass XML into Copy-NsxEdge, I'm creating an edge object while connected to the first NSX Manager, disconnecting, connecting to the second NSX Manager, and passing the edge object into Copy-NsxEdge. Looking at the debug output, Copy-NsxEdge is running API calls against the second NSX Manager (since I'm currently connected to it) to pull information for the source edge specified by the edge object that I created, and is failing since the edge does not exist in the second NSX Manager.

$PrimaryEdgeInfo | Copy-NsxEdge -Name $DREdge -Interface $IntInternet,$IntTransit

DEBUG: Copy-NsxEdge : Invoked with Default ParameterSet
DEBUG: Copy-NsxEdge : Removing appliance node from Edge XML with moref vm-24664
DEBUG: Copy-NsxEdge : Creating new primary appliance node with ResourcePool moref: domain-c9, Datastore moref: datastore-38, Folder moref: group-v27061.
WARNING: IPSec PSK for site site set to P0WVH7z5.  Please update manually as required.
WARNING: IPSec PSK for site global set to L1b3gBOj.  Please update manually as required.
DEBUG: Invoke-NsxRestMethod : ParameterSetName : ConnectionObj
DEBUG: Invoke-NsxRestMethod : Method: get, URI: https://10.11.1.150:443/api/2.0/services/truststore/certificate/scope/edge-47, URIPrefix: , Body: 

Invoke-NsxRestMethod : The NSX API response received indicates a failure. 404 : Not Found : Response Body: <?xml version="1.0" encoding="UTF-8"?>
<error><errorCode>202</errorCode><details>The requested object : edge-47 could not be found. Object identifiers are case sensitive.</details><moduleName>core-services</moduleName></error>
At C:\Users\clay.thomas\Documents\WindowsPowerShell\Modules\PowerNSX\3.0.1118\PowerNSX.psm1:4037 char:13
+             throw $ErrorString
+             ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Invoke-NsxRestM...leName></error>:String) [], RuntimeException
    + FullyQualifiedErrorId : Invoke-NsxRestMethod : The NSX API response received indicates a failure. 404 : Not Found : Response Body: <?xml version="1.0" encoding="UTF-8"?>
<error><errorCode>202</errorCode><details>The requested object : edge-47 could not be found. Object identifiers are case sensitive.</details><moduleName>core-services</moduleName></error>

If there was a way to have Copy-NsxEdge (or another cmdlet) validate the source edge data passed to it via an object or XML, then use that without having to pull source edge info from the NSX Manager, that would likely solve this issue. However, I'm sure it's much easier said than done, and my case is probably a limited edge case.