- available_host_types = ResourceManager.getInstance().getAvailableHostTypes(lab)
- if hostprofile not in available_host_types:
- # TODO: handle deleting generic resource in this instance along with grb
- raise HostNotAvailable('Requested host type is not available. Please try again later. Host availability can be viewed in the "Hosts" tab to the left.')
-
- hostset = Host.objects.filter(lab=lab, profile=hostprofile).filter(booked=False).filter(working=True)
- if not hostset.exists():
- raise HostNotAvailable("Couldn't find any matching unbooked hosts")
-
- return True
-
-
-# Functions to create models
-
-def generate_grb(owner, lab, common_id):
- """Create a Generic Resource Bundle."""
- grbundle = GenericResourceBundle(owner=owner)
- grbundle.lab = lab
- grbundle.name = "grbundle for quick booking with uid " + common_id
- grbundle.description = "grbundle created for quick-deploy booking"
- grbundle.save()
-
- return grbundle
-
-
-def generate_gresource(bundle, hostname):
- """Create a Generic Resource."""
- if not re.match(r"(?=^.{1,253}$)(^([A-Za-z0-9-_]{1,62}\.)*[A-Za-z0-9-_]{1,63})$", hostname):
- raise InvalidHostnameException("Hostname must comply to RFC 952 and all extensions to it until this point")
- gresource = GenericResource(bundle=bundle, name=hostname)
- gresource.save()
-
- return gresource
-
-
-def generate_ghost(generic_resource, host_profile):
- """Create a Generic Host."""
- ghost = GenericHost()
- ghost.resource = generic_resource
- ghost.profile = host_profile
- ghost.save()
-
- return ghost
-
-
-def generate_config_bundle(owner, common_id, grbundle):
- """Create a Configuration Bundle."""
- cbundle = ConfigBundle()
- cbundle.owner = owner
- cbundle.name = "configbundle for quick booking with uid " + common_id
- cbundle.description = "configbundle created for quick-deploy booking"
- cbundle.bundle = grbundle
- cbundle.save()
-
- return cbundle
-
-
-def generate_opnfvconfig(scenario, installer, config_bundle):
- """Create an OPNFV Configuration."""
- opnfvconfig = OPNFVConfig()
- opnfvconfig.scenario = scenario
- opnfvconfig.installer = installer
- opnfvconfig.bundle = config_bundle
- opnfvconfig.save()
-
- return opnfvconfig
-
+ name = user.username + "'s Copy of '" + old_template.name + "'"
+ num_copies = ResourceTemplate.objects.filter(name__startswith=name).count()
+ template = ResourceTemplate.objects.create(
+ name=name if num_copies == 0 else name + " (" + str(num_copies) + ")",
+ xml=old_template.xml,
+ owner=user,
+ lab=old_template.lab,
+ description=old_template.description,
+ public=False,
+ temporary=True,
+ private_vlan_pool=old_template.private_vlan_pool,
+ public_vlan_pool=old_template.public_vlan_pool,
+ copy_of=old_template
+ )