Jump to content
Welcome to our new Citrix community!
  • 0

Creating an ISCSI SR


Brian Hesdorfer1709159049

Question

Hello all,

 

I'm working on automating our DR testing. I have a clone of one of our main data volumes (normally used via ISCSI) and an offsite server. We're on 7.1 CU2.

 

I'm trying to automate the process of adding this SR to the server.  I have the target IP and IQN (and can use them through XenCenter with no trouble), but I can't figure out how to get it to work through the powershell SDK.

 

The error I get is:

 

Quote

New-XenSR : The request is missing the target parameter
At line:1 char:1
+ New-XenSR -Hashtable $sr_table
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-XenSR], Failure
    + FullyQualifiedErrorId : XenAPI.Failure,Citrix.XenServer.Commands.NewXenSRCommand

 

I've tried doing it a couple ways. First, I tried to create an sm_config hashtable (based on the "configuration" property of 'Get-XenSM') with the target/IQN and added it to an sr_config table with my other settings.

 

Here's a redacted/reduced version:

# Build SM config
$sm_config = @{}
$sm_config.add("target","192.168.x.x")
$sm_config.add("targetIQN","<iqn>")


# Build SR config
$sr_table = @{}
$sr_table.Add("sm_config",$sm_config)
$sr_table.Add("name_label","Powershell SR")
$sr_table.Add("type","lvmoiscsi")
$sr_table.Add("shared",$true)

# Attach SR
New-XenSR -Hashtable $sr_table


I Also tried doing it through the single command, but that gave me the same error:
 

New-XenSR -NameLabel "Powershell SR" -Type "lvmoiscsi" -Shared $true -SmConfig $sm_config

 

I'm pretty sure the issue is that I haven't put the "SmConfig" hashtable together correctly, but I haven't been able to find any real documentation on any of the SDK outside of the small number of included examples. I've attached a poster I found online with the commands broken up, but that's about it.

 

I looked through the regular .net SDK, and while that helped a bit, I'm still stuck.

 

There's also a chance I'm getting something else wrong (maybe the type, or even the command I'm using), but it's hard to tell.

 

Does anyone have any suggestions, or anywhere they know of with more documentation/examples?

 

Any help is very appreciated.

 

Thanks!

Citrix XenServer 7.1 SDK for PowerShell - Poster v1.1.pdf

Link to comment

8 answers to this question

Recommended Posts

  • 0

To re-attach you need to work along the following lines:

$hostRef = (Get-XenHost).opaque_ref
$deviceConfig = @{ "target"="192.168.x.x"; "port"="xxxx"; "targetIQN"="xxxxxx"; "SCSIid"="xxxxx" }
$result = Invoke-XenSR -XenAction Probe -XenHost $hostRef -Type "lvmoiscsi" -DeviceConfig $deviceConfig -Ref OpaqueRef:NULL -PassThru
$doc=[xml]$result
$sr = Invoke-XenSR -XenAction Introduce -UuidParam $doc.SRlist.SR.UUID -NameLabel mySR -Type "lvmoiscsi" -Shared $true -Ref OpaqueRef:NULL -PassThru
$pbd = New-XenPBD -XenHost $hostRef -SR $sr -DeviceConfig $deviceConfig -PassThru
Invoke-xenPBD -XenAction Plug -PBD $pbd

Now, I'm not 100% sure how your test goes about it, but if your SR supports replication and the reattach is part of a DR task, you can do:

New-XenDRTask -Type "lvmoiscsi" -DeviceConfig $deviceConfig -PassThru

On a general note, the powershell cmdlets wrap the C# SDK used by XenCenter, which means most stuff XenCenter does can be achieved with powershell, but sometimes it's tricky to find the right cmdlets to use. It may be helpful to look at how XenCenter (https://github.com/xenserver/xenadmin) does things and try to replicate it with powershell.

  • Like 1
Link to comment
  • 0

I'm not 100% sure what you are trying to accomplish, but will note that any given SR can only be associated with one pool, ever. If I understand your intentions correctly regarding SR, you cannot make it available to another. The only way you could do this is to save the VM metadata to that SR, reattach i fro the original pool. attach it to the new pool and restore all the metadata.

 

-=Tobias

Link to comment
  • 0
On 8/17/2019 at 10:59 AM, Tobias Kreidl said:

I'm not 100% sure what you are trying to accomplish, but will note that any given SR can only be associated with one pool, ever. If I understand your intentions correctly regarding SR, you cannot make it available to another. The only way you could do this is to save the VM metadata to that SR, reattach i fro the original pool. attach it to the new pool and restore all the metadata.

 

-=Tobias

 

Hi Tobias and Konstantina,

 

Sorry, I didn't explain it well.

 

The NAS we use replicates our data offsite. A few times a year, we test to make sure the offsite data is healthy/usable.

 

Right now the entire testing procedure is done manually. I'm attempting to automate the process to speed it along, and perhaps include more frequent automated tests. There are 4 big steps to this:

 

  1. Make a copy of our replicated data available on the offsite unit. (I’m almost finished automating this.)
  2. Set the SR up in XenCenter.
  3. Start up the VMs to verify they can boot properly. (This is almost automated.)
  4. Other tests within certain VMs. (These aren’t well defined yet, so there’s no automation.)

 

What I’m looking for is automating step 2. I have the serial, the IQN, and the target IP/port. My hope was to get around manually using the “New SR” wizard. That said, I’m pretty sure I’ve put more time into researching this step than we’d ever save. Obligatory XKCD: https://xkcd.com/1205/

 

 

23 hours ago, Konstantina Chremmou said:

The target/IQN should be in the DeviceConfig. Try this:


New-XenSR -NameLabel "mySR" -XenHost "hostname" -Type "lvmoiscsi" -Shared $true `
  -DeviceConfig @{ "target"="192.168.x.x"; "port"="xxxx"; "targetIQN"="xxxxxx"; "SCSIid"="xxxxx" }  

 

 

This command stalled out and failed until I put a "2" in front of the iSCSI ID, an idea that came to mind when seeing 2s prepended to all of our other IDs.

 

I noticed that the command formats the SR. Is there a way to have it reattach with the existing data instead? Maybe that's another command instead, or an extra option?

 

For example, the "New SR" wizard offers me the choice when it detects existing data:

 

XenCenterMain_2019-08-19_10-22-49.thumb.png.1e0a3b343c1cf5996c6ddd3695b2d64d.png

 

Thank you both for your time and insights!

 

 

 

 

 

Edited by hesdorferb
Bad copy/pasting images.
Link to comment
  • 0
12 hours ago, Konstantina Chremmou said:

...

 

This worked perfectly! I still have to prepend my SCSI id values with a 2, but that's easy enough.

 

I have a bit of experience in c# .net, and I've poked around that repository before, but as you've said, it's not always easy to find the right ones. I may shift in that direction since I'm pretty familiar with how to do most things in XenCenter.

 

Thank you both for your time and help!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...