Skip to content

Commit

Permalink
Fixing lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jawatts committed Jul 17, 2019
1 parent 183c2e1 commit 365f591
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
3 changes: 2 additions & 1 deletion wrapanapi/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

__all__ = [
'Template', 'TemplateMixin', 'Vm', 'VmState', 'VmMixin', 'Instance',
'PhysicalContainer', 'Server', 'ServerState', 'Stack', 'StackMixin'
'PhysicalContainer', 'Server', 'ServerState', 'Stack', 'StackMixin',
'Project', 'ProjectMixin'
]
2 changes: 1 addition & 1 deletion wrapanapi/entities/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Project(six.with_metaclass(ABCMeta, Entity)):
"""
Represents a project on a system
"""
@abstractproperty
@abstractmethod
def get_quota(self):
"""
Deploy a VM/instance with name 'vm_name' using this template
Expand Down
79 changes: 41 additions & 38 deletions wrapanapi/systems/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from openshift import client as ociclient
from wait_for import TimedOutError, wait_for

from wrapanapi.entities import (Template, Vm, VmMixin, VmState, ProjectMixin,
Project)
from wrapanapi.entities import (Template, Vm, VmMixin, VmState, ProjectMixin, Project)
from wrapanapi.systems.base import System


Expand Down Expand Up @@ -88,23 +87,31 @@ def wrap(*args, **kwargs):
return wrap


class Project(Project):
class RHOpenShiftProject(Project, Vm):

"""
We are assuming that a Project is a VM for purposes of simplicity for CFME-QE
"""

state_map = {
'Pending': VmState.PENDING,
'Running': VmState.RUNNING,
'Succeeded': VmState.SUCCEEDED,
'Failed': VmState.FAILED,
'Unknown': VmState.UNKNOWN
}

def __init__(self, system, raw=None, **kwargs):
"""
Construct a VMWareVirtualMachine instance
Construct a RHOpenShiftProject instance
Args:
system: instance of VMWareSystem
raw: pyVmomi.vim.VirtualMachine object
name: name of VM
system: instance of OpenShiftSystem
raw: openshift.dynamic.client.ResourceField
name: name of Project
"""
super(Project, self).__init__(system, raw, **kwargs)
super(RHOpenShiftProject, self).__init__(system, raw, **kwargs)
self._name = raw.metadata.name if raw else kwargs.get('name')
if not self._name:
raise ValueError("missing required kwarg 'name'")
Expand All @@ -127,7 +134,6 @@ def _does_project_exist(self):
else:
return False

@property
def get_quota(self):
return self.system.ocp_client.resources.get(api_version='v1', kind='ResourceQuota').get(
namespace=self.name)
Expand All @@ -151,6 +157,17 @@ def uuid(self):
def ip(self):
raise NotImplementedError

@property
def creation_time(self):
"""Detect the vm_creation_time either via uptime if non-zero, or by last boot time
The API provides no sensible way to actually get this value. The only way in which
vcenter API MAY have this is by filtering through events
Return tz-naive datetime object
"""
raise NotImplementedError

def start(self):
self.logger.info("starting vm/project %s", self.name)
if self._does_project_exist:
Expand Down Expand Up @@ -187,7 +204,7 @@ def cleanup(self):
return self.delete()


class Pod(Vm):
class RHOpenShiftPod(Vm):
state_map = {
'Pending': VmState.PENDING,
'Running': VmState.RUNNING,
Expand All @@ -198,14 +215,14 @@ class Pod(Vm):

def __init__(self, system, raw=None, **kwargs):
"""
Construct a VMWareVirtualMachine instance
Construct a RHOpenShiftPod instance
Args:
system: instance of VMWareSystem
raw: pyVmomi.vim.VirtualMachine object
name: name of VM
system: instance of OpenShiftSystem
raw: openshift.dynamic.client.ResourceField
name: name of Pod
"""
super(Pod, self).__init__(system, raw, **kwargs)
super(RHOpenShiftPod, self).__init__(system, raw, **kwargs)
self._name = raw.metadata.name if raw else kwargs.get('name')
self._namespace = raw.metadata.namespace if raw else kwargs.get('namespace')
if not self._name:
Expand Down Expand Up @@ -284,12 +301,12 @@ class OpenShiftTemplate(Template):

def __init__(self, system, raw=None, **kwargs):
"""
Construct a VMWareVirtualMachine instance
Construct a OpenShiftTemplate instance
Args:
system: instance of VMWareSystem
raw: pyVmomi.vim.VirtualMachine object
name: name of VM
system: instance of OpenShiftSystem
raw: openshift.dynamic.client.ResourceField
name: name of Template
"""
super(OpenShiftTemplate, self).__init__(system, raw, **kwargs)
self._name = raw.metadata.name if raw else kwargs.get('name')
Expand Down Expand Up @@ -686,19 +703,6 @@ def _k8s_client_connect(self):
# Create a ApiClient with our config
return kubeclient.ApiClient(k8_configuration)

# def _connect(self):
#
# self.dyn_client = DynamicClient(self.k8s_client)

# self.ociclient = ociclient
# self.kclient = kubeclient
# self.oapi_client = ociclient.ApiClient(config=config)
# self.kapi_client = kubeclient.ApiClient(config=config)
# self.o_api = ociclient.OapiApi(api_client=self.oapi_client)
# self.k_api = kubeclient.CoreV1Api(api_client=self.kapi_client)
# self.security_api = self.ociclient.SecurityOpenshiftIoV1Api(api_client=self.oapi_client)
# self.batch_api = self.kclient.BatchV1Api(api_client=self.kapi_client) # for job api

@property
def _identifying_attrs(self):
"""
Expand Down Expand Up @@ -933,7 +937,7 @@ def get_pod(self, name, namespace=None):
else:
pod = self.get_ocp_obj(resource_type=self.v1_pod, name=name)

return Pod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)
return RHOpenShiftPod(system=self, name=pod.metadata.name, namespace=pod.metadata.namespace, raw=pod)

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

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

project = self.v1_project.create(body=proj)
self.wait_project_exist(name=name)
return Project(system=self, name=project.metadata.name, raw=project)
return RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)

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

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

return Project(system=self, name=project.metadata.name, raw=project)
return RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)

get_vm = get_project

def list_project(self, namespace=None):

return [
Project(system=self, name=project.metadata.name, raw=project)
RHOpenShiftProject(system=self, name=project.metadata.name, raw=project)
for project in self.v1_project.get(namespace=namespace).items]

list_vms = list_project
Expand Down Expand Up @@ -1847,7 +1851,6 @@ def read_pod_log(self, namespace, name):
"""
return self.v1_pod.log.get(name=name, namespace=namespace)


def start_vm(self, vm_name):
"""Starts a vm.
Expand Down

0 comments on commit 365f591

Please sign in to comment.