Skip to content

Commit 1a3e771

Browse files
committed
Added key-pair feature
1 parent 76dcf44 commit 1a3e771

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ Launching spot states sir-123abcde
4242
If you don't want to enter the CLI prompt every time, you can run the CLI with the options
4343

4444
```bash
45-
spotme --InstanceType=t2.micro --SpotPrice=0.006 --InstanceCount=1 --AvailabilityZone=ca-central-1a --LaunchImageId=ami-d29e25b6 --SecurityGroup=sg-123abcd
45+
spotme --InstanceType=t2.micro --SpotPrice=0.006 --InstanceCount=1 --AvailabilityZone=ca-central-1a --LaunchImageId=ami-d29e25b6 --SecurityGroup=sg-123abcd --KeyName=yourkeypair
4646

4747
```
4848

4949
## Version
50+
* **1.2.0**
51+
* Added Key-pair name
52+
5053
* **1.1.0**
5154
* Added customization security group
5255

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ CLI with the options
6363

6464
.. code:: bash
6565
66-
spotme --InstanceType=t2.micro --SpotPrice=0.006 --InstanceCount=1 --AvailabilityZone=ca-central-1a --LaunchImageId=ami-d29e25b6 --SecurityGroup=sg-123abcd
66+
spotme --InstanceType=t2.micro --SpotPrice=0.006 --InstanceCount=1 --AvailabilityZone=ca-central-1a --LaunchImageId=ami-d29e25b6 --SecurityGroup=sg-123abcd --KeyName=yourkeypair
6767
6868
Version
6969
-------
7070

71+
- **1.2.0**
72+
73+
- Added Key-pair name
74+
7175
- **1.1.0**
7276

7377
- Added customization security group

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from setuptools import setup
88

99

10-
version = "1.1.1"
10+
version = "1.2.0"
1111

1212
with open("README.rst", "rb") as f:
1313
long_descr = f.read().decode("utf-8")

spotme/spotme.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
g["availabilityzone"] = client.describe_availability_zones()["AvailabilityZones"][0]["ZoneName"]
2121
security_groups = client.describe_security_groups()["SecurityGroups"]
2222
security_groups = [(group["GroupId"], group["GroupName"]) for group in security_groups]
23+
keynames = client.describe_key_pairs()["KeyPairs"]
24+
keynames = [kp["KeyName"] for kp in keynames]
2325

2426
def get_spot_instance_id(response):
2527
ids = []
@@ -71,7 +73,13 @@ def print_urls(urls):
7173
default=d.get("securitygroup", security_groups[0][0]),
7274
help="Security Group to put the spot instance"
7375
)
74-
def main(instancetype, spotprice, instancecount, availabilityzone, launchimageid, securitygroup):
76+
@click.option(
77+
"--KeyName",
78+
prompt="Key-Pair Name, pick from:\n\t" + "\n\t".join([kp for kp in keynames]) +"\nDefault is",
79+
default=d.get("keyname", keynames[0]),
80+
help="Key-Pair Name for the spot instance"
81+
)
82+
def main(instancetype, spotprice, instancecount, availabilityzone, launchimageid, securitygroup, keyname):
7583
interval = 3
7684
client = boto3.client("ec2")
7785
response = client.request_spot_instances(
@@ -83,7 +91,8 @@ def main(instancetype, spotprice, instancecount, availabilityzone, launchimageid
8391
"AvailabilityZone": availabilityzone
8492
},
8593
"InstanceType": instancetype,
86-
"SecurityGroupIds": [securitygroup]
94+
"SecurityGroupIds": [securitygroup],
95+
"KeyName": keyname
8796
}
8897
)
8998
pending_spot_ids = get_spot_instance_id(response)

0 commit comments

Comments
 (0)