def deploy(self, config, dependencies_changed=False, silent=False): exists = config.path in self.api.list_secrets() if exists: content = self.api.get_secret(config.path) if config.value: changed = content != config.value elif config.file_content: if isinstance(config.file_content, str): content = content.decode("utf-8") changed = content != config.file_content else: raise Exception( "Specified neither value nor file_content for secret") if not changed: print_if(not silent, "\tSecret already exists. No update needed.") return False print_if(not silent, "\tUpdating secret") self.api.write_secret(config.path, config.value, config.file_content, update=exists) print_if(not silent, "\tSecret updated.") return True else: print_if(not silent, "\tCreating secret") self.api.write_secret(config.path, config.value, config.file_content, update=exists) print_if(not silent, "\tSecret created.") return True
def deploy(self, config, dependencies_changed=False, silent=False): if config.compress: zip_obj = self._compress_zip(config.files[1]) size = zip_obj.tell() zip_obj.seek(0) hash = self._hash_for_file_list(config.files[1]) print_if(not silent, "\tUploading file to %s" % config.files[0]) self.api.upload_file(config.server, config.bucket, config.files[0], zip_obj, size, hash) print_if(not silent, "\tUploaded file to %s" % config.files[0]) return True else: changed = False for key, filename in config.files: with open(filename, "rb") as source_file: hash = md5_hash_bytes(source_file) source_file.seek(0) if not self.api.files_equal(config.server, config.bucket, key, hash): changed = True print_if(not silent, "\tUploading file to %s" % key) file_stat = os.stat(filename) self.api.upload_file(config.server, config.bucket, key, source_file, file_stat.st_size, hash) print_if(not silent, "\tUploaded file to %s" % key) if not changed: print_if(not silent, "\tNothing changed") return changed
def deploy(self, config, dependencies_changed=False, silent=False): print_if(not silent, "\tRunning command") parent_container_id, slave_id = self.api.get_container_id_and_slave_id_for_task( config.task) result = self.api.launch_nested_container(slave_id, parent_container_id, config.command.split(" ")) if config.print_output and not silent: print(result) print_if(not silent, "\tFinished.") return True
def deploy(self, config, dependencies_changed=False, silent=False): if self.api.does_job_exist(config.job_id): print_if(not silent, "\tUpdating existing job") self.api.update_job(config.job_definition) print_if(not silent, "\tUpdated job.") return True else: print_if(not silent, "\tCreating job") self.api.create_job(config.job_definition) print_if(not silent, "\tCreated job.") return True
def deploy(self, config, dependencies_changed=False, silent=False): repo = self._get_repo(config.name) if repo: if repo["uri"] != config.uri: print_if(not silent, "\tURIs do not match. Deleting old repository") self.api.delete_repository(config.name) else: print_if(not silent, "\tNothing changed.") return False print_if(not silent, "\tAdding repository") self.api.add_repository(config.name, config.uri, config.index) print_if(not silent, "\tFinished") return True
def deploy(self, config, dependencies_changed=False, silent=False): old_description = self.api.describe_service(config.service_name) package_version = config.package_version if not old_description: print_if(not silent, "\tInstalling framework") self.api.install_package(config.service_name, config.package_name, config.package_version, config.options) print_if(not silent, "\tWaiting for framework to start") self.marathon.wait_for_deployment(config.service_name) time.sleep(5) # Wait a few seconds for admin-lb to catch up if self.api.has_plans_api(config.service_name): print_if(not silent, "\tWaiting for deployment plan to finish") self.api.wait_for_plan_complete(config.service_name, "deploy") else: if old_description["package"]["version"] == config.package_version: package_version = None print_if(not silent, "\tUpdating framework") self.api.update_service(config.service_name, package_version, config.options) # Do not wait for completion after update, assume update is done in rolling fashion print_if(not silent, "\tFinished") return True
def deploy(self, config, dependencies_changed=False, silent=False): changed = False if not self._does_serviceaccount_exist(config.path): print_if(not silent, "\tCreating serviceaccount") self._create_serviceaccount(config.path, config.secret) changed = True else: print_if(not silent, "\tServiceaccount already exists. Not creating it.") existing_groups = self.bouncer.get_groups_for_user(config.path) existing_permissions = self.bouncer.get_permissions_for_user( config.path) existing_rids = self.bouncer.get_rids() print_if(not silent, "\tUpdating groups") # Update groups for group in existing_groups: if group not in config.groups: self.bouncer.remove_user_from_group(config.path, group) changed = True for group in config.groups: if group not in existing_groups: self.bouncer.add_user_to_group(config.path, group) changed = True # Update permissions print_if(not silent, "\tUpdating permissions") for rid, actions in existing_permissions.items(): target_actions = config.permissions.get(rid, list()) for action in actions: if action not in target_actions: self.bouncer.remove_permission_from_user( config.path, rid, action) changed = True for rid, actions in config.permissions.items(): if rid not in existing_rids: self.bouncer.create_permission(rid) for action in actions: if action not in existing_permissions.get(rid, list()): self.bouncer.add_permission_to_user( config.path, rid, action) changed = True return changed
def deploy(self, config, dependencies_changed=False, silent=False): if not self.api.ping(): print_if(not silent, "\tEdgeLB api not yet available. Waiting ...") waiting = 0 while not self.api.ping(): time.sleep(10) waiting += 1 if waiting > 12: print_if(not silent, "\tCould not reach edgelb api. Giving up") raise Exception("EdgeLB api not available.") exists = config.name in self.api.get_pools() if exists: print_if(not silent, "\tUpdating pool") self.api.update_pool(config.pool_config) print_if(not silent, "\tPool updated.") return True else: print_if(not silent, "\tCreating pool") self.api.create_pool(config.pool_config) print_if(not silent, "\tPool created.") return True