Beispiel #1
0
def main():
    freta = Freta()
    versions = freta.versions()
    for image in freta.image.list():
        if (
            image["state"] == "Report available"
            and image["analysis_version"] != versions["analysis"]
        ):
            print("redoing %s" % image["image_id"])
            freta.image.analyze(image["image_id"])
def main():
    parser = argparse.ArgumentParser(
        description="Image VMs from the current 'az login' subscription")
    parser.add_argument("--query", help="Search query", required=True)
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--ids", nargs="+", help="Freta Image IDs")
    group.add_argument("--all", action="store_true", help="Search all VMs")
    args = parser.parse_args()

    expression = jmespath.compile(args.query)

    results = {}
    freta = Freta()
    for image in freta.image.list():
        if args.ids and image["image_id"] not in args.ids:
            continue
        if image["state"] != "Report available":
            continue
        raw_report = freta.image.artifact.get(image["image_id"], "report.json")
        report = json.loads(raw_report)
        result = expression.search(report)
        if not result:
            continue
        results[image["image_id"]] = {
            "name": image["machine_id"],
            "result": result
        }

    if results:
        print(json.dumps(results, sort_keys=True, indent=4))
def main():
    parser = argparse.ArgumentParser(description="Wait for images to finish processing")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--ids", nargs="+", help="Freta Image IDs")
    group.add_argument("--all", action="store_true", help="Search all VMs")
    args = parser.parse_args()

    freta = Freta()

    while True:
        done = True
        for image in freta.image.list():
            if args.ids and image["image_id"] not in args.ids:
                continue
            if image["state"] not in ["Report available", "Failed"]:
                print(
                    "waiting on", image["image_id"], image["machine_id"],
                )
                done = False

        if done:
            break
        time.sleep(10)

    print("done")
Beispiel #4
0
 def test_api_artfacts_without_scan(self):
     freta = Freta()
     image = freta.image.upload("freta-cli-unittest upload", "lime",
                                "eastus", "README.md")
     with self.assertRaises(Error):
         freta.image.artifact.get(image["image_id"], "image.lime")
     freta.image.delete(image["image_id"])
Beispiel #5
0
    def test_api_upload(self):
        freta = Freta()
        data = freta.image.upload("freta-cli-unit-test upload", "lime",
                                  "eastus", "README.md")
        self.assertIn("image_id", data)
        freta.image.delete(data["image_id"])

        data = freta.image.upload_sas("freta-cli-unit-test upload", "lime",
                                      "eastus")
        self.assertIn("image_id", data)
        self.verify_sas(data["image"]["sas_url"])
        self.verify_sas(data["profile"]["sas_url"])
        freta.image.delete(data["image_id"])
Beispiel #6
0
    def test_api_get_image_artifacts(self):
        freta = Freta()
        images = freta.image.list()
        for image in images:
            self.assertTrue(check_image(image))

        image = [x for x in images if x["state"] == "Report available"][0]
        artifacts = freta.image.artifact.list(image["image_id"])
        self.assertIsInstance(artifacts, list)
        self.assertIn("report.json", artifacts)

        # TODO: add report content validation
        content = freta.image.artifact.get(image["image_id"], "report.json")
        self.assertGreater(len(content), 10)
def snapshot_upload(vm, snapshot, region):
    data = run(
        'Get-VMSnapshot -VMName "{}" -Name "{}" | Select Id,Path'.format(
            vm, snapshot))

    if isinstance(data, list):
        data = data[-1]

    path = os.path.join(data["Path"], "Snapshots",
                        "%s.VMRS" % data["Id"].upper())
    name = "{} : {}".format(vm, snapshot)
    freta = Freta()
    upload = freta.image.upload(name, "vmrs", region, path)
    freta.image.analyze(upload["image_id"])
Beispiel #8
0
    def test_api_create_update_analyze_delete(self):
        freta = Freta()
        image_sas = freta.image.upload_sas("freta-cli-unittest-upload", "lime",
                                           "eastus")
        self.assertIn("sas_url", image_sas["image"])
        image_id = image_sas["image_id"]
        self.assertTrue(check_uuid(image_id))

        # no change
        image = freta.image.status(image_id)
        freta.image.update(image_id, name="this is a test name")
        # TODO machine_id is force set in mocking, so we only verify we didn't assert
        # image = self.check_diffs(image, freta.status(image_id), ["machine_id"])

        image = freta.image.status(image_id)
        freta.backend.upload_blob(image_sas["image"]["sas_url"], "README.md")
        freta.image.analyze(image_id)
        image = self.check_diffs(image, freta.image.status(image_id),
                                 ["state"])
        freta.image.delete(image_id)
Beispiel #9
0
 def __init__(self):
     self.az = get_client_from_cli_profile(ComputeManagementClient)
     self.freta = Freta()
     self.publisher = "Microsoft.Azure.Extensions"
     self.extension = "customScript"
Beispiel #10
0
def main():
    freta = Freta()
    for image in freta.image.list():
        if image["state"] == "Report available":
            print("redoing %s" % image["image_id"])
            freta.image.analyze(image["image_id"])
Beispiel #11
0
def main():
    """ Build & Execute Freta CLI """
    return execute_api(Freta(), [Endpoint], __version__)
Beispiel #12
0
 def test_api_search_filters(self):
     data = Freta().image.search_filters()
     self.assertIsInstance(data, list)
     self.assertIn("my_images_and_samples", data)
Beispiel #13
0
 def test_api_versions(self):
     data = Freta().versions()
     self.assertIsInstance(data, dict)
     self.assertIn("analysis", data)
Beispiel #14
0
 def test_api_regions(self):
     data = Freta().regions()
     self.assertIsInstance(data, dict)
     self.assertIn("eastus", data)
     self.assertEqual(data["eastus"]["name"], "East US")
Beispiel #15
0
 def test_api_formats(self):
     data = Freta().image.formats()
     self.assertIsInstance(data, dict)
     self.assertIn("lime", data)
     self.assertEqual(data["lime"], "LiME image")