Skip to content

Commit 365f591

Browse files
committed
Fixing lint issues
1 parent 183c2e1 commit 365f591

3 files changed

Lines changed: 44 additions & 40 deletions

File tree

wrapanapi/entities/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313

1414
__all__ = [
1515
'Template', 'TemplateMixin', 'Vm', 'VmState', 'VmMixin', 'Instance',
16-
'PhysicalContainer', 'Server', 'ServerState', 'Stack', 'StackMixin'
16+
'PhysicalContainer', 'Server', 'ServerState', 'Stack', 'StackMixin',
17+
'Project', 'ProjectMixin'
1718
]

wrapanapi/entities/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Project(six.with_metaclass(ABCMeta, Entity)):
1515
"""
1616
Represents a project on a system
1717
"""
18-
@abstractproperty
18+
@abstractmethod
1919
def get_quota(self):
2020
"""
2121
Deploy a VM/instance with name 'vm_name' using this template

wrapanapi/systems/openshift.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
from openshift import client as ociclient
1919
from wait_for import TimedOutError, wait_for
2020

21-
from wrapanapi.entities import (Template, Vm, VmMixin, VmState, ProjectMixin,
22-
Project)
21+
from wrapanapi.entities import (Template, Vm, VmMixin, VmState, ProjectMixin, Project)
2322
from wrapanapi.systems.base import System
2423

2524

@@ -88,23 +87,31 @@ def wrap(*args, **kwargs):
8887
return wrap
8988

9089

91-
class Project(Project):
90+
class RHOpenShiftProject(Project, Vm):
9291

9392
"""
9493
We are assuming that a Project is a VM for purposes of simplicity for CFME-QE
9594
9695
"""
9796

97+
state_map = {
98+
'Pending': VmState.PENDING,
99+
'Running': VmState.RUNNING,
100+
'Succeeded': VmState.SUCCEEDED,
101+
'Failed': VmState.FAILED,
102+
'Unknown': VmState.UNKNOWN
103+
}
104+
98105
def __init__(self, system, raw=None, **kwargs):
99106
"""
100-
Construct a VMWareVirtualMachine instance
107+
Construct a RHOpenShiftProject instance
101108
102109
Args:
103-
system: instance of VMWareSystem
104-
raw: pyVmomi.vim.VirtualMachine object
105-
name: name of VM
110+
system: instance of OpenShiftSystem
111+
raw: openshift.dynamic.client.ResourceField
112+
name: name of Project
106113
"""
107-
super(Project, self).__init__(system, raw, **kwargs)
114+
super(RHOpenShiftProject, self).__init__(system, raw, **kwargs)
108115
self._name = raw.metadata.name if raw else kwargs.get('name')
109116
if not self._name:
110117
raise ValueError("missing required kwarg 'name'")
@@ -127,7 +134,6 @@ def _does_project_exist(self):
127134
else:
128135
return False
129136

130-
@property
131137
def get_quota(self):
132138
return self.system.ocp_client.resources.get(api_version='v1', kind='ResourceQuota').get(
133139
namespace=self.name)
@@ -151,6 +157,17 @@ def uuid(self):
151157
def ip(self):
152158
raise NotImplementedError
153159

160+
@property
161+
def creation_time(self):
162+
"""Detect the vm_creation_time either via uptime if non-zero, or by last boot time
163+
164+
The API provides no sensible way to actually get this value. The only way in which
165+
vcenter API MAY have this is by filtering through events
166+
167+
Return tz-naive datetime object
168+
"""
169+
raise NotImplementedError
170+
154171
def start(self):
155172
self.logger.info("starting vm/project %s", self.name)
156173
if self._does_project_exist:
@@ -187,7 +204,7 @@ def cleanup(self):
187204
return self.delete()
188205

189206

190-
class Pod(Vm):
207+
class RHOpenShiftPod(Vm):
191208
state_map = {
192209
'Pending': VmState.PENDING,
193210
'Running': VmState.RUNNING,
@@ -198,14 +215,14 @@ class Pod(Vm):
198215

199216
def __init__(self, system, raw=None, **kwargs):
200217
"""
201-
Construct a VMWareVirtualMachine instance
218+
Construct a RHOpenShiftPod instance
202219
203220
Args:
204-
system: instance of VMWareSystem
205-
raw: pyVmomi.vim.VirtualMachine object
206-
name: name of VM
221+
system: instance of OpenShiftSystem
222+
raw: openshift.dynamic.client.ResourceField
223+
name: name of Pod
207224
"""
208-
super(Pod, self).__init__(system, raw, **kwargs)
225+
super(RHOpenShiftPod, self).__init__(system, raw, **kwargs)
209226
self._name = raw.metadata.name if raw else kwargs.get('name')
210227
self._namespace = raw.metadata.namespace if raw else kwargs.get('namespace')
211228
if not self._name:
@@ -284,12 +301,12 @@ class OpenShiftTemplate(Template):
284301

285302
def __init__(self, system, raw=None, **kwargs):
286303
"""
287-
Construct a VMWareVirtualMachine instance
304+
Construct a OpenShiftTemplate instance
288305
289306
Args:
290-
system: instance of VMWareSystem
291-
raw: pyVmomi.vim.VirtualMachine object
292-
name: name of VM
307+
system: instance of OpenShiftSystem
308+
raw: openshift.dynamic.client.ResourceField
309+
name: name of Template
293310
"""
294311
super(OpenShiftTemplate, self).__init__(system, raw, **kwargs)
295312
self._name = raw.metadata.name if raw else kwargs.get('name')
@@ -686,19 +703,6 @@ def _k8s_client_connect(self):
686703
# Create a ApiClient with our config
687704
return kubeclient.ApiClient(k8_configuration)
688705

689-
# def _connect(self):
690-
#
691-
# self.dyn_client = DynamicClient(self.k8s_client)
692-
693-
# self.ociclient = ociclient
694-
# self.kclient = kubeclient
695-
# self.oapi_client = ociclient.ApiClient(config=config)
696-
# self.kapi_client = kubeclient.ApiClient(config=config)
697-
# self.o_api = ociclient.OapiApi(api_client=self.oapi_client)
698-
# self.k_api = kubeclient.CoreV1Api(api_client=self.kapi_client)
699-
# self.security_api = self.ociclient.SecurityOpenshiftIoV1Api(api_client=self.oapi_client)
700-
# self.batch_api = self.kclient.BatchV1Api(api_client=self.kapi_client) # for job api
701-
702706
@property
703707
def _identifying_attrs(self):
704708
"""
@@ -933,7 +937,7 @@ def get_pod(self, name, namespace=None):
933937
else:
934938
pod = self.get_ocp_obj(resource_type=self.v1_pod, name=name)
935939

