Skip to content

Instantly share code, notes, and snippets.

@RonnyPfannschmidt
Created July 4, 2016 10:38
Show Gist options
  • Save RonnyPfannschmidt/28775efd574770320f9da456e5828968 to your computer and use it in GitHub Desktop.
Save RonnyPfannschmidt/28775efd574770320f9da456e5828968 to your computer and use it in GitHub Desktop.
class foo(Element)
exists = sentaku.ContextualMethod()
@exists.implemented_for(ViaDB)
def exists(self):
"""
Checks if the PXE server already exists
"""
return self.db.exists("pxe_servers", name=self.name)
return self.impl.db.session.query(
self.impl.db["pxe_servers"]
).filter_by(
name=self.name
).count() > 0
@exists.implemented_for(ViaUI)
def exists(self):
"""
Checks if the PXE server already exists
"""
# ** Here we are talking to the Sentaku system and asking for the implementation object,
# ** or the endpoint object. This object is what enables us to "talk" to the endpoint, so
# ** in this example it provides force_navigate, a browser, and other UI related things.
# ** Over in the db module it will provide a db session.
# ** Notice also how the rest of the UI stuff, like pxe_tree remains unchanged. This is our
# ** desire, to leave as much of the objects code intact as possible.
return self.can_navigate_to(pxe_tree, self.name)
self.impl.force_navigate('infrastructure_pxe_servers')
try:
pxe_tree(self.name)
return True
except CandidateNotFound:
return False
except NoSuchElementException:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment