Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support vSphere Long-term Discount IF-13827 #162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions ecl/dedicated_hypervisor/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ecl.dedicated_hypervisor.v1 import usage as _usage
from ecl.dedicated_hypervisor.v1 import vcf as _vcf
from ecl.dedicated_hypervisor.v1 import vcenter as _vcenter
from ecl.dedicated_hypervisor.v1 import vsphere_contract as _vsphere_contract
from ecl import proxy2


Expand Down Expand Up @@ -320,3 +321,43 @@ def delete_vcenter(self, vcenter_id, ignore_missing=False):
"""
return self._delete(_vcenter.VCenter, vcenter_id ,
ignore_missing=ignore_missing)

def vsphere_contracts(self):
"""
List vSphere Contracts.

:returns:
vsphere_contracts: A list of the vSphere Contracts
all_server_cores: The total cores of your vSphere ESXi server.
vsphere_contracts_histories: A list of the vSphere contracts histories.
:rtype:
vsphere_contracts: list of :class:`~ecl.dedicated_hypervisor.v1._vsphere_contract.VSphereContract` instance.
all_server_cores: integer
vsphere_contracts_histories: dict
"""
vsphere_contract = _vsphere_contract.VSphereContract()
return vsphere_contract.list(self.session)

def manage_vsphere_contract(self, contract_year, cores):
"""
Manage vSphere Contracts.

:param integer contract_year: The number of years of the contract. You can specify 1 or 3.
:param integer cores: The number of cores to be added to your contract.
:return: vSphere Contract.
:rtype: :class:`~ecl.dedicated_hypervisor.v1._vsphere_contract.VSphereContract`
"""
vsphere_contract = _vsphere_contract.VSphereContract()
return vsphere_contract.manage(self.session, contract_year, cores)

def renewal_vsphere_contract(self, contract_year, contract_renewal=None):
"""
Enable/Disable Contract Renewal.

:param integer contract_year: The number of years of the contract. You can specify 1 or 3.
:param bool contract_renewal: The flag that you renew your contract or not.
:return: vSphere Contract.
:rtype: :class:`~ecl.dedicated_hypervisor.v1._vsphere_contract.VSphereContract`
"""
vsphere_contract = _vsphere_contract.VSphereContract()
return vsphere_contract.renewal(self.session, contract_year, contract_renewal)
83 changes: 83 additions & 0 deletions ecl/dedicated_hypervisor/v1/vsphere_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from ecl.dedicated_hypervisor import dedicated_hypervisor_service
from ecl import resource2


class VSphereContract(resource2.Resource):
resources_key = 'vsphere_contracts'
resource_key = 'vsphere_contract'
base_path = '/vsphere_contracts'
service = dedicated_hypervisor_service.DedicatedHypervisorService()

# Properties
#: Contract year
contract_year = resource2.Body('contract_year')
#: The flag that you renew the contract or not
contract_renewal = resource2.Body('contract_renewal')
#: The number of cores used for calculating the discount amount for current month
cores = resource2.Body('cores')
#: The month that your contract starts
start_month = resource2.Body('start_month')
#: The month that your contract ends
end_month = resource2.Body('end_month')
#: The number of additional cores used from next month
pending_cores = resource2.Body('pending_cores')
#: The number of cores used for calculating the discount amount for next month
cores_in_next_month = resource2.Body('cores_in_next_month')

def list(self, session, **params):
resp = session.get(
self.base_path,
endpoint_filter=self.service
)
resp = resp.json()
datas = resp[self.resources_key]
all_server_cores = resp['all_server_cores']
vsphere_contracts_histories = resp['vsphere_contracts_histories']
vsphere_contracts = []
for data in datas:
data.pop("self", None)
vsphere_contract = self.existing(**data)
vsphere_contracts.append(vsphere_contract)
return vsphere_contracts, all_server_cores, vsphere_contracts_histories

def manage(self, session, contract_year, cores):
params = {
'contract_year': contract_year,
'cores': cores
}
resp = session.post(
self.base_path,
endpoint_filter=self.service,
json={self.resource_key: params}
)
body = resp.json()
vsphere_contract = body[self.resource_key]
if vsphere_contract is None or len(vsphere_contract) == 0:
return None
self._translate_response(resp)
return self

def renewal(self, session, contract_year, contract_renewal=None):
params = {}
params['contract_year'] = contract_year
if contract_renewal:
params['contract_renewal'] = contract_renewal
resp = session.put(
self.base_path,
endpoint_filter=self.service,
json={self.resource_key: params}
)
self._translate_response(resp)
return self