|
| 1 | +## 🚀 Usage |
| 2 | + |
| 3 | +Basic usage with the default profile: |
| 4 | + |
| 5 | +```python |
| 6 | +from osc_sdk_python import Gateway |
| 7 | + |
| 8 | +gw = Gateway() |
| 9 | + |
| 10 | +# Example: list VMs |
| 11 | +vms = gw.ReadVms() |
| 12 | +print(vms) |
| 13 | +``` |
| 14 | + |
| 15 | +Using a specific profile: |
| 16 | + |
| 17 | +```python |
| 18 | +from osc_sdk_python import Gateway |
| 19 | + |
| 20 | +gw = Gateway(profile="profile_1") |
| 21 | +``` |
| 22 | + |
| 23 | +Calling actions: |
| 24 | + |
| 25 | +* **Typed methods**: `gw.ReadVms(...)`, `gw.CreateVms(...)`, etc. |
| 26 | +* **Raw calls**: `gw.raw("ActionName", **params)` |
| 27 | + |
| 28 | +Example: |
| 29 | + |
| 30 | +```python |
| 31 | +from osc_sdk_python import Gateway |
| 32 | + |
| 33 | +gw = Gateway(profile="profile_1") |
| 34 | + |
| 35 | +# Calls with API action as method |
| 36 | +result = gw.ReadSecurityGroups(Filters={"SecurityGroupNames": ["default"]}) |
| 37 | +result = gw.CreateVms(ImageId="ami-3e158364", VmType="tinav4.c2r4") |
| 38 | + |
| 39 | +# Or raw calls: |
| 40 | +result = gw.raw("ReadVms") |
| 41 | +result = gw.raw( |
| 42 | + "CreateVms", |
| 43 | + ImageId="ami-xx", |
| 44 | + BlockDeviceMappings=[{"/dev/sda1": {"Size": 10}}], |
| 45 | + SecurityGroupIds=["sg-aaa", "sg-bbb"], |
| 46 | + Wrong="wrong", |
| 47 | +) |
| 48 | +``` |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## 💡 Examples |
| 53 | + |
| 54 | +### List all VM and Volume IDs |
| 55 | + |
| 56 | +```python |
| 57 | +from osc_sdk_python import Gateway |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + gw = Gateway() |
| 61 | + |
| 62 | + print("Your virtual machines:") |
| 63 | + for vm in gw.ReadVms()["Vms"]: |
| 64 | + print(vm["VmId"]) |
| 65 | + |
| 66 | + print("\nYour volumes:") |
| 67 | + for volume in gw.ReadVolumes()["Volumes"]: |
| 68 | + print(volume["VolumeId"]) |
| 69 | +``` |
| 70 | + |
| 71 | +### Enabling logs |
| 72 | + |
| 73 | +```python |
| 74 | +from osc_sdk_python import * |
| 75 | + |
| 76 | +if __name__ == "__main__": |
| 77 | + gw = Gateway(profile="profile_1") |
| 78 | + |
| 79 | + # 'what' can be LOG_KEEP_ONLY_LAST_REQ or LOG_ALL |
| 80 | + # Here we print logs in memory, standard output and standard error |
| 81 | + gw.log.config(type=LOG_MEMORY | LOG_STDIO | LOG_STDERR, what=LOG_KEEP_ONLY_LAST_REQ) |
| 82 | + |
| 83 | + result = gw.raw("ReadVms") |
| 84 | + |
| 85 | + last_request = gw.log.str() |
| 86 | + print(last_request) |
| 87 | +``` |
| 88 | + |
| 89 | +Usage examples can be combined with the official [Outscale API documentation](https://docs.outscale.com/en/userguide/Home.html). |
0 commit comments