Skip to content

Commit

Permalink
move some code from flex to flexvolume
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic committed Jun 18, 2018
1 parent 84cc791 commit 7d7c89e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,7 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs

# built files
flex-provisioner.exe
iscsiHelper.exe
63 changes: 0 additions & 63 deletions flexprovisioner/src/flex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,6 @@ $logSource = "KubeFlex"
. $PSScriptRoot\iscsi.ps1
. $PSScriptRoot\smb.ps1

Function RemotelyInvoke([string]$ComputerName, [ScriptBlock]$ScriptBlock, $ArgumentList = @())
{
return Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ArgumentList $argumentlist -erroraction Stop
}

function DeleteRemotePath([string]$pathToDelete, [string]$ComputerName)
{
DebugLog "deleting $path"
RemotelyInvoke -ComputerName $ComputerName -ScriptBlock {
param($path)
if(test-path $path){
$empty = rmdir $path -Force -Recurse -ErrorAction Stop 2>&1
}
else {
$parentPath = Join-Path $path ".."
$empty = Resolve-Path $parentPath -ErrorAction Stop
}
} -ArgumentList $pathToDelete -ErrorAction Stop
DebugLog "Deleted path"
}
function EnsureRemotePathExists([string]$path, [string]$ComputerName)
{
DebugLog "Ensuring $path exists on server $ComputerName"
RemotelyInvoke -ComputerName $ComputerName -ScriptBlock {
param($path)
if(-not $(test-path $path)){
$empty = mkdir $path -ErrorAction Stop 2>&1
}
} -ArgumentList $path -ErrorAction Stop
DebugLog "Path $path exists on server $ComputerName"
}

function ConvertKubeSize([string]$number)
{
$sizes = @(
@("k", [math]::pow(10,3)),
@("M", [math]::pow(10,6)),
@("G", [math]::pow(10,9)),
@("T", [math]::pow(10,12)),
@("P", [math]::pow(10,15)),
@("E", [math]::pow(10,16)),
@("Ki", [math]::pow(2,10)),
@("Mi", [math]::pow(2,20)),
@("Gi", [math]::pow(2,30)),
@("Ti", [math]::pow(2,40)),
@("Pi", [math]::pow(2,50)),
@("Ei", [math]::pow(2,60)))

$multiplier = 1
foreach($size in $sizes)
{
if($number.EndsWith($size[0],"CurrentCultureIgnoreCase"))
{
$multiplier = $size[1]
$number = $number.substring(0,$number.length - $size[0].length)
break
}
}
[decimal]$dNumber = $number
[uint64]$uNumber = ([decimal]$multiplier) * $dNumber

$uNumber
}
function init()
{
}
Expand Down
64 changes: 64 additions & 0 deletions flexprovisioner/src/flexvolume.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,70 @@ if($logSource -eq $null)
throw "Define logSource before including this script"
}

Function RemotelyInvoke([string]$ComputerName, [ScriptBlock]$ScriptBlock, $ArgumentList = @())
{
return Invoke-Command -ComputerName $ComputerName -ScriptBlock $ScriptBlock -ArgumentList $argumentlist -erroraction Stop
}

function DeleteRemotePath([string]$pathToDelete, [string]$ComputerName)
{
DebugLog "deleting $path"
RemotelyInvoke -ComputerName $ComputerName -ScriptBlock {
param($path)
if(test-path $path){
$empty = rmdir $path -Force -Recurse -ErrorAction Stop 2>&1
}
else {
$parentPath = Join-Path $path ".."
$empty = Resolve-Path $parentPath -ErrorAction Stop
}
} -ArgumentList $pathToDelete -ErrorAction Stop
DebugLog "Deleted path"
}
function EnsureRemotePathExists([string]$path, [string]$ComputerName)
{
DebugLog "Ensuring $path exists on server $ComputerName"
RemotelyInvoke -ComputerName $ComputerName -ScriptBlock {
param($path)
if(-not $(test-path $path)){
$empty = mkdir $path -ErrorAction Stop 2>&1
}
} -ArgumentList $path -ErrorAction Stop
DebugLog "Path $path exists on server $ComputerName"
}

function ConvertKubeSize([string]$number)
{
$sizes = @(
@("k", [math]::pow(10,3)),
@("M", [math]::pow(10,6)),
@("G", [math]::pow(10,9)),
@("T", [math]::pow(10,12)),
@("P", [math]::pow(10,15)),
@("E", [math]::pow(10,16)),
@("Ki", [math]::pow(2,10)),
@("Mi", [math]::pow(2,20)),
@("Gi", [math]::pow(2,30)),
@("Ti", [math]::pow(2,40)),
@("Pi", [math]::pow(2,50)),
@("Ei", [math]::pow(2,60)))

$multiplier = 1
foreach($size in $sizes)
{
if($number.EndsWith($size[0],"CurrentCultureIgnoreCase"))
{
$multiplier = $size[1]
$number = $number.substring(0,$number.length - $size[0].length)
break
}
}
[decimal]$dNumber = $number
[uint64]$uNumber = ([decimal]$multiplier) * $dNumber

$uNumber
}

#allow you to expect an item and throw a useful message
Filter GetFirst
{
Expand Down

0 comments on commit 7d7c89e

Please sign in to comment.