Powershell - How to attach existing device to existing storage

Software-based VM-centric and flash-friendly VM storage + free version

Moderators: anton (staff), art (staff), Max (staff), Anatoly (staff)

Post Reply
hjgl
Posts: 5
Joined: Tue Mar 27, 2018 2:57 pm

Tue Mar 27, 2018 3:53 pm

Hi all,

I was searching how to attach a new disk to my existing storage in PS, but i can't find documentation about this. In PS examples files (CreateImageFile.ps1), when i run this script, this dettach all devices and then attach the new one.

Anybody can help me? Thanks in advance.
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Tue Mar 27, 2018 4:09 pm

Could you be more specific on "attach a new disk to my existing storage"? What scenario is meant by this?
hjgl
Posts: 5
Joined: Tue Mar 27, 2018 2:57 pm

Tue Mar 27, 2018 5:11 pm

hjgl wrote:Hi all,

I was searching how to attach a new disk to my existing storage in PS, but i can't find documentation about this. In PS examples files (CreateImageFile.ps1), when i run this script, this dettach all devices and then attach the new one.

Anybody can help me? Thanks in advance.
Oh i'm sorry, i'm not english speaker. My setup is stand alone in windows 2012 on test environment. I want create a new virtual disk in my storage, called "vSAN". This "vSAN" have 17 virtual disk working fine and i want add one more. When i ran the CreateImageFile.ps1 script, this script dettach all my virtual disks and then attach only the new one.

My Script is this:

Import-Module StarWindX
try
{
$server = New-SWServer -host 127.31.0.6 -port 3261 -user root -password starwind
$server.Connect()

#create image file
New-ImageFile -server $server -path "My Computer\D\VM\Shared Storage\SQLData05" -fileName "imagefile18" -size 120

#create device
$device = Add-ImageDevice -server $server -path "My Computer\D\VM\Shared Storage\SQLData05" -fileName "imagefile18" -sectorSize 512 -NumaNode 0

#create target
$target = New-Target -server $server -alias "vSAN" -devices $device.Name

#$target
}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}

If i skip the "Create Target" label, then the disk is created but not attached to the "vSAN" storage. Please, help.
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Wed Mar 28, 2018 8:55 am

What is the build number you currently use and encounter this behavior? Do you have all 17 virtual disks attached to the same vSAN target? If so, this should not be so. I would recommend using 1 disk per 1 target.
hjgl
Posts: 5
Joined: Tue Mar 27, 2018 2:57 pm

Wed Mar 28, 2018 2:33 pm

The build number is the most recent (i just download the last weekend) 8.0.0.11818. Yes, the 17 virtual disk are attached to the same vSAN target and i believe this setup is right because is a SQL Server cluster with many mount points. The setup work fine and the cluster run fine, but i can't create a new vdisk and attach to the same vSAN for dev and research purpoise. Can you help me with this? I only need the code in PS for create and attach a new vdisk.
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Thu Mar 29, 2018 3:19 pm

Do you use a standalone setup?
If so, this script can help you:

Code: Select all

import StarWindX

try
{
	$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind

	$server.Connect()

	#create image file
   #size in megabytes
	New-ImageFile -server $server -path "My Computer\D" -fileName "new_image_file_name" -size 1024
    
	#create device
	$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "img3" -sectorSize 512 -NumaNode 0
    
	#create target
	$target = New-Target -server $server -alias "your_existing_target_name" -devices $server.Devices[0].Name,$server.Devices[1].Name,$server.Devices[3].Name,$server.Devices[4].Name,$server.Devices[5].Name,$server.Devices[6].Name,$server.Devices[7].Name,$server.Devices[8].Name,$server.Devices[9].Name,$server.Devices[10].Name,$server.Devices[11].Name,$server.Devices[12].Name,$server.Devices[13].Name,$server.Devices[14].Name,$server.Devices[15].Name,$server.Devices[16].Name,$server.Devices[17].Name

}
catch
{
	Write-Host $_ -foreground red
}
finally
{
	$server.Disconnect()
}
Before running this script, I would recommend you disconnecting client iSCSI connections to all disks in that target, so that no I/O operations are processed at that time. Also, be aware this script is a workaround developed specifically for your case, but not an official sample to be used. The requested functionality is expected to be offered officially in one of the next builds.
hjgl
Posts: 5
Joined: Tue Mar 27, 2018 2:57 pm

