Skip to content

Commit

Permalink
Add extra filter options to reserved_* ec2 offer functions (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettheel committed Mar 8, 2017
1 parent ad9cff7 commit 74d07b1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -7,7 +7,7 @@ python:
install:
- pip install -e .
- pip install -r test-requirements.txt
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install mypy; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then pip install -r mypy-requirements.txt; fi
script:
- make test
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then make test_mypy; fi
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* Add extra filter options (tenancy, license_model, preinstalled_software) when fetching EC2 reserved prices (#4)

## 1.0.0

* Initial release
2 changes: 2 additions & 0 deletions awspricing/constants.py
@@ -1,3 +1,5 @@
from typing import Dict # noqa


class Enum(object):
"""Very simple string enumeration implementation.
Expand Down
58 changes: 38 additions & 20 deletions awspricing/offers.py
@@ -1,6 +1,6 @@
from collections import defaultdict

from typing import Any, Optional, Set, Type # noqa
from typing import Any, Dict, List, Optional, Set, Type # noqa

import six

Expand Down Expand Up @@ -85,8 +85,8 @@ def hash_attributes(*attributes): # type: (*str) -> str
return '|'.join(attributes)

def _generate_reverse_sku_mapping(self,
*attribute_names, # type: *str
**kwargs # type: *Optional[str]
*attribute_names, # type: str
**kwargs # type: Dict[str, str]
):
# type: (...) -> Dict[str, str]

Expand Down Expand Up @@ -179,19 +179,28 @@ def ondemand_hourly(self,
return float(raw_price)

def reserved_hourly(self,
instance_type, # type: str
operating_system=None, # type: Optional[str]
lease_contract_length=None, # type: Optional[str]
offering_class='standard', # type: Optional[str]
purchase_option=None, # type: Optional[str]
amortize_upfront=True, # type: bool
region=None, # type: Optional[str]
instance_type, # type: str
operating_system=None, # type: Optional[str]
tenancy=None, # type: Optional[str]
license_model=None, # type: Optional[str]
preinstalled_software=None, # type: Optional[str]
lease_contract_length=None, # type: Optional[str]
offering_class=EC2_OFFERING_CLASS.STANDARD, # type: str
purchase_option=None, # type: Optional[str]
amortize_upfront=True, # type: bool
region=None, # type: Optional[str]
):
# type: (...) -> float
self._validate_reserved_price_args(
lease_contract_length, offering_class, purchase_option)
sku = self.get_sku(instance_type, operating_system=operating_system,
region=region)
sku = self.get_sku(
instance_type,
operating_system=operating_system,
tenancy=tenancy,
license_model=license_model,
preinstalled_software=preinstalled_software,
region=region,
)

term_attributes = [
lease_contract_length,
Expand Down Expand Up @@ -250,18 +259,27 @@ def _get_hours_in_lease_contract_length(cls, lease_contract_length):
.format(lease_contract_length))

def reserved_upfront(self,
instance_type, # type: str
operating_system=None, # type: Optional[str]
lease_contract_length=None, # type: Optional[str]
offering_class=None, # type: Optional[str]
purchase_option=None, # type: Optional[str]
region=None, # type: Optional[str]
instance_type, # type: str
operating_system=None, # type: Optional[str]
tenancy=None, # type: Optional[str]
license_model=None, # type: Optional[str]
preinstalled_software=None, # type: Optional[str]
lease_contract_length=None, # type: Optional[str]
offering_class=EC2_OFFERING_CLASS.STANDARD, # type: str
purchase_option=None, # type: Optional[str]
region=None, # type: Optional[str]
):
# type: (...) -> float
self._validate_reserved_price_args(
lease_contract_length, offering_class, purchase_option)
sku = self.get_sku(instance_type, operating_system=operating_system,
region=region)
sku = self.get_sku(
instance_type,
operating_system=operating_system,
tenancy=tenancy,
license_model=license_model,
preinstalled_software=preinstalled_software,
region=region,
)

term_attributes = [
lease_contract_length,
Expand Down
1 change: 1 addition & 0 deletions mypy-requirements.txt
@@ -0,0 +1 @@
mypy==0.501
4 changes: 2 additions & 2 deletions setup.cfg
@@ -1,7 +1,7 @@
[flake8]
# The jenkins violations plugin can read the pylint format.
format = pylint
max-line-length = 80
max-line-length = 100

# .svn,CVS,.bzr,.hg,.git,__pycache__:
# default excludes
Expand All @@ -12,7 +12,7 @@ exclude = .git,__pycache__,venv,tests/,.ropeproject


[pep8]
max-line-length = 80
max-line-length = 100


[bdist_wheel]
Expand Down

0 comments on commit 74d07b1

Please sign in to comment.