Skip to content

Commit

Permalink
swanagent related jetez changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssendhil committed Feb 11, 2020
1 parent 9d4b5be commit 427b1ad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions example-app/jet.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
basename: "example"
comment: "JetEZ GO Example"
arch: "x86"
abi: "64"
files:
- source: hello
destination: /var/db/scripts/jet/hello
Empty file added example-app/scripts/activate.sh
Empty file.
22 changes: 19 additions & 3 deletions jet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def main():
shutil.rmtree(args.build)
os.makedirs(args.build)
os.makedirs('%s/contents' % args.build)
os.makedirs('%s/scripts' % args.build)
contents = "%s/contents/contents" % args.build
scripts = "%s/scripts/activate" % args.build
os.makedirs(contents)
contents_pkg = '%s/pkg' % contents
os.makedirs(contents_pkg)
Expand Down Expand Up @@ -117,6 +119,17 @@ def main():
with open(contents_symlink_file, "w") as f:
f.write(contents_symlink)

given_scripts_file = os.path.join(args.source, "scripts/activate.sh")
init_content = ""
with open(given_scripts_file, 'r') as file:
init_content = file.read()

scripts_file = '%s.sh' % scripts
log.info("create symlink file %s", scripts_file)
with open(scripts_file, "w") as f:
f.write(init_content)
os.chmod(scripts_file, 0o755)

log.info("sign manifest file %s" % content_manifest_file)
crypto.sign(content_manifest_file, "%s.sig" % content_manifest_file, args.key, args.cert)

Expand All @@ -128,13 +141,16 @@ def main():
shutil.rmtree(contents)

log.info("create package.xml")
utils.create_package_xml(project, args.version, package, args.build)
utils.create_package_xml(project, version, package, args.build)

package_manifest = "/set package_id=31 role=Provider_Daemon\n"
package_manifest_files = ["contents/contents.iso", "contents/contents.symlinks", "package.xml"]
package_manifest_files = ["contents/contents.iso", "contents/contents.symlinks", "scripts/activate.sh", "package.xml"]

for f in package_manifest_files:
package_manifest += "%s sha1=%s\n" % (f, crypto.generate_sha1(os.path.join(args.build, f)))
if "scripts" not in f:
package_manifest += "%s sha1=%s\n" % (f, crypto.generate_sha1(os.path.join(args.build, f)))
else:
package_manifest += "%s sha1=%s program_id=1\n" % (f, crypto.generate_sha1(os.path.join(args.build, f)))

package_manifest_file = os.path.join(args.build, "manifest")
log.info("create manifest file %s", package_manifest_file)
Expand Down
12 changes: 9 additions & 3 deletions jet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def load_project(project_file, version):
:rtype: dict
"""
with open(project_file , 'r') as f:
project_yaml = yaml.load(f)
project_yaml = yaml.load(f, Loader=yaml.FullLoader)

def required(d, k):
if k in d:
Expand All @@ -114,9 +114,11 @@ def required(d, k):
"basename": required(project_yaml, "basename"),
"files": [],
"comment": project_yaml.get("comment", "JET app %s" % project_yaml["basename"]),
"arch": project_yaml.get("arch", "x86"),
"abi": project_yaml.get("abi", "32"),
"arch": required(project_yaml, "arch"),
"abi": required(project_yaml, "abi"),
"copyright": project_yaml.get("copyright", "Copyright %s, Juniper Networks, Inc." % timestamp.year),
"mounted-action": project_yaml.get("mounted-action", "scripts/activate.sh"),
"deleting-action": project_yaml.get("deleting-action", "scripts/activate.sh"),
"package_id": project_yaml.get("package_id", 31),
"role": project_yaml.get("role", "Provider_Daemon"),
"date": timestamp.strftime("%Y%m%d"),
Expand Down Expand Up @@ -186,8 +188,10 @@ def package_xml_file(filename):
etree.SubElement(package_xml, "basename").text = project["basename"]
etree.SubElement(package_xml, "comment").text = "%s [%s]" % (project["comment"], version)
etree.SubElement(package_xml, "copyright").text = project["copyright"]
etree.SubElement(package_xml, "deleting-action").text = project["deleting-action"]
etree.SubElement(package_xml, "description").text = project["basename"]
etree.SubElement(package_xml, "mntname").text = "%s%s-%s" % (project["basename"], project["abi"], binascii.b2a_hex(os.urandom(4)).decode())
etree.SubElement(package_xml, "mounted-action").text = project["mounted-action"]
etree.SubElement(package_xml, "require").text = "junos-runtime32"
etree.SubElement(package_xml, "version").text = project["date"]
etree.SubElement(package_xml, "spin").text = project["time"]
Expand All @@ -201,5 +205,7 @@ def package_xml_file(filename):
dir = etree.SubElement(package_xml, "dir", name="contents")
package_xml_file("contents/contents.iso")
package_xml_file("contents/contents.symlinks")
dir = etree.SubElement(package_xml, "dir", name="scripts")
package_xml_file("scripts/activate.sh")
with open("%s/package.xml" % path, "w+") as f:
f.write(etree.tostring(package_xml, pretty_print=True).decode("utf8"))

0 comments on commit 427b1ad

Please sign in to comment.