Repository: softlayer/softlayer-python
Pull request #1838 (2023-01-24 22:41:39)

vs os-available command
[#issue1837](https://github.com/softlayer/softlayer-python/issues/1837)

![image](https://user-images.githubusercontent.com/22535437/214437278-fd4ea795-82d6-459b-ba83-71063b55486a.png)



Patch:
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index ff754030..bc5cc3ee 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -58,6 +58,7 @@
     ('virtual:notification-add', 'SoftLayer.CLI.virt.notification_add:cli'),
     ('virtual:notification-delete', 'SoftLayer.CLI.virt.notification_delete:cli'),
     ('virtual:host-list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
+    ('virtual:os-available', 'SoftLayer.CLI.virt.os_available:cli'),
 
     ('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
     ('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
diff --git a/SoftLayer/CLI/virt/os_available.py b/SoftLayer/CLI/virt/os_available.py
new file mode 100644
index 00000000..ecf10098
--- /dev/null
+++ b/SoftLayer/CLI/virt/os_available.py
@@ -0,0 +1,30 @@
+"""Get all available Operating Systems."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+
+import SoftLayer
+
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import formatting
+
+
+@click.command(cls=SoftLayer.CLI.command.SLCommand, )
+@environment.pass_env
+def cli(env):
+    """Get all available Operating Systems."""
+
+    table = formatting.KeyValueTable(['Id', 'KeyName', 'Description', 'Hourly', 'Monthly', 'Setup'])
+    table.align['name'] = 'r'
+    table.align['value'] = 'l'
+    manager = SoftLayer.OrderingManager(env.client)
+    _filter = {"items": {"prices": {"categories": {"categoryCode": {"operation": "os"}}}}}
+    # PUBLIC_CLOUD_SERVER = 835
+    operations = manager.get_items(storage_filter=_filter, package_id=835)
+
+    for operation_system in operations:
+        table.add_row([operation_system.get('id'), operation_system.get('keyName'), operation_system.get('description'),
+                       operation_system['prices'][0].get('hourlyRecurringFee') or formatting.blank(),
+                       operation_system['prices'][0]['laborFee'],
+                       operation_system['prices'][0]['setupFee']])
+    env.fout(table)
diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package.py b/SoftLayer/fixtures/SoftLayer_Product_Package.py
index 9c2b02ec..724a0c7a 100644
--- a/SoftLayer/fixtures/SoftLayer_Product_Package.py
+++ b/SoftLayer/fixtures/SoftLayer_Product_Package.py
@@ -2276,3 +2276,33 @@
         }
     }
 ]
+
+getItemsOS = [{
+    "description": "Debian GNU/Linux 6.x Squeeze/Stable - LAMP Install (64 bit)",
+    "id": 3975,
+    "itemTaxCategoryId": 166,
+    "keyName": "OS_DEBIAN_6_X_SQUEEZE_LAMP_64_BIT",
+    "softwareDescriptionId": 881,
+    "itemCategory": {
+        "categoryCode": "os",
+        "id": 12,
+        "name": "Operating System",
+    },
+    "prices": [
+        {
+            "hourlyRecurringFee": "0",
+            "id": 14056,
+            "itemId": 3975,
+            "laborFee": "0",
+            "recurringFee": "0",
+            "setupFee": "0",
+            "packageReferences": [
+                {
+                    "id": 74660,
+                    "itemPriceId": 14056,
+                    "packageId": 46
+                }
+            ]
+        }
+    ]
+}]
diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py
index d0d5a03e..f6520849 100644
--- a/SoftLayer/managers/vs.py
+++ b/SoftLayer/managers/vs.py
@@ -1120,7 +1120,7 @@ def get_disk_category_id_by_disk_number(self, capacity, disk_number):
         if category_to_request is None:
             return None
 
-        key_name = "*= GUEST_DISK_"+str(capacity)+"_GB_SAN"
+        key_name = "*= GUEST_DISK_" + str(capacity) + "_GB_SAN"
         object_filter = {
             "itemPrices": {
                 "locationGroupId": {"operation": "is null"},
diff --git a/docs/cli/vs.rst b/docs/cli/vs.rst
index 00163336..ff502c99 100644
--- a/docs/cli/vs.rst
+++ b/docs/cli/vs.rst
@@ -296,6 +296,10 @@ If no timezone is specified, IMS local time (CST) will be assumed, which might n
     :prog: virtual host-list
     :show-nested:
 
+.. click:: SoftLayer.CLI.virt.os_available:cli
+   :prog: virtual os-available
+   :show-nested:
+
 Manages the migration of virutal guests. Supports migrating virtual guests on Dedicated Hosts as well.
 
 Reserved Capacity


Test patch:
diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py
index c87dede5..8562f446 100644
--- a/tests/CLI/modules/vs/vs_tests.py
+++ b/tests/CLI/modules/vs/vs_tests.py
@@ -995,3 +995,9 @@ def test_add_notification(self):
     def test_notification_delete(self):
         result = self.run_command(['vs', 'notification-delete', '100'])
         self.assert_no_fail(result)
+
+    def test_os_available(self):
+        _mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
+        _mock.return_value = SoftLayer_Product_Package.getItemsOS
+        result = self.run_command(['vs', 'os-available'])
+        self.assert_no_fail(result)