Skip to content

Commit

Permalink
Merge pull request #60 from BUEC528-HIL-QUADS/revert-59-sat
Browse files Browse the repository at this point in the history
Revert "MockInventoryDriver.py QuadsNativeInventoryDriver.py functions"
  • Loading branch information
vsemp authored Apr 24, 2017
2 parents 2bcf1e3 + 6694947 commit 23ff08d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 193 deletions.
4 changes: 4 additions & 0 deletions bin/quads.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from subprocess import call
from subprocess import check_call

sys.path.append(os.path.dirname(__file__) + "/../")
#from lib.hardware_services.hardware_service import set_hardware_service


logger = logging.getLogger('quads')
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)
Expand Down
48 changes: 44 additions & 4 deletions lib/Quads.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ def __init__(self, config, statedir, movecommand, datearg, syncstate, initialize
self.hardware_service_url = hardwareserviceurl


self.inventory_service.load_data(self, force, initialize)
if initialize:
self.quads_init_data(force)
try:
stream = open(config, 'r')
self.data = yaml.load(stream)
stream.close()
except Exception, ex:
self.logger.error(ex)
exit(1)

self.quads = QuadsData(self.data)
self._quads_history_init()
Expand Down Expand Up @@ -126,12 +134,32 @@ def _quads_history_init(self):

# we occasionally need to write the data back out
def quads_write_data(self, doexit = True):
self.inventory_service.write_data(self, doexit)
try:
stream = open(self.config, 'w')
self.data = {"clouds":self.quads.clouds.data, "hosts":self.quads.hosts.data, "history":self.quads.history.data, "cloud_history":self.quads.cloud_history.data}
stream.write( yaml.dump(self.data, default_flow_style=False))
if doexit:
exit(0)
except Exception, ex:
self.logger.error("There was a problem with your file %s" % ex)
if doexit:
exit(1)

# if passed --init, the config data is wiped.
# typically we will not want to continue execution if user asks to initialize
def quads_init_data(self, force):
self.inventory_service.init_data(self, force)
if not force:
if os.path.isfile(self.config):
self.logger.warn("Warning: " + self.config + " exists. Use --force to initialize.")
exit(1)
try:
stream = open(self.config, 'w')
data = {"clouds":{}, "hosts":{}, "history":{}, "cloud_history":{}}
stream.write( yaml.dump(data, default_flow_style=False))
exit(0)
except Exception, ex:
self.logger.error("There was a problem with your file %s" % ex)
exit(1)

# helper function called from other methods. Never called from main()
def _quads_find_current(self, host, datearg):
Expand Down Expand Up @@ -192,7 +220,19 @@ def quads_hosts_schedule(self,
# sync the statedir db for hosts with schedule
def quads_sync_state(self):
# sync state
self.inventory_service.sync_state(self)
if self.datearg is not None:
self.logger.error("--sync and --date are mutually exclusive.")
exit(1)
for h in sorted(self.quads.hosts.data.iterkeys()):
default_cloud, current_cloud, current_override = self._quads_find_current(h, self.datearg)
if not os.path.isfile(self.statedir + "/" + h):
try:
stream = open(self.statedir + "/" + h, 'w')
stream.write(current_cloud + '\n')
stream.close()
except Exception, ex:
self.logger.error("There was a problem with your file %s" % ex)
return

# list the hosts
def quads_list_hosts(self):
Expand Down
47 changes: 8 additions & 39 deletions lib/hardware_services/inventory_drivers/MockInventoryDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def list_clouds(self,quadsinstance):
def list_hosts(self,quadsinstance):
quadsinstance.quads.hosts.host_list()

def load_data(self, quadsinstance, force, initialize):
def load_data(self, quadsinstance, force):
if initialize:
quadsinstance.quads_init_data(force)
try:
Expand All @@ -151,45 +151,14 @@ def load_data(self, quadsinstance, force, initialize):
quadsinstance.logger.error(ex)
exit(1)

def write_data(self, quadsinstance, doexit):
try:
stream = open(quadsinstance.config, 'w')
quadsinstance.data = {"clouds":quadsinstance.quads.clouds.data,
"hosts":quadsinstance.quads.hosts.data, "history":quadsinstance.quads.history.data, "cloud_history":quadsinstance.quads.cloud_history.data}
stream.write( yaml.dump(quadsinstance.data, default_flow_style=False))
if doexit:
exit(0)
except Exception, ex:
quadsinstance.logger.error("There was a problem with your file %s" % ex)
if doexit:
exit(1)
def write_data(self, quadsinstance, doexit = True):
quadsinstance.quads_write_data_(doexit)

def sync_state(self, quadsinstance):
# sync state
if quadsinstance.datearg is not None:
quadsinstance.logger.error("--sync and --date are mutually exclusive.")
exit(1)
for h in sorted(quadsinstance.quads.hosts.data.iterkeys()):
default_cloud, current_cloud, current_override = quadsinstance._quads_find_current(h, quadsinstance.datearg)
if not os.path.isfile(quadsinstance.statedir + "/" + h):
try:
stream = open(quadsinstance.statedir + "/" + h, 'w')
stream.write(current_cloud + '\n')
stream.close()
except Exception, ex:
quadsinstance.logger.error("There was a problem with your file %s" % ex)
return
quadsinstance.quads_sync_state_()

def init_data(self, quadsinstance, force):
if not force:
if os.path.isfile(quadsinstance.config):
quadsinstance.logger.warn("Warning: " + quadsinstance.config + " exists. Use --force to initialize.")
exit(1)
try:
stream = open(quadsinstance.config, 'w')
data = {"clouds":{}, "hosts":{}, "history":{}, "cloud_history":{}}
stream.write( yaml.dump(data, default_flow_style=False))
exit(0)
except Exception, ex:
quadsinstance.logger.error("There was a problem with your file %s" % ex)
exit(1)
quadsinstance.quads_init_data_(force)



Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def list_clouds(self,quadsinstance):
def list_hosts(self,quadsinstance):
quadsinstance.quads.hosts.host_list()

def load_data(self, quadsinstance, force, initialize):
def load_data(self, quadsinstance, force):
if initialize:
quadsinstance.quads_init_data(force)
try:
Expand All @@ -153,45 +153,12 @@ def load_data(self, quadsinstance, force, initialize):
quadsinstance.logger.error(ex)
exit(1)

def write_data(self, quadsinstance, doexit):
try:
stream = open(quadsinstance.config, 'w')
quadsinstance.data = {"clouds":quadsinstance.quads.clouds.data,
"hosts":quadsinstance.quads.hosts.data, "history":quadsinstance.quads.history.data, "cloud_history":quadsinstance.quads.cloud_history.data}
stream.write( yaml.dump(quadsinstance.data, default_flow_style=False))
if doexit:
exit(0)
except Exception, ex:
quadsinstance.logger.error("There was a problem with your file %s" % ex)
if doexit:
exit(1)
def write_data(self, quadsinstance, doexit = True):
quadsinstance.quads_write_data(doexit)

def sync_state(self, quadsinstance):
# sync state
if quadsinstance.datearg is not None:
quadsinstance.logger.error("--sync and --date are mutually exclusive.")
exit(1)
for h in sorted(quadsinstance.quads.hosts.data.iterkeys()):
default_cloud, current_cloud, current_override = quadsinstance._quads_find_current(h, quadsinstance.datearg)
if not os.path.isfile(quadsinstance.statedir + "/" + h):
try:
stream = open(quadsinstance.statedir + "/" + h, 'w')
stream.write(current_cloud + '\n')
stream.close()
except Exception, ex:
quadsinstance.logger.error("There was a problem with your file %s" % ex)
return
quadsinstance.quads_sync_state()

def init_data(self, quadsinstance, force):
if not force:
if os.path.isfile(quadsinstance.config):
quadsinstance.logger.warn("Warning: " + quadsinstance.config + " exists. Use --force to initialize.")
exit(1)
try:
stream = open(quadsinstance.config, 'w')
data = {"clouds":{}, "hosts":{}, "history":{}, "cloud_history":{}}
stream.write( yaml.dump(data, default_flow_style=False))
exit(0)
except Exception, ex:
quadsinstance.logger.error("There was a problem with your file %s" % ex)
exit(1)
quadsinstance.quads_init_data(force)

4 changes: 2 additions & 2 deletions lib/hardware_services/inventory_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def list_hosts(self):
"""

@abstractmethod
def load_data(self, quads, force, initialize):
def load_data(self, quads, force):
""" TODO add documentation
"""

Expand All @@ -85,7 +85,7 @@ def sync_state(self, quads):
"""

@abstractmethod
def write_data(self, quads, doexit):
def write_data(self, quads, doexit = True):
""" TODO add documentation
"""

Expand Down
2 changes: 0 additions & 2 deletions lib/hardware_services/network_drivers/hil.yml

This file was deleted.

107 changes: 0 additions & 107 deletions lib/hardware_services/network_drivers/hilapi.py

This file was deleted.

0 comments on commit 23ff08d

Please sign in to comment.