Update EC2 instance type list

This commit is contained in:
Jacob-House 2020-04-15 18:48:33 -02:30
parent 532480a3b5
commit f04d64d981
No known key found for this signature in database
GPG Key ID: C922B98E6A12DDFC
2 changed files with 59 additions and 39 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import json import json
import os import os
import subprocess import subprocess
@ -11,128 +12,142 @@ class Instance(object):
self.instance = instance self.instance = instance
def _get_td(self, td): def _get_td(self, td):
return self.instance.find('td', attrs={'class': td}) return self.instance.find("td", attrs={"class": td})
def _get_sort(self, td): def _get_sort(self, td):
return float(self.instance.find('td', attrs={'class': td}).find('span')['sort']) return float(self.instance.find("td", attrs={"class": td}).find("span")["sort"])
@property @property
def name(self): def name(self):
return self._get_td('name').text.strip() return self._get_td("name").text.strip()
@property @property
def apiname(self): def apiname(self):
return self._get_td('apiname').text.strip() return self._get_td("apiname").text.strip()
@property @property
def memory(self): def memory(self):
return self._get_sort('memory') return self._get_sort("memory")
@property @property
def computeunits(self): def computeunits(self):
return self._get_sort('computeunits') return self._get_sort("computeunits")
@property @property
def vcpus(self): def vcpus(self):
return self._get_sort('vcpus') return self._get_sort("vcpus")
@property @property
def gpus(self): def gpus(self):
return int(self._get_td('gpus').text.strip()) return int(self._get_td("gpus").text.strip())
@property @property
def fpga(self): def fpga(self):
return int(self._get_td('fpga').text.strip()) return int(self._get_td("fpga").text.strip())
@property @property
def ecu_per_vcpu(self): def ecu_per_vcpu(self):
return self._get_sort('ecu-per-vcpu') return self._get_sort("ecu-per-vcpu")
@property @property
def physical_processor(self): def physical_processor(self):
return self._get_td('physical_processor').text.strip() return self._get_td("physical_processor").text.strip()
@property @property
def clock_speed_ghz(self): def clock_speed_ghz(self):
return self._get_td('clock_speed_ghz').text.strip() return self._get_td("clock_speed_ghz").text.strip()
@property @property
def intel_avx(self): def intel_avx(self):
return self._get_td('intel_avx').text.strip() return self._get_td("intel_avx").text.strip()
@property @property
def intel_avx2(self): def intel_avx2(self):
return self._get_td('intel_avx2').text.strip() return self._get_td("intel_avx2").text.strip()
@property @property
def intel_turbo(self): def intel_turbo(self):
return self._get_td('intel_turbo').text.strip() return self._get_td("intel_turbo").text.strip()
@property @property
def storage(self): def storage(self):
return self._get_sort('storage') return self._get_sort("storage")
@property @property
def architecture(self): def architecture(self):
return self._get_td('architecture').text.strip() return self._get_td("architecture").text.strip()
@property @property
def network_perf(self): # 2 == low def network_perf(self): # 2 == low
return self._get_sort('networkperf') return self._get_sort("networkperf")
@property @property
def ebs_max_bandwidth(self): def ebs_max_bandwidth(self):
return self._get_sort('ebs-max-bandwidth') return self._get_sort("ebs-max-bandwidth")
@property @property
def ebs_throughput(self): def ebs_throughput(self):
return self._get_sort('ebs-throughput') return self._get_sort("ebs-throughput")
@property @property
def ebs_iops(self): def ebs_iops(self):
return self._get_sort('ebs-iops') return self._get_sort("ebs-iops")
@property @property
def max_ips(self): def max_ips(self):
return int(self._get_td('maxips').text.strip()) return int(self._get_td("maxips").text.strip())
@property @property
def enhanced_networking(self): def enhanced_networking(self):
return self._get_td('enhanced-networking').text.strip() != 'No' return self._get_td("enhanced-networking").text.strip() != "No"
@property @property
def vpc_only(self): def vpc_only(self):
return self._get_td('vpc-only').text.strip() != 'No' return self._get_td("vpc-only").text.strip() != "No"
@property @property
def ipv6_support(self): def ipv6_support(self):
return self._get_td('ipv6-support').text.strip() != 'No' return self._get_td("ipv6-support").text.strip() != "No"
@property @property
def placement_group_support(self): def placement_group_support(self):
return self._get_td('placement-group-support').text.strip() != 'No' return self._get_td("placement-group-support").text.strip() != "No"
@property @property
def linux_virtualization(self): def linux_virtualization(self):
return self._get_td('linux-virtualization').text.strip() return self._get_td("linux-virtualization").text.strip()
def to_dict(self): def to_dict(self):
result = {} result = {}
for attr in [x for x in self.__class__.__dict__.keys() if not x.startswith('_') and x != 'to_dict']: for attr in [
result[attr] = getattr(self, attr) x
for x in self.__class__.__dict__.keys()
if not x.startswith("_") and x != "to_dict"
]:
try:
result[attr] = getattr(self, attr)
except ValueError as ex:
if "'N/A'" in str(ex):
print(
"Skipping attribute '{0}' for instance type '{1}' (not found)".format(
attr, self.name
)
)
else:
raise
return self.apiname, result return self.apiname, result
def main(): def main():
print("Getting HTML from http://www.ec2instances.info") print("Getting HTML from http://www.ec2instances.info")
page_request = requests.get('http://www.ec2instances.info') page_request = requests.get("http://www.ec2instances.info")
soup = BeautifulSoup(page_request.text, 'html.parser') soup = BeautifulSoup(page_request.text, "html.parser")
data_table = soup.find(id='data') data_table = soup.find(id="data")
print("Finding data in table") print("Finding data in table")
instances = data_table.find('tbody').find_all('tr') instances = data_table.find("tbody").find_all("tr")
print("Parsing data") print("Parsing data")
result = {} result = {}
@ -140,11 +155,16 @@ def main():
instance_id, instance_data = Instance(instance).to_dict() instance_id, instance_data = Instance(instance).to_dict()
result[instance_id] = instance_data result[instance_id] = instance_data
root_dir = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).decode().strip() root_dir = (
dest = os.path.join(root_dir, 'moto/ec2/resources/instance_types.json') subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
.decode()
.strip()
)
dest = os.path.join(root_dir, "moto/ec2/resources/instance_types.json")
print("Writing data to {0}".format(dest)) print("Writing data to {0}".format(dest))
with open(dest, 'w') as open_file: with open(dest, "w") as open_file:
json.dump(result, open_file) json.dump(result, open_file, sort_keys=True)
if __name__ == '__main__':
if __name__ == "__main__":
main() main()