def instance_stop(self, inst_id): (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst) try: if inst.topology.state != Topology.STATE_RUNNING: message = "Cannot start an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) deployer_class = self.__get_deployer_class(inst) deployer = deployer_class() try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_STOPPING inst.topology.save() nodes = inst.topology.get_nodes() (success, message) = self.__stop_vms(deployer, nodes) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_STOPPED inst.topology.save() log.info("Stopping Globus Online endpoints") try: eps = inst.topology.get_go_endpoints() self.__globusonline_stop(inst, eps) inst.topology.save() except GlobusOnlineException, goe: log.warning("Unable to stop GO endpoint/s: %s" % goe)
def instance_terminate(self, inst_id): (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst) try: if inst.topology.state in [Topology.STATE_NEW]: message = "Cannot terminate an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) deployer_class = self.__get_deployer_class(inst) deployer = deployer_class() try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_TERMINATING inst.topology.save() nodes = inst.topology.get_nodes() (success, message) = self.__terminate_vms(deployer, nodes) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) # Remove GO endpoints eps = inst.topology.get_go_endpoints() self.__globusonline_remove(inst, eps) inst.topology.state = Topology.STATE_TERMINATED inst.topology.save() log.info("Instances have been terminated.") return (API.STATUS_SUCCESS, "Success")
def instance_start(self, inst_id, extra_files, run_cmds): (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst) try: deployer_class = self.__get_deployer_class(inst) deployer = deployer_class(extra_files, run_cmds) try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) if inst.topology.state == Topology.STATE_NEW: resuming = False elif inst.topology.state == Topology.STATE_STOPPED: resuming = True else: message = "Cannot start an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) if not resuming: inst.topology.state = Topology.STATE_STARTING else: inst.topology.state = Topology.STATE_RESUMING inst.topology.save() if not resuming: try: eps = inst.topology.get_go_endpoints() self.__globusonline_pre_start(inst, eps) except GlobusOnlineException, goe: log.warning("Unable to create GO endpoint/s: %s" % goe)
def instance_stop(self, inst_id): (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst_id) try: if inst.topology.state != Topology.STATE_RUNNING: message = "Cannot start an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) deployer_class = self.__get_deployer_class(inst) deployer = deployer_class() try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_STOPPING inst.topology.save() nodes = inst.topology.get_nodes() (success, message) = self.__stop_vms(deployer, nodes) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_STOPPED inst.topology.save() log.info("Instances have been stopped running.") return (API.STATUS_SUCCESS, "Success")
def instance_start(self, inst_id, extra_files, run_cmds): (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst_id) try: deployer_class = self.__get_deployer_class(inst) deployer = deployer_class(extra_files, run_cmds) try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) if inst.topology.state == Topology.STATE_NEW: resuming = False elif inst.topology.state == Topology.STATE_STOPPED: resuming = True else: message = "Cannot start an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) if not resuming: inst.topology.state = Topology.STATE_STARTING else: inst.topology.state = Topology.STATE_RESUMING inst.topology.save() nodes = inst.topology.get_nodes() (success, message, node_vm) = self.__allocate_vms(deployer, nodes, resuming) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_CONFIGURING inst.topology.save() log.info("Instances are running.") for node, vm in node_vm.items(): deployer.post_allocate(node, vm) inst.topology.save() # Generate certificates if not resuming: inst.gen_certificates(force_hosts=False, force_users=False) else: inst.gen_certificates(force_hosts=True, force_users=False) inst.topology.gen_chef_ruby_file(inst.instance_dir + "/topology.rb") inst.topology.gen_hosts_file(inst.instance_dir + "/hosts") log.info("Setting up Globus Provision on instances") (success, message) = self.__configure_vms(deployer, node_vm) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.state = Topology.STATE_RUNNING inst.topology.save() return (API.STATUS_SUCCESS, "Success")
def instance_update(self, inst_id, topology_json, extra_files, run_cmds): try: (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst_id) if inst.topology.state != Topology.STATE_RUNNING: message = "Cannot update the topology of an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) deployer_class = self.__get_deployer_class(inst) deployer = deployer_class(extra_files, run_cmds) try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) if topology_json != None: old_topology = inst.topology try: (success, message, create_hosts, destroy_hosts) = inst.update_topology(topology_json) except ObjectValidationException, ove: message = "Error in topology file: %s" % ove return (API.STATUS_FAIL, message) nodes = inst.topology.get_nodes() if len(destroy_hosts) > 0: old_nodes = old_topology.get_nodes() log.info("Terminating hosts %s" % destroy_hosts) old_nodes = [n for n in old_nodes if n.id in destroy_hosts] (success, message) = self.__terminate_vms(deployer, old_nodes) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.save() if len(create_hosts) > 0: nodes = inst.topology.get_nodes() log.info("Allocating VMs for hosts %s" % create_hosts) new_nodes = [n for n in nodes if n.id in create_hosts] (success, message, node_vm) = self.__allocate_vms(deployer, new_nodes, resuming = False) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.save() for node, vm in node_vm.items(): deployer.post_allocate(node, vm) inst.topology.save() # Generate certificates inst.gen_certificates() inst.topology.gen_chef_ruby_file(inst.instance_dir + "/topology.rb") inst.topology.gen_hosts_file(inst.instance_dir + "/hosts")
def instance_update(self, inst_id, topology_json, extra_files, run_cmds): try: (success, message, inst) = self.__get_instance(inst_id) if not success: return (API.STATUS_FAIL, message) log.set_logging_instance(inst) if inst.topology.state == Topology.STATE_NEW: # If the topology is still in a New state, we simply # validate that the update is valid, and replace # the old topology. We don't need to deploy or # configure any hosts.. if topology_json != None: (success, message, topology_changes) = inst.update_topology(topology_json) if not success: message = "Error in topology file: %s" % message return (API.STATUS_FAIL, message) return (API.STATUS_SUCCESS, "Success") elif inst.topology.state not in (Topology.STATE_RUNNING, Topology.STATE_FAILED): message = "Cannot update the topology of an instance that is in state '%s'" % (Topology.state_str[inst.topology.state]) return (API.STATUS_FAIL, message) deployer_class = self.__get_deployer_class(inst) deployer = deployer_class(extra_files, run_cmds) try: deployer.set_instance(inst) except DeploymentException, de: message = "Deployer failed to initialize. %s " % de return (API.STATUS_FAIL, message) if topology_json != None: old_topology = inst.topology try: (success, message, topology_changes) = inst.update_topology(topology_json) if not success: return (API.STATUS_FAIL, message) except ObjectValidationException, ove: message = "Error in topology file: %s" % ove return (API.STATUS_FAIL, message) create_hosts = [] destroy_hosts = [] create_endpoints = [] remove_endpoints = [] if topology_changes.changes.has_key("domains"): for domain in topology_changes.changes["domains"].add: d = inst.topology.domains[domain] create_hosts += [n.id for n in d.nodes.values()] for domain in topology_changes.changes["domains"].remove: d = inst.topology.domains[domain].keys() destroy_hosts += [n.id for n in d.nodes.values()] for domain in topology_changes.changes["domains"].edit: if topology_changes.changes["domains"].edit[domain].changes.has_key("nodes"): nodes_changes = topology_changes.changes["domains"].edit[domain].changes["nodes"] create_hosts += nodes_changes.add destroy_hosts += nodes_changes.remove if topology_changes.changes["domains"].edit[domain].changes.has_key("go_endpoints"): ep_changes = topology_changes.changes["domains"].edit[domain].changes["go_endpoints"] if ep_changes.change_type == PropertyChange.ADD: create_endpoints += inst.topology.domains[domain].go_endpoints elif ep_changes.change_type == PropertyChange.REMOVE: remove_endpoints += old_topology.domains[domain].go_endpoints elif ep_changes.change_type == PropertyChange.EDIT: create_endpoints += ep_changes.add remove_endpoints += ep_changes.remove nodes = inst.topology.get_nodes() if len(destroy_hosts) > 0: old_nodes = old_topology.get_nodes() log.info("Terminating hosts %s" % destroy_hosts) old_nodes = [n for n in old_nodes if n.id in destroy_hosts] (success, message) = self.__terminate_vms(deployer, old_nodes) if not success: inst.topology.state = Topology.STATE_FAILED inst.topology.save() return (API.STATUS_FAIL, message) inst.topology.save() if len(create_endpoints) > 0: try: self.__globusonline_pre_start(inst, create_endpoints) except GlobusOnlineException, goe: log.warning("Unable to create GO endpoint/s: %s" % goe)