Page 1 of 1

Create New Device Powershell

Posted: Thu Nov 30, 2017 4:08 pm
by chrisguk
Hi I am trying to create new devices with the script below but I get getting the errors:

Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
200 Failed: operation cannot be completed.. "
Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
200 Failed: There is not enough space on the disk.. "
Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
200 Failed: operation cannot be completed.. "

Code: Select all

	Import-Module StarWindX
	
$storage = 'FS1'
$storage2 = 'FS2'
	try
	{
		$server = New-SWServer -host $storage -port 3261 -user root -password starwind
		
		$server.Connect()
		
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "CSV1"
		$firstNode.Size = 20000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "csv1"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.10:3260"
		$firstNode.HBInterface = "#p2=10.32.35.80:3260"
		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "CSV1"
		$secondNode.Size = 20000
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "csv1"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.20:3260"
		$secondNode.HBInterface = "#p1=10.32.35.81:3260"
		$secondNode.ALUAOptimized = $true
		
		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}
	
	
	try
	{
		$server = New-SWServer -host $storage -port 3261 -user root -password starwind
		$server.Connect()
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "CSV2"
		$firstNode.Size = 20000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "csv2"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.10:3260"
		$firstNode.HBInterface = "#p2=10.32.35.80:3260"
		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "CSV2"
		$secondNode.Size = 20000
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "csv2"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.20:3260"
		$secondNode.HBInterface = "#p1=10.32.35.81:3260"
		$secondNode.ALUAOptimized = $true

		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}
	
	try
	{
		$server = New-SWServer -host $storage -port 3261 -user root -password starwind
		$server.Connect()
		
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "witness"
		$firstNode.Size = 10000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "witness"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.10:3260"
	
		$firstNode.HBInterface = "#p2=10.32.35.80:3260"

		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		$firstNode.SectorSize = 512
		$firstNode.SerialID = ""
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "witness"
		$secondNode.Size = 10000
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "witness"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.10:3260"
		$secondNode.HBInterface = "#p1=10.32.35.81:3260"
		$secondNode.ALUAOptimized = $true
		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}
	
	$server.Disconnect()
Can you please offer some advice?

Re: Create New Device Powershell

Posted: Thu Nov 30, 2017 5:11 pm
by Boris (staff)
In your case, the interfaces stated in the italics block are the ones on node 1, are they not? The matter is that if there is the key "p2" before the interface, the IP address of the partner node should follow, but not the local node IP. If it is "p1", then node 1 interfaces are there.

$firstNode.SyncInterface = "#p2=10.32.10.10:3260"
$firstNode.HBInterface = "#p2=10.32.35.80:3260"


Check that the IPs are from partner nodes - it should be:

$firstNode.SyncInterface = "#p2=Sync_IP_on_node_2"
$firstNode.HBInterface = "#p2=iSCSI_IP_on_node_2"


Feel free to amend the script accordingly (for all devices and both nodes) and let me know the outcome.

Re: Create New Device Powershell

Posted: Fri Dec 01, 2017 10:52 am
by chrisguk
So I made the change and I still get this error - Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
200 Failed: operation cannot be completed..

Code: Select all

Import-Module StarWindX

try
	{
		$server = New-SWServer -host $storage -port 3261 -user root -password starwind
		
		$server.Connect()
		
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "CSV1"
		$firstNode.Size = 1000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "csv1"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.20:3260"
		$firstNode.HBInterface = "#p2=10.32.35.81:3260"
		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "CSV1"
		$secondNode.Size = 1000
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "csv1"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.10:3260"
		$secondNode.HBInterface = "#p1=10.32.35.80:3260"
		$secondNode.ALUAOptimized = $true
		
		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}

Re: Create New Device Powershell

Posted: Fri Dec 01, 2017 11:22 am
by Boris (staff)
First of all, your latest script is missing variables declaration at the very top:

Code: Select all

$storage = 'FS1'
$storage2 = 'FS2'
This may be one of the reasons.
Next, try connecting not to "$storage", but to 127.0.0.1 in case you execute the script on one of the HA nodes.

Code: Select all

$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()

Re: Create New Device Powershell

Posted: Fri Dec 01, 2017 5:25 pm
by chrisguk
okay now I get this error. By the way it creates the first images on FS2 not FS1:

Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
104 Target name 'iqn.2008-08.com.starwindsoftware:FS2-csvone' is invalid according to RFC 3722!. "
Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
104 Target name 'iqn.2008-08.com.starwindsoftware:FS2-csvtwo' is invalid according to RFC 3722!. "
Exception Exception calling "CreateDevice" with "4" argument(s): "Error:
104 Target name 'iqn.2008-08.com.starwindsoftware:FS2-witness' is invalid according to RFC 3722!. "

Updated script:

Code: Select all

	Import-Module StarWindX
	$NODE1IPISCSI = "10.32.35.82"
$NODE2IPISCSI = "10.32.35.83"
$FS1SYNCIP = "10.32.10.10"
$FS2SYNCIP = "10.32.10.20"
$FS1HBIP = "10.32.35.80"
$FS2HBIP = "10.32.35.81"
$servers = 'winnode1', 'winnode2'
$storage = 'FS1'
$storage2 = 'FS2'
	try
	{
		$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
		
		$server.Connect()
		
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "csvone"
		$firstNode.Size = 10000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "csvone"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.20:3260"
		$firstNode.HBInterface = "#p2=10.32.35.81:3260"
		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		$firstNode.SerialID = "" 
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "csvone"
		$secondNode.Size = 10000
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "csvone"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.10:3260"
		$secondNode.HBInterface = "#p1=10.32.35.80:3260"
		$secondNode.ALUAOptimized = $true
		
		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}
	
	
	try
	{
		$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
		$server.Connect()
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "csvtwo"
		$firstNode.Size = 10000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "csvtwo"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.20:3260"
		$firstNode.HBInterface = "#p2=10.32.35.81:3260"
		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "csvtwo"
		$secondNode.Size = 10000
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "csvtwo"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.10:3260"
		$secondNode.HBInterface = "#p1=10.32.35.80:3260"
		$secondNode.ALUAOptimized = $true

		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}
	
	try
	{
		$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
		$server.Connect()
		
		$firstNode = new-Object Node
		$firstNode.ImagePath = "My computer\E"
		$firstNode.ImageName = "witness"
		$firstNode.Size = 10000
		$firstNode.CreateImage = $true
		$firstNode.TargetAlias = "witness"
		$firstNode.AutoSynch = $true
		$firstNode.SyncInterface = "#p2=10.32.10.20:3260"
		$firstNode.HBInterface = "#p2=10.32.35.81:3260"

		$firstNode.CacheSize = 128
		$firstNode.CacheMode = "wb"
		$firstNode.PoolName = "SW"
		$firstNode.SyncSessionCount = 1
		$firstNode.ALUAOptimized = $true
		$firstNode.SectorSize = 512
		$firstNode.SerialID = ""
		
		$secondNode = new-Object Node
		$secondNode.HostName = $storage2
		$secondNode.HostPort = "3261"
		$secondNode.Login = "root"
		$secondNode.Password = "starwind"
		$secondNode.ImagePath = "My computer\E"
		$secondNode.ImageName = "witness"
		$secondNode.Size = 8192
		$secondNode.CreateImage = $true
		$secondNode.TargetAlias = "witness"
		$secondNode.AutoSynch = $true
		$secondNode.SyncInterface = "#p1=10.32.10.10:3260"
		$secondNode.HBInterface = "#p1=10.32.35.80:3260"
		$secondNode.ALUAOptimized = $true
		$device = Add-HADevice -server $server -firstNode $firstNode -secondNode $secondNode -initMethod "Clear"
		Start-Sleep -m 1000
		$syncState = $device.GetPropertyValue("ha_synch_status")
		
		while ($syncState -ne "1")
		{
			$device.Refresh()
			
			$syncState = $device.GetPropertyValue("ha_synch_status")
			$syncPercent = $device.GetPropertyValue("ha_synch_percent")
			
			Start-Sleep -m 500
			Write-Host "Synchronizing: $($syncPercent)%" -foreground yellow
		}
	}
	catch
	{
		Write-Host "Exception $($_.Exception.Message)" -foreground red
	}
	
	$server.Disconnect()

Re: Create New Device Powershell

Posted: Fri Dec 01, 2017 6:12 pm
by Michael (staff)
You shouldn't use capital letters in the target name. They are present in $storage and $storage2 .

Re: Create New Device Powershell

Posted: Sat Dec 02, 2017 11:08 am
by chrisguk
ok now it works!

What is the command to check the sync status of any image/device in powershell?

Re: Create New Device Powershell

Posted: Mon Dec 04, 2017 3:48 pm
by Oleg(staff)
Hi chrisguk,
You can consider GetHASyncState.ps1 script to get devices state.