text
stringlengths
0
828
resources: Dict[str, Any] = {
""metadata"": {
""name"": f""homework-{hw_num}"",
""path"": str(prefix),
""modified_date"": date.today().strftime(""%B %d, %Y""),
},
""output_extension"": "".pdf"",
}
fw.write(combine_pdf_as_bytes(assignment_pdfs), resources, f""homework-{hw_num}"")
resources[""metadata""][""name""] = f""homework-{hw_num}-soln""
fw.write(combine_pdf_as_bytes(solution_pdfs), resources, f""homework-{hw_num}-soln"")"
1142,"def main(argv: Optional[Sequence[str]] = None) -> None:
""""""Parse arguments and process the homework assignment.""""""
parser = ArgumentParser(description=""Convert Jupyter Notebook assignments to PDFs"")
parser.add_argument(
""--hw"",
type=int,
required=True,
help=""Homework number to convert"",
dest=""hw_num"",
)
parser.add_argument(
""-p"",
""--problems"",
type=int,
help=""Problem numbers to convert"",
dest=""problems"",
nargs=""*"",
)
parser.add_argument(
""--by-hand"",
type=int,
help=""Problem numbers to be completed by hand"",
dest=""by_hand"",
nargs=""*"",
)
args = parser.parse_args(argv)
prefix = Path(f""homework/homework-{args.hw_num}"")
process(args.hw_num, args.problems, prefix=prefix, by_hand=args.by_hand)"
1143,"def get_object_by_name(content, object_type, name, regex=False):
'''
Get the vsphere object associated with a given text name
Source: https://github.com/rreubenur/vmware-pyvmomi-examples/blob/master/create_template.py
'''
container = content.viewManager.CreateContainerView(
content.rootFolder, [object_type], True
)
for c in container.view:
if regex:
if re.match(name, c.name):
return c
elif c.name == name:
return c"
1144,"def get_vm_by_name(content, name, regex=False):
'''
Get a VM by its name
'''
return get_object_by_name(content, vim.VirtualMachine, name, regex)"
1145,"def get_all(content, container, object_type):
'''
Get all items of a certain type
Example: get_all(content, vim.Datastore) return all datastore objects
'''
obj_list = list()
view_manager = content.viewManager
object_view = view_manager.CreateContainerView(
container, [object_type], True
)
for obj in object_view.view:
if isinstance(obj, object_type):
obj_list.append(obj)
object_view.Destroy()
return obj_list"
1146,"def get_datacenter(content, obj):
'''
Get the datacenter to whom an object belongs
'''
datacenters = content.rootFolder.childEntity
for d in datacenters:
dch = get_all(content, d, type(obj))
if dch is not None and obj in dch:
return d"
1147,"def get_all_vswitches(content):
'''
Get all the virtual switches
'''
vswitches = []
hosts = get_all_hosts(content)
for h in hosts:
for s in h.config.network.vswitch:
vswitches.append(s)
return vswitches"
1148,"def print_vm_info(vm):
'''
Print information for a particular virtual machine
'''
summary = vm.summary
print('Name : ', summary.config.name)