936-
return Pod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
940+
return RHOpenShiftPod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
937941

938942
def create_vm(self, name, **kwargs):
939943
raise NotImplementedError('This function has not yet been implemented.')
@@ -950,7 +954,7 @@ def list_pods(self, namespace=None):
950954
list of wrapanapi.entities.Vm
951955
"""
952956
return [
953-
Pod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
957+
RHOpenShiftPod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
954958
for pod in self.v1_pod.get(namespace=namespace).items]
955959

956960
def wait_project_exist(self, name, wait=60):
@@ -976,22 +980,22 @@ def create_project(self, name, description=None, **kwargs):
976980

977981
project = self.v1_project.create(body=proj)
978982
self.wait_project_exist(name=name)
979-
return Project(system=self, name=project.metadata.name, raw=project)
983+
return RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
980984

981985
def find_projects(self, *args, **kwargs):
982986
raise NotImplementedError
983987

984988
def get_project(self, name):
985989
project = self.v1_project.get(name=name)
986990

987-
return Project(system=self, name=project.metadata.name, raw=project)
991+
return RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
988992

989993
get_vm = get_project
990994

991995
def list_project(self, namespace=None):
992996

993997
return [
994-
Project(system=self, name=project.metadata.name, raw=project)
998+
RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
995999
for project in self.v1_project.get(namespace=namespace).items]
9961000

9971001
list_vms = list_project
@@ -1847,7 +1851,6 @@ def read_pod_log(self, namespace, name):
18471851
"""
18481852
return self.v1_pod.log.get(name=name, namespace=namespace)
18491853

1850-
18511854
def start_vm(self, vm_name):
18521855
"""Starts a vm.
18531856

0 commit comments

Comments
 (0)