def get_raw_manifest_list(self): """Return the docker manifest list in json format Raises: ManifestListNotFound: [description] Returns: DICT: manifest.list.json content """ listpath = '/'.join([ self.artifactory_base, self._get_artifactory_repo( ), # We have to massage the repo for artifactory self.image.get_image_name(), self.image.get_tag(), "list.manifest.json" ]) list_path = ArtifactoryPath(listpath, auth=(self.artifactory_user, self.artifactory_key)) try: f = list_path.open() except FileNotFoundError as e: raise ManifestListNotFound(e) except RuntimeError as e: raise ManifestListNotFound(e) return json.loads(f.read().decode('utf-8'))
def pullArtifact(artifact, version, user=None, token=None): dpl = artifact.deploy file = "{filename}_v{version}.{ext}".format( filename=artifact.name, version=version, ext=artifact.file.split(".")[1]) url = "{url}/{repo}/{path}/{file}".format(url=dpl.url, repo=dpl.repo, path=dpl.path, file=file) if (ArtifactoryPath("{url}".format(url=url)).exists()): if (user == None): user = input("Please provide a valid Artifactory user: "******"Please provide a valid Artifactory token: ") print("Pulling {file} from {url}".format(file=file, url=url)) path = ArtifactoryPath(url, auth=(user, token)) with path.open() as fd: with open(file, "wb") as out: out.write(fd.read()) else: print("Artifact Not Found: {url}".format(url=url))
def download(): path = ArtifactoryPath( "http://artifactory.calormen.net:8040/artifactory/generic-local/test/numbers.txt", auth=('admin', 'f22-demo')) with path.open() as fd: with open("old.txt", "wb") as out: out.write(fd.read())
def get_latest_image(self,url): auth = str( base64.b64encode( bytes('%s:%s' % (cicd_user,cicd_pw ), 'utf-8') ), 'ascii' ).strip() headers = {'Authorization': 'Basic ' + auth} ''' FIND THE LATEST FILE NAME''' print(url) req = urllib.request.Request(url, headers=headers) response = urllib.request.urlopen(req) html = response.read() soup = BeautifulSoup(html, features="html.parser") last_link = soup.find_all('a', href=True)[-1] latest_file=last_link['href'] filepath = local_dir os.chdir(filepath) #file_url = url + latest_file ''' Download the binary file from Jfrog''' path = ArtifactoryPath(url,auth=(cicd_user, cicd_pw)) path.touch() for file in path: print('File =', file) path = ArtifactoryPath(file, auth=(cicd_user, cicd_pw)) print("file to be downloaded :" ,latest_file) print("File Path:",file) with path.open() as des: with open(latest_file, "wb") as out: out.write(des.read()) des.close() print("Extract the tar.gz file and upgrade the AP ") housing_tgz = tarfile.open(latest_file) housing_tgz.extractall() housing_tgz.close() return "pass" print("Extract the tar file, and copying the file to Linksys AP directory") #with open("/Users/syamadevi/Desktop/syama/ea8300/ap_sysupgrade_output.log", "a") as output: # subprocess.call("scp /Users/syamadevi/Desktop/syama/ea8300/openwrt-ipq40xx-generic-linksys_ea8300-squashfs-sysupgrade.bin [email protected]:/tmp/openwrt-ipq40xx-generic-linksys_ea8300-squashfs-sysupgrade.bin",shell=True, stdout=output, # stderr=output) print('SSH to Linksys and upgrade the file') '''
def getArtifact(type, version, artifact, dest): target = os.path.join(dest, '%s-%s.jar' % (artifact, version)) if not os.path.exists(target): print('Downloading artifact %s-%s.jar' % (artifact, version)) baseurl = '%s/%s/%s' % (ARTIFACTORY_URL, type.repositoryId, type.groupId.replace('.', '/')) url = '%s/%s/%s/%s-%s.jar' % (baseurl, artifact, version, artifact, version) path = ArtifactoryPath( url, auth=(os.environ.get('CORDA_ARTIFACTORY_USERNAME'), os.environ.get('CORDA_ARTIFACTORY_PASSWORD'))) with path.open() as fd: with open(target, 'wb') as out: out.write(fd.read()) return target
def download_packages(self): with open(self._config.depslock_path) as f: packages_path_in_repo = DepsTxtLockListFormatter.read_packages_from_lock_file( f) session = requests.Session() packages_not_found = [] output_path = self._config.output_path if output_path is not None and output_path != '': pathlib.Path(output_path).mkdir(parents=True, exist_ok=True) for package_path in packages_path_in_repo: errors = {} package_download_done = False for src in self._config.sources(): if package_download_done: break session.auth = src.get_auth_params().auth packages = src.generate_full_urls_from_package_path_in_repo( package_path) # packages = self.find_package_in_artifactory(src, package) for p in packages: try: ap = ArtifactoryPath(p, session=session) dst_path = os.path.join(output_path, ap.name) with ap.open() as input, open(dst_path, "wb") as output: shutil.copyfileobj(input, output) package_download_done = True self._log.info( f"Success {ap} downloaded to {dst_path}") break except RuntimeError as e: if isinstance(e.args[0], int): errors[ap] = http.HTTPStatus(e.args[0]) else: errors[ap] = e if not package_download_done: packages_not_found += [package_path] self._log.error( f"PACKAGE NOT FOUND {package_path}. Errors for attempts {errors}" ) if packages_not_found: raise CrosspmException( CROSSPM_ERRORCODE_PACKAGE_NOT_FOUND, 'Some package(s) not found: {}'.format( ', '.join(packages_not_found)))
def main(): # creating AnsibleModule object with acceptable attributes module = AnsibleModule(argument_spec=dict( name=dict(required=True, type='str'), jar_version=dict(required=True, type='str'), environment=dict(required=True, type='str'), ), supports_check_mode=True) # condition for check mode/dry run if module.check_mode: module.exit_json(changed=False) # initialising the passed attributes as variables name = module.params['name'] jar_version = module.params['jar_version'] environment = module.params['environment'] # killing the microservice if it is running on the server if is_running(name): pid = demolish() time.sleep(2) if is_running(name): msg = "Program could not be stopped. Please check the host." module.fail_json(msg=msg) else: program_status = "Program '{0}' having PID '{1}' has been killed on this host.".format( name, pid) else: program_status = "Program '{0}' is not running on this host.".format( name) # copying the properties file and timestamping the previous property file. Creating the property file path if it does not exist. property_dir = "/home/ngaurav/{0}/resources/".format(name) property_file = "/home/ngaurav/{0}/resources/application-{1}.properties".format( name, environment) property_src = "/root/test/application-{0}.properties".format(environment) if filepath_exists(property_file): timestamp(property_file) copy_reply = copy(property_src, property_file) property_file_status = "Property file has been timestamped. New property {0}.".format( copy_reply) elif filepath_exists(property_dir): file_copy_status = copy(property_src, property_file) property_file_status = "There exists no previous property file. {0} ".format( file_copy_status) else: path_create(property_dir) property_file_status = "File path has been created." # deleting previous backup jar and creating the backup directory if it does not exist. backup_jar = "/dev/shm/eSource/Backup_Deployment/Artifacts/{0}-{1}.jar".format( name, jar_version) backup_dir = "/dev/shm/eSource/Backup_Deployment/Artifacts/" current_jar = "/dev/shm/eSource/Current_Deployment/Artifacts/{0}-{1}.jar".format( name, jar_version) current_dir = "/dev/shm/eSource/Current_Deployment/Artifacts/" if filepath_exists(backup_jar): delete(backup_jar) backup_jar_status = "Backup jar has been deleted." elif filepath_exists(backup_dir): backup_jar_status = "Backup directory exists but there is no backup jar yet." else: path_create(backup_dir) backup_jar_status = "Backup directory did not exist previously. It has been created." # backing up the current jar to backup directory. Creating the current deployment directory if it does not exist. if filepath_exists(current_dir): copyjar_reply = copy(current_jar, backup_dir) current_jar_status = "The current jar {0} for backup".format( copyjar_reply) else: path_create(current_dir) current_jar_status = "The directory for current deployments did not exist. It has been created." if filepath_exists(current_jar): delete(current_jar) #downloading the latest jar and moving it to the current deployment path path = ArtifactoryPath( "http://ec2-34-210-28-18.us-west-2.compute.amazonaws.com:8081/artifactory/libs-release-local/com/wlt/cel/{0}/{1}/{0}-{1}.jar" .format(name, jar_version), auth=('admin', 'password')) with path.open() as fd: with open("{0}-{1}.jar".format(name, jar_version), "wb") as out: out.write(fd.read()) here = "/root/module/{0}-{1}.jar".format(name, jar_version) move(here, current_dir) jar_download_status = " Downloaded latest jar." #starting up jar and checking if it is running with backup steps in case new jar does not start delete_current_jar = '{0}{1}-{2}.jar'.format(current_dir, name, jar_version) p = subprocess.Popen( 'java -jar -Dspring.profiles.active={0} -Dspring.config.location={1} {2}{3}-{4}.jar' .format(environment, property_dir, current_dir, name, jar_version), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if is_running(name): running_jar_status = 'New jar has been started.' else: delete(delete_current_jar) move(backup_jar, current_dir) p = subprocess.Popen( 'java -jar -Dspring.profiles.active={0} -Dspring.config.location={1} {2}{3}-{4}.jar' .format(environment, property_dir, current_dir, name, jar_version), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if is_running(name): running_jar_status = "Failed jar has been removed. The backup jar has been started." else: running_jar_status = "Failed jar has been removed. The backup jar could not be started. Please check the host manually." module.exit_json(program_status=program_status, property_file_status=property_file_status, backup_jar_status=backup_jar_status, current_jar_status=current_jar_status, jar_download_status=jar_download_status, running_jar_status=running_jar_status)
with open("bambo-test.properties", "rb") as f: p.load(f) build = p["BUILD_NUMMBER"].data planName = p["REPO_NAME"].data print("BUILD NUMBER IS =====> " + build) print("REPO NAME IS =====> " + planName) url = os.environ[ 'bamboo_artifactory_url'] + "com/services/{0}/{1}-0.0.1-SNAPSHOT.war".format( build, planName) print("Artifactory URL ====> " + url) auth = (os.environ['bamboo_artifactory_username'], os.environ['bamboo_artifactory_password']) path = ArtifactoryPath(url, auth=auth) with path.open() as fd, open("{0}-0.0.1-SNAPSHOT.war".format(planName), "wb") as out: out.write(fd.read()) src = "{0}-0.0.1-SNAPSHOT.war".format(planName) dst = "C:\\apache-tomcat-9.0.44\\webapps\\{0}-0.0.1-SNAPSHOT.war".format( planName) shutil.copyfile( src, dst, ) print(" Deployment Sucessful") print("==================API Deployment Ends ====================") # curl -u admin:Welcome@123 -X GET "http://localhost:8082/artifactory/DEMO/com/services/1/employeservice-0.0.1-SNAPSHOT.war" -o "employeservice-0.0.1-SNAPSHOT.war"