-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
README.md: more documentation for variables
Signed-off-by: Matthias Gatto <[email protected]>
- Loading branch information
1 parent
cc3c388
commit 9d288ed
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
Let's say you want to create a VM, called "joe" in a script. | ||
|
||
using osc-cli, you would have to do something like this: | ||
|
||
```sh | ||
vm_id=$(osc-cli api CreateVms --ImageId $id | jq .Vms[0].VmId) | ||
oapi-cli CreateTags --ResourceIds "[$vm_id]" --Tags '[ { "Key": "Name", "Value": "joe" } ]' | ||
``` | ||
Moreover if you want to retrieve the ImageId programmatically, You need another call to ReadImage: | ||
```sh | ||
image_id=$(osc-cli api ReadImages --Filters '{"ImageNames": ["RockyLinux*"]}' | jq .Images[0].ImageId) | ||
vm_id=$(osc-cli api CreateVms --ImageId $image_id | jq .Vms[0].VmId) | ||
oapi-cli CreateTags --ResourceIds "[$vm_id]" --Tags '[ { "Key": "Name", "Value": "joe" } ]' | ||
``` | ||
|
||
With oapi-cli you can now chain calls, so you don't have to keep intermediary variables. | ||
|
||
```sh | ||
oapi-cli ReadImages --Filter.ImageNames[] "RockyLinux*" --set-var img_id=Images.0.ImageId \ | ||
CreateVms --ImageId --var img_id --set-var vm_id=Vms.0.VmId \ | ||
CreateTags --ResourceIds[] --var vm_id --Tags.0.Key Name ..Value "my vm" | ||
``` | ||
|
||
New let's create a Net, a SecurityGroups, and add rule on it. | ||
|
||
```sh | ||
net=$(osc-cli --endpoint "http://127.0.0.1:3000" api CreateNet --IpRange "10.0.0.0/16" | jq .Net.NetId) | ||
|
||
sg=$(osc-cli --endpoint "http://127.0.0.1:3000" api CreateSecurityGroup \ | ||
--NetId $net \ | ||
--SecurityGroupName "security-group-example" \ | ||
--Description "Security group example" | jq .SecurityGroup.SecurityGroupId) | ||
|
||
osc-cli --endpoint "http://127.0.0.1:3000" api CreateSecurityGroupRule \ | ||
--Flow "Inbound" \ | ||
--SecurityGroupId $sg \ | ||
--Rules '[ | ||
{ | ||
"FromPortRange": 22, | ||
"ToPortRange": 22, | ||
"IpProtocol": "tcp", | ||
"SecurityGroupsMembers": [{"AccountId": "123456789012", "SecurityGroupName": "another-security-group"}], | ||
}, | ||
]' | ||
``` | ||
|
||
with oapi-cli | ||
```sh | ||
oapi-cli CreateNet --IpRange "10.0.0.0/16" --set-var net=Net.NetId \ | ||
CreateSecurityGroup --NetId --var net --SecurityGroupName "security-group-example"\ | ||
--Description "Security group example" --set-var sg=SecurityGroup.SecurityGroupId \ | ||
CreateSecurityGroupRule --Flow "Inbound" --SecurityGroupId --var sg \ | ||
--Rules.0.FromPortRange 22 ..ToPortRange 22 ..IpProtocol tcp \ | ||
..SecurityGroupsMembers.0.AccountId 123456789012 \ | ||
..SecurityGroupName another-security-group | ||
``` |