Skip to content

Latest commit

 

History

History
85 lines (61 loc) · 1.92 KB

File metadata and controls

85 lines (61 loc) · 1.92 KB

🚀 Usage

Basic usage with the default profile:

from osc_sdk_python import Gateway

with Gateway() as gw:
    # Example: list VMs
    vms = gw.ReadVms()
    print(vms)

Using a specific profile:

from osc_sdk_python import Gateway

gw = Gateway(profile="profile_1")

Calling actions:

  • Typed methods: gw.ReadVms(...), gw.CreateVms(...), etc.
  • Raw calls: gw.raw("ActionName", **params)

Example:

from osc_sdk_python import Gateway

with Gateway(profile="profile_1") as gw:
    # Calls with API action as method
    result = gw.ReadSecurityGroups(Filters={"SecurityGroupNames": ["default"]})
    result = gw.CreateVms(ImageId="ami-3e158364", VmType="tinav4.c2r4")

    # Or raw calls:
    result = gw.raw("ReadVms")
    result = gw.raw(
        "CreateVms",
        ImageId="ami-xx",
        BlockDeviceMappings=[{"/dev/sda1": {"Size": 10}}],
        SecurityGroupIds=["sg-aaa", "sg-bbb"],
        Wrong="wrong",
    )

💡 Examples

List all VM and Volume IDs

from osc_sdk_python import Gateway

if __name__ == "__main__":
    with Gateway() as gw:
        print("Your virtual machines:")
        for vm in gw.ReadVms()["Vms"]:
            print(vm["VmId"])

        print("\nYour volumes:")
        for volume in gw.ReadVolumes()["Volumes"]:
            print(volume["VolumeId"])

Enabling logs

from osc_sdk_python import *

if __name__ == "__main__":
    with Gateway(profile="profile_1") as gw:
        # 'what' can be LOG_KEEP_ONLY_LAST_REQ or LOG_ALL
        # Here we print logs in memory, standard output and standard error
        gw.log.config(type=LOG_MEMORY | LOG_STDIO | LOG_STDERR, what=LOG_KEEP_ONLY_LAST_REQ)

        result = gw.raw("ReadVms")

        last_request = gw.log.str()
        print(last_request)

Usage examples can be combined with the official Outscale API documentation.