@@ -1559,9 +1559,10 @@ def build_volume(self, vmid, node, key, storage=None, volume=None, host_path=Non
1559
1559
volume = volume ,
1560
1560
),
1561
1561
)
1562
- vol_string = "{storage}:{volume},size={size}" .format (
1563
- storage = storage , volume = volume , size = size
1564
- )
1562
+ vol_parts = [
1563
+ "{storage}:{volume}" .format (storage = storage , volume = volume ),
1564
+ "size={size}" .format (size = size ),
1565
+ ]
1565
1566
# 2. If volume not defined (but storage is), check if it exists
1566
1567
elif storage is not None :
1567
1568
proxmox_node = self .proxmox_api .nodes (
@@ -1570,9 +1571,10 @@ def build_volume(self, vmid, node, key, storage=None, volume=None, host_path=Non
1570
1571
try :
1571
1572
vol = proxmox_node .lxc (vmid ).get ("config" ).get (key )
1572
1573
volume = self .parse_disk_string (vol ).get ("volume" )
1573
- vol_string = "{storage}:{volume},size={size}" .format (
1574
- storage = storage , volume = volume , size = size
1575
- )
1574
+ vol_parts = [
1575
+ "{storage}:{volume}" .format (storage = storage , volume = volume ),
1576
+ "size={size}" .format (size = size ),
1577
+ ]
1576
1578
1577
1579
# If not, we have proxmox create one using the special syntax
1578
1580
except Exception :
@@ -1582,36 +1584,32 @@ def build_volume(self, vmid, node, key, storage=None, volume=None, host_path=Non
1582
1584
)
1583
1585
elif size .endswith ("G" ):
1584
1586
size = size .rstrip ("G" )
1585
- vol_string = "{storage}:{size}" .format (storage = storage , size = size )
1587
+ vol_parts = [ "{storage}:{size}" .format (storage = storage , size = size )]
1586
1588
else :
1587
1589
raise ValueError (
1588
1590
"Size must be provided in GiB for storage-backed volume creation. Convert it to GiB or allocate a new storage manually."
1589
1591
)
1590
1592
# 3. If we have a host_path, we don't have storage, a volume, or a size
1591
1593
# Then we don't have to do anything, just build and return the vol_string
1592
1594
elif host_path is not None :
1593
- vol_string = ""
1595
+ vol_parts = []
1594
1596
else :
1595
1597
raise ValueError (
1596
1598
"Could not build a valid volume string. One of volume, storage, or host_path must be provided."
1597
1599
)
1598
1600
1599
1601
if host_path is not None :
1600
- vol_string += "," + host_path
1602
+ vol_parts += [ host_path ]
1601
1603
1602
1604
if mountpoint is not None :
1603
- vol_string += ", mp={}" .format (mountpoint )
1605
+ vol_parts += [ " mp={}" .format (mountpoint )]
1604
1606
1605
1607
if options is not None :
1606
- vol_string += "," + "," .join (
1607
- ["{0}={1}" .format (k , v ) for k , v in options .items ()]
1608
- )
1608
+ vol_parts += ["{0}={1}" .format (k , v ) for k , v in options .items ()]
1609
1609
1610
1610
if kwargs :
1611
- vol_string += "," + "," .join (
1612
- ["{0}={1}" .format (k , v ) for k , v in kwargs .items ()]
1613
- )
1614
- return {key : vol_string }
1611
+ vol_parts += ["{0}={1}" .format (k , v ) for k , v in kwargs .items ()]
1612
+ return {key : "," .join (vol_parts )}
1615
1613
1616
1614
def get_lxc_resource (self , vmid , hostname ):
1617
1615
if not vmid and not hostname :
0 commit comments