def uninstall_cluster(self, req, cluster_id, install_meta): """ Uninstall backend to a cluster. :param req: The WSGI/Webob Request object :raises HTTPBadRequest if x-install-cluster is missing """ self._enforce(req, 'uninstall_cluster') self._raise_404_if_cluster_deleted(req, cluster_id) uninstall_hosts = self._get_uninstall_hosts(req, install_meta) backends = get_deployment_backends( req, cluster_id, BACKENDS_UNINSTALL_ORDER) for backend in backends: backend_driver = driver.load_deployment_driver(backend) backend_driver.check_uninstall_hosts(req, cluster_id, uninstall_hosts) uninstall_thread = Thread( target=backend_driver.uninstall, args=( req, cluster_id, uninstall_hosts)) uninstall_thread.start() return {"status": "begin uninstall"}
def _backends_install(self): backends = get_deployment_backends( self.req, self.cluster_id, BACKENDS_INSTALL_ORDER) if not backends: LOG.info(_("No backends need to install.")) return self.cluster_id for backend in backends: backend_driver = driver.load_deployment_driver(backend) backend_driver.install(self.req, self.cluster_id)
def update_cluster(self, req, cluster_id, install_meta): """ upgrade cluster. """ os_handle = get_os_handle() self._enforce(req, 'update_cluster') self._raise_404_if_cluster_deleted(req, cluster_id) if not install_meta.get('version_id', None): msg = "upgrade version is null" raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") if not install_meta.get('hosts', None): #TODO: Push kolla code into target(openstack)-driver(kolla) if install_meta['update_object'] == "kolla": hosts = [] else: msg = "upgrade hosts is null!" raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") else: hosts = install_meta['hosts'] update_file = "" if install_meta.get('version_patch_id', None): version_patch = self.get_version_patch_meta_or_404( req, install_meta['version_patch_id']) update_file = version_patch['name'] elif install_meta.get('version_id', None): version = self.get_version_meta_or_404(req, install_meta['version_id']) update_file = version['name'] if install_meta['update_object'] in BACKENDS_UPGRADE_ORDER: backends = get_deployment_backends(req, cluster_id, BACKENDS_UPGRADE_ORDER) if not backends: LOG.info(_("No backends need to upgrade.")) return {"status": ""} for backend in backends: backend_driver = driver.load_deployment_driver(backend) update_thread = Thread( target=backend_driver.upgrade, args=(req, cluster_id, install_meta['version_id'], install_meta.get('version_patch_id', None), update_file, hosts)) update_thread.start() else: update_thread = Thread( target=os_handle.upgrade, args=(self, req, cluster_id, install_meta.get('version_id', None), install_meta.get('version_patch_id', None), update_file, hosts, install_meta.get('update_object', None))) update_thread.start() return {"status": "begin update"}
def _backends_install(self): backends = get_deployment_backends(self.req, self.cluster_id, BACKENDS_INSTALL_ORDER) if not backends: LOG.info(_("No backends need to install.")) return self.cluster_id for backend in backends: backend_driver = driver.load_deployment_driver(backend) backend_driver.install(self.req, self.cluster_id)
def update_progress(self, req, cluster_id): self._enforce(req, 'update_progress') self._raise_404_if_cluster_deleted(req, cluster_id) backends = get_deployment_backends( req, cluster_id, BACKENDS_UPGRADE_ORDER) all_nodes = {} for backend in backends: backend_driver = driver.load_deployment_driver(backend) nodes_process = backend_driver.upgrade_progress(req, cluster_id) all_nodes.update(nodes_process) return all_nodes
def update_progress(self, req, cluster_id): self._enforce(req, 'update_progress') self._raise_404_if_cluster_deleted(req, cluster_id) backends = get_deployment_backends(req, cluster_id, BACKENDS_UPGRADE_ORDER) all_nodes = {} for backend in backends: backend_driver = driver.load_deployment_driver(backend) nodes_process = backend_driver.upgrade_progress(req, cluster_id) all_nodes.update(nodes_process) return all_nodes
def uninstall_progress(self, req, cluster_id): self._enforce(req, 'uninstall_progress') self._raise_404_if_cluster_deleted(req, cluster_id) all_nodes = {} backends = get_deployment_backends( req, cluster_id, BACKENDS_UNINSTALL_ORDER) if not backends: LOG.info(_("No backends need to uninstall.")) return all_nodes for backend in backends: backend_driver = driver.load_deployment_driver(backend) nodes_process = backend_driver.uninstall_progress(req, cluster_id) all_nodes.update(nodes_process) return all_nodes
def uninstall_progress(self, req, cluster_id): self._enforce(req, 'uninstall_progress') self._raise_404_if_cluster_deleted(req, cluster_id) all_nodes = {} backends = get_deployment_backends(req, cluster_id, BACKENDS_UNINSTALL_ORDER) if not backends: LOG.info(_("No backends need to uninstall.")) return all_nodes for backend in backends: backend_driver = driver.load_deployment_driver(backend) nodes_process = backend_driver.uninstall_progress(req, cluster_id) all_nodes.update(nodes_process) return all_nodes
def update_disk_array(self, req, cluster_id): """ update backend Disk Array config for a cluster. :param req: The WSGI/Webob Request object :raises HTTPBadRequest if x-cluster is missing """ self._enforce(req, 'update_disk_array') self._raise_404_if_cluster_deleted(req, cluster_id) tecs_backend_name = 'tecs' backends = get_deployment_backends( req, cluster_id, BACKENDS_UNINSTALL_ORDER) if tecs_backend_name not in backends: message = "No tecs backend" LOG.info(_(message)) else: backend_driver = driver.load_deployment_driver(tecs_backend_name) message = backend_driver.update_disk_array(req, cluster_id) return {'status': message}
def update_disk_array(self, req, cluster_id): """ update backend Disk Array config for a cluster. :param req: The WSGI/Webob Request object :raises HTTPBadRequest if x-cluster is missing """ self._enforce(req, 'update_disk_array') self._raise_404_if_cluster_deleted(req, cluster_id) tecs_backend_name = 'tecs' backends = get_deployment_backends(req, cluster_id, BACKENDS_UNINSTALL_ORDER) if tecs_backend_name not in backends: message = "No tecs backend" LOG.info(_(message)) else: backend_driver = driver.load_deployment_driver(tecs_backend_name) message = backend_driver.update_disk_array(req, cluster_id) return {'status': message}
def export_db(self, req, install_meta): """ Export daisy db data to tecs.conf and HA.conf. :param req: The WSGI/Webob Request object :raises HTTPBadRequest if x-install-cluster is missing """ self._enforce(req, 'export_db') cluster_id = install_meta['cluster_id'] self._raise_404_if_cluster_deleted(req, cluster_id) all_config_files = {} backends = get_deployment_backends( req, cluster_id, BACKENDS_INSTALL_ORDER) if not backends: LOG.info(_("No backends need to export.")) return all_config_files for backend in backends: backend_driver = driver.load_deployment_driver(backend) backend_config_files = backend_driver.export_db(req, cluster_id) all_config_files.update(backend_config_files) return all_config_files
def export_db(self, req, install_meta): """ Export daisy db data to tecs.conf and HA.conf. :param req: The WSGI/Webob Request object :raises HTTPBadRequest if x-install-cluster is missing """ self._enforce(req, 'export_db') cluster_id = install_meta['cluster_id'] self._raise_404_if_cluster_deleted(req, cluster_id) all_config_files = {} backends = get_deployment_backends(req, cluster_id, BACKENDS_INSTALL_ORDER) if not backends: LOG.info(_("No backends need to export.")) return all_config_files for backend in backends: backend_driver = driver.load_deployment_driver(backend) backend_config_files = backend_driver.export_db(req, cluster_id) all_config_files.update(backend_config_files) return all_config_files
def uninstall_cluster(self, req, cluster_id, install_meta): """ Uninstall backend to a cluster. :param req: The WSGI/Webob Request object :raises HTTPBadRequest if x-install-cluster is missing """ self._enforce(req, 'uninstall_cluster') self._raise_404_if_cluster_deleted(req, cluster_id) uninstall_hosts = self._get_uninstall_hosts(req, install_meta) backends = get_deployment_backends(req, cluster_id, BACKENDS_UNINSTALL_ORDER) for backend in backends: backend_driver = driver.load_deployment_driver(backend) backend_driver.check_uninstall_hosts(req, cluster_id, uninstall_hosts) uninstall_thread = Thread(target=backend_driver.uninstall, args=(req, cluster_id, uninstall_hosts)) uninstall_thread.start() return {"status": "begin uninstall"}
def update_cluster(self, req, cluster_id, install_meta): """ upgrade cluster. """ os_handle = get_os_handle() self._enforce(req, 'update_cluster') self._raise_404_if_cluster_deleted(req, cluster_id) if not install_meta.get('version_id', None): msg = "upgrade version is null" raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") if not install_meta.get('hosts', None): #TODO: Push kolla code into target(openstack)-driver(kolla) if install_meta['update_object'] == "kolla": hosts = [] else: msg = "upgrade hosts is null!" raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") else: hosts = install_meta['hosts'] update_file = "" if install_meta.get('version_patch_id', None): version_patch = self.get_version_patch_meta_or_404( req, install_meta['version_patch_id']) update_file = version_patch['name'] elif install_meta.get('version_id', None): version = self.get_version_meta_or_404(req, install_meta['version_id']) update_file = version['name'] if install_meta['update_object'] in BACKENDS_UPGRADE_ORDER: backends = get_deployment_backends( req, cluster_id, BACKENDS_UPGRADE_ORDER) if not backends: LOG.info(_("No backends need to upgrade.")) return {"status": ""} for backend in backends: backend_driver = driver.load_deployment_driver(backend) update_thread = Thread(target=backend_driver.upgrade, args=(req, cluster_id, install_meta['version_id'], install_meta.get( 'version_patch_id', None), update_file, hosts)) update_thread.start() else: update_thread = Thread(target=os_handle.upgrade, args=(self, req, cluster_id, install_meta.get('version_id', None), install_meta.get('version_patch_id', None), update_file, hosts, install_meta.get('update_object', None))) update_thread.start() return {"status": "begin update"}
def update_role(self, req, id, role_meta): """ Updates an existing role with the registry. :param request: The WSGI/Webob Request object :param id: The opaque image identifier :retval Returns the updated image information as a mapping """ orig_role_meta = self.get_role_meta_or_404(req, id) role_service_list = registry.get_role_services(req.context, id) role_service_id_list = [role_service['service_id'] for role_service in role_service_list] role_host_info_list = registry.get_role_host_metadata(req.context, id) role_host_id_list = [role_host['host_id'] for role_host in role_host_info_list] if orig_role_meta['role_type'] == "CONTROLLER_HA": if not role_meta.get('docker_vg_size', orig_role_meta['docker_vg_size']): role_meta['docker_vg_size'] = '104448' if orig_role_meta['role_type'] != "CONTROLLER_HA" and role_meta.get( 'docker_vg_size', None): msg = _("only CONTROLLER_HA can be updated with docker_vg_size.") LOG.debug(msg) raise HTTPForbidden(explanation=msg, request=req, content_type="text/plain") self._check_role_update_parameters( req, role_meta, orig_role_meta, role_service_id_list, role_host_id_list) if orig_role_meta['role_type'] == "CONTROLLER_HA": cluster_meta = {} cluster_meta['public_vip'] = role_meta.get( 'public_vip') or role_meta.get('vip') if cluster_meta['public_vip']: cluster_meta = registry.update_cluster_metadata( req.context, orig_role_meta['cluster_id'], cluster_meta) params = dict() neutron_backends = registry.list_neutron_backend_metadata(req.context, **params) if neutron_backends and 'neutron_backends_array' in role_meta: for neutron_backend in neutron_backends: if neutron_backend.get('role_id') == id: registry.delete_neutron_backend_metadata( req.context, neutron_backend['id']) backends = get_backend() for backend in backends: backend_driver = driver.load_deployment_driver(backend) role_meta = backend_driver.config_neutron_backend( req, orig_role_meta, role_meta) self._enforce(req, 'modify_image') # orig_role_meta = self.get_role_meta_or_404(req, id) # Do not allow any updates on a deleted image. # Fix for LP Bug #1060930 if orig_role_meta['deleted']: msg = _("Forbidden to update deleted role.") raise HTTPForbidden(explanation=msg, request=req, content_type="text/plain") try: role_meta = registry.update_role_metadata(req.context, id, role_meta) except exception.Invalid as e: msg = (_("Failed to update role metadata. Got error: %s") % utils.exception_to_str(e)) LOG.warning(msg) raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") except exception.NotFound as e: msg = (_("Failed to find role to update: %s") % utils.exception_to_str(e)) LOG.warning(msg) raise HTTPNotFound(explanation=msg, request=req, content_type="text/plain") except exception.Forbidden as e: msg = (_("Forbidden to update role: %s") % utils.exception_to_str(e)) LOG.warning(msg) raise HTTPForbidden(explanation=msg, request=req, content_type="text/plain") except (exception.Conflict, exception.Duplicate) as e: LOG.warning(utils.exception_to_str(e)) raise HTTPConflict(body=_('Host operation conflicts'), request=req, content_type='text/plain') else: self.notifier.info('role.update', role_meta) return {'role_meta': role_meta}
def update_role(self, req, id, role_meta): """ Updates an existing role with the registry. :param request: The WSGI/Webob Request object :param id: The opaque image identifier :retval Returns the updated image information as a mapping """ orig_role_meta = self.get_role_meta_or_404(req, id) role_service_list = registry.get_role_services(req.context, id) role_service_id_list = [ role_service['service_id'] for role_service in role_service_list ] role_host_info_list = registry.get_role_host_metadata(req.context, id) role_host_id_list = [ role_host['host_id'] for role_host in role_host_info_list ] if orig_role_meta['role_type'] == "CONTROLLER_HA": if not role_meta.get('docker_vg_size', orig_role_meta['docker_vg_size']): role_meta['docker_vg_size'] = '104448' if orig_role_meta['role_type'] != "CONTROLLER_HA" and role_meta.get( 'docker_vg_size', None): msg = _("only CONTROLLER_HA can be updated with docker_vg_size.") LOG.debug(msg) raise HTTPForbidden(explanation=msg, request=req, content_type="text/plain") self._check_role_update_parameters(req, role_meta, orig_role_meta, role_service_id_list, role_host_id_list) if orig_role_meta['role_type'] == "CONTROLLER_HA": cluster_meta = {} cluster_meta['public_vip'] = role_meta.get( 'public_vip') or role_meta.get('vip') if cluster_meta['public_vip']: cluster_meta = registry.update_cluster_metadata( req.context, orig_role_meta['cluster_id'], cluster_meta) params = dict() neutron_backends = registry.list_neutron_backend_metadata( req.context, **params) if neutron_backends and 'neutron_backends_array' in role_meta: for neutron_backend in neutron_backends: if neutron_backend.get('role_id') == id: registry.delete_neutron_backend_metadata( req.context, neutron_backend['id']) backends = get_backend() for backend in backends: backend_driver = driver.load_deployment_driver(backend) role_meta = backend_driver.config_neutron_backend( req, orig_role_meta, role_meta) self._enforce(req, 'modify_image') # orig_role_meta = self.get_role_meta_or_404(req, id) # Do not allow any updates on a deleted image. # Fix for LP Bug #1060930 if orig_role_meta['deleted']: msg = _("Forbidden to update deleted role.") raise HTTPForbidden(explanation=msg, request=req, content_type="text/plain") try: role_meta = registry.update_role_metadata(req.context, id, role_meta) except exception.Invalid as e: msg = (_("Failed to update role metadata. Got error: %s") % utils.exception_to_str(e)) LOG.warning(msg) raise HTTPBadRequest(explanation=msg, request=req, content_type="text/plain") except exception.NotFound as e: msg = (_("Failed to find role to update: %s") % utils.exception_to_str(e)) LOG.warning(msg) raise HTTPNotFound(explanation=msg, request=req, content_type="text/plain") except exception.Forbidden as e: msg = (_("Forbidden to update role: %s") % utils.exception_to_str(e)) LOG.warning(msg) raise HTTPForbidden(explanation=msg, request=req, content_type="text/plain") except (exception.Conflict, exception.Duplicate) as e: LOG.warning(utils.exception_to_str(e)) raise HTTPConflict(body=_('Host operation conflicts'), request=req, content_type='text/plain') else: self.notifier.info('role.update', role_meta) return {'role_meta': role_meta}