Mon Apr 02, 2018 3:15 pm

Boris (staff) wrote:Do you use a standalone setup?
If so, this script can help you:

Code: Select all

import StarWindX

try
{
	$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind

	$server.Connect()

	#create image file
   #size in megabytes
	New-ImageFile -server $server -path "My Computer\D" -fileName "new_image_file_name" -size 1024
    
	#create device
	$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "img3" -sectorSize 512 -NumaNode 0
    
	#create target
	$target = New-Target -server $server -alias "your_existing_target_name" -devices $server.Devices[0].Name,$server.Devices[1].Name,$server.Devices[3].Name,$server.Devices[4].Name,$server.Devices[5].Name,$server.Devices[6].Name,$server.Devices[7].Name,$server.Devices[8].Name,$server.Devices[9].Name,$server.Devices[10].Name,$server.Devices[11].Name,$server.Devices[12].Name,$server.Devices[13].Name,$server.Devices[14].Name,$server.Devices[15].Name,$server.Devices[16].Name,$server.Devices[17].Name

}
catch
{
	Write-Host $_ -foreground red
}
finally
{
	$server.Disconnect()
}
Before running this script, I would recommend you disconnecting client iSCSI connections to all disks in that target, so that no I/O operations are processed at that time. Also, be aware this script is a workaround developed specifically for your case, but not an official sample to be used. The requested functionality is expected to be offered officially in one of the next builds.
Thank you for your help. This have an issue: the $server.Devices[] array is empty, so i couldn't attach the disks again (neither the new one 18). I get your idea and it's good because is an experimental and dev environment, but have this issue.
hjgl
Posts: 5
Joined: Tue Mar 27, 2018 2:57 pm

Mon Apr 02, 2018 3:39 pm

hjgl wrote:
Boris (staff) wrote:Do you use a standalone setup?
If so, this script can help you:

Code: Select all

import StarWindX

try
{
	$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind

	$server.Connect()

	#create image file
   #size in megabytes
	New-ImageFile -server $server -path "My Computer\D" -fileName "new_image_file_name" -size 1024
    
	#create device
	$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "img3" -sectorSize 512 -NumaNode 0
    
	#create target
	$target = New-Target -server $server -alias "your_existing_target_name" -devices $server.Devices[0].Name,$server.Devices[1].Name,$server.Devices[3].Name,$server.Devices[4].Name,$server.Devices[5].Name,$server.Devices[6].Name,$server.Devices[7].Name,$server.Devices[8].Name,$server.Devices[9].Name,$server.Devices[10].Name,$server.Devices[11].Name,$server.Devices[12].Name,$server.Devices[13].Name,$server.Devices[14].Name,$server.Devices[15].Name,$server.Devices[16].Name,$server.Devices[17].Name

}
catch
{
	Write-Host $_ -foreground red
}
finally
{
	$server.Disconnect()
}
Before running this script, I would recommend you disconnecting client iSCSI connections to all disks in that target, so that no I/O operations are processed at that time. Also, be aware this script is a workaround developed specifically for your case, but not an official sample to be used. The requested functionality is expected to be offered officially in one of the next builds.
Thank you for your help. This have an issue: the $server.Devices[] array is empty, so i couldn't attach the disks again (neither the new one 18). I get your idea and it's good because is an experimental and dev environment, but have this issue.
Ready, thanks a lot! The workaround was set the device name hardcoded like imagefile1,imagefile2,etc and this work great. No shutdown or errors in the cluster manager during the script execution.

I put the script "fixed":

Import-Module StarWindX

try
{
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind

$server.Connect()

#create image file
#size in megabytes
New-ImageFile -server $server -path "My Computer\D" -fileName "imagefile18" -size 10240

#create device
$device = Add-ImageDevice -server $server -path "My Computer\D" -fileName "imagefile18" -sectorSize 512 -NumaNode 0

#create target
$target = New-Target -server $server -alias "vSAN" -devices imagefile1,imagefile2,imagefile3,imagefile4,...,imagefile17,imagefile18

}
catch
{
Write-Host $_ -foreground red
}
finally
{
$server.Disconnect()
}
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Mon Apr 02, 2018 4:04 pm

Nice to learn this worked for you.
Post Reply