def setUp(self): self.driver = VTAMDriver() self.resource = self.get_default_resource_to_reserve() self.slice_urn = "urn:publicid:IDN+ocf:i2cat:vtam+slice+mytestslice" self.expiration = datetime.utcnow() + timedelta(hours=1) self.reserved_resources = self.driver.reserve_vms( self.slice_urn, self.resource) self.reservation = Reservation.objects.get( projectName="ocf.i2cat.vtam.mytestslice")
def setUp(self): self.driver = VTAMDriver() self.resource = self.get_default_resource_to_reserve() self.slice_urn = "urn:publicid:IDN+ocf:i2cat:vtam+slice+mytestslice" self.expiration = datetime.utcnow() + timedelta(hours=1) self.reserved_resources = self.driver.reserve_vms(self.slice_urn, self.resource) self.reservation = Reservation.objects.get(projectName = "ocf.i2cat.vtam.mytestslice")
class TestReserveVM(unittest.TestCase): def setUp(self): self.driver = VTAMDriver() self.resource = self.get_default_resource_to_reserve() self.slice_urn = "urn:publicid:IDN+ocf:i2cat:vtam+slice+mytestslice" self.expiration = datetime.utcnow() + timedelta(hours=1) self.reserved_resources = self.driver.reserve_vms( self.slice_urn, self.resource) self.reservation = Reservation.objects.get( projectName="ocf.i2cat.vtam.mytestslice") def tearDown(self): self.reservation.delete() def get_default_resource_to_reserve(self): resource = ResourceMocker() resource.set_component_id( "urn:publicid:IDN+ocf:i2cat:vtam+node+Verdaguer") return resource def test_should_reserve_resource(self): self.assertFalse(self.reservation == None) def test_should_reserve_resource_with_project_name(self): self.assertEquals("ocf.i2cat.vtam.mytestslice", self.reservation.projectName) def test_should_reserve_resource_with_slice_name(self): self.assertEquals("ocf.i2cat.vtam.mytestslice", self.reservation.sliceName) def test_should_reserve_fake_vm_in_Verdaguer(self): server_name = self.reservation.server.name self.assertEquals("Verdaguer", server_name) def test_reserve_should_expire_in_an_hour(self): expiration = self.reservation.get_valid_until() expiration_formatted = datetime.strptime(expiration, '%Y-%m-%d %H:%M:%S.%f') self.assertEquals(self.expiration.hour, expiration_formatted.hour) def test_should_return_object(self): self.assertFalse(self.reserved_resources == None) def test_should_return_reservation_object(self): self.assertTrue(isinstance(self.reserved_resources, ResourceMocker))
class TestReserveVM(unittest.TestCase): def setUp(self): self.driver = VTAMDriver() self.resource = self.get_default_resource_to_reserve() self.slice_urn = "urn:publicid:IDN+ocf:i2cat:vtam+slice+mytestslice" self.expiration = datetime.utcnow() + timedelta(hours=1) self.reserved_resources = self.driver.reserve_vms(self.slice_urn, self.resource) self.reservation = Reservation.objects.get(projectName = "ocf.i2cat.vtam.mytestslice") def tearDown(self): self.reservation.delete() def get_default_resource_to_reserve(self): resource = ResourceMocker() resource.set_component_id( "urn:publicid:IDN+ocf:i2cat:vtam+node+Verdaguer") return resource def test_should_reserve_resource(self): self.assertFalse(self.reservation == None) def test_should_reserve_resource_with_project_name(self): self.assertEquals("ocf.i2cat.vtam.mytestslice", self.reservation.projectName) def test_should_reserve_resource_with_slice_name(self): self.assertEquals("ocf.i2cat.vtam.mytestslice", self.reservation.sliceName) def test_should_reserve_fake_vm_in_Verdaguer(self): server_name = self.reservation.server.name self.assertEquals("Verdaguer", server_name) def test_reserve_should_expire_in_an_hour(self): expiration = self.reservation.get_valid_until() expiration_formatted = datetime.strptime(expiration, '%Y-%m-%d %H:%M:%S.%f') self.assertEquals(self.expiration.hour, expiration_formatted.hour) def test_should_return_object(self): self.assertFalse(self.reserved_resources == None) def test_should_return_reservation_object(self): self.assertTrue(isinstance(self.reserved_resources, ResourceMocker))
class TestTranslatorToDict(unittest.TestCase): def setUp(self): self.driver = VTAMDriver() self.reservation = self.get_default_reservation() self.vm_params = self.driver.get_default_vm_parameters( self.reservation) def get_default_reservation(self): r = ReservationMocker() r.set_project_id("test-project") r.set_slice_id("test-slice") r.set_slice_name("test-slice-name") r.set_project_name("test-project-name") r.set_uuid("THIS-IS-THE-UUID-OF-A-VM") s = ServerMocker() s.set_uuid("THIS-IS-THE-UUID-OF-A-SERVER") s.set_virt_tech("paravirtualization") r.server = s return r def test_shoud_return_correct_default_vm_params(self): self.assertFalse(None in self.vm_params.values())
class TestTranslatorToDict(unittest.TestCase): def setUp(self): self.driver = VTAMDriver() self.reservation = self.get_default_reservation() self.vm_params = self.driver.get_default_vm_parameters(self.reservation) def get_default_reservation(self): r = ReservationMocker() r.set_project_id("test-project") r.set_slice_id("test-slice") r.set_slice_name("test-slice-name") r.set_project_name("test-project-name") r.set_uuid("THIS-IS-THE-UUID-OF-A-VM") s = ServerMocker() s.set_uuid("THIS-IS-THE-UUID-OF-A-SERVER") s.set_virt_tech("paravirtualization") r.server = s return r def test_shoud_return_correct_default_vm_params(self): self.assertFalse(None in self.vm_params.values())
def get_vt_am_driver(): driver = VTAMDriver() driver.set_config(VTAMConfig) return driver
def setUp(self): self.driver = VTAMDriver() self.reservation = self.get_default_reservation() self.vm_params = self.driver.get_default_vm_parameters( self.reservation)
def setUp(self): self.driver = VTAMDriver() self.reservation = self.get_default_reservation() self.vm_params = self.driver.get_default_vm_parameters(self.reservation)
def setUp(self): self.driver = VTAMDriver() self.vm_params = self.get_default_vm_params() self.vm_class = self.prepare_vm_class() self.driver.vm_dict_to_class(self.vm_params, self.vm_class)
class TestTranslatorToDict(unittest.TestCase): def setUp(self): self.driver = VTAMDriver() self.vm_params = self.get_default_vm_params() self.vm_class = self.prepare_vm_class() self.driver.vm_dict_to_class(self.vm_params, self.vm_class) def get_default_vm_params(self): return DEFAULT_VM_PARAMS def prepare_vm_class(self): rspec = XmlHelper.getSimpleActionQuery() actionClassEmpty = copy.deepcopy(rspec.query.provisioning.action[0]) actionClassEmpty.type_ = "create" rspec.query.provisioning.action.pop() return actionClassEmpty.server.virtual_machines[0] def test_should_set_correct_name(self): self.assertEquals(self.vm_params.get("name"), self.vm_class.name) def test_should_set_correct_uuid(self): self.assertEquals(self.vm_params.get("uuid"), self.vm_class.uuid) def test_should_set_correct_status(self): self.assertEquals(self.vm_params.get("state"), self.vm_class.status) def test_should_set_correct_project_id(self): self.assertEquals(self.vm_params.get("project-id"), self.vm_class.project_id) def test_should_set_correct_project_name(self): self.assertEquals(self.vm_params.get("project-name"), self.vm_class.project_name) def test_should_set_correct_slice_name(self): self.assertEquals(self.vm_params.get("slice-name"), self.vm_class.slice_name) def test_should_set_correct_slice_id(self): self.assertEquals(self.vm_params.get("slice-id"), self.vm_class.slice_id) def test_should_set_correct_operating_system_type(self): self.assertEquals(self.vm_params.get("operating-system-type"), self.vm_class.operating_system_type) def test_should_set_correct_operating_system_version(self): self.assertEquals(self.vm_params.get("operating-system-version"), self.vm_class.operating_system_version) def test_should_set_correct_operating_system_distro(self): self.assertEquals(self.vm_params.get("operating-system-distribution"), self.vm_class.operating_system_distribution) def test_should_set_correct_virtualization_type(self): self.assertEquals(self.vm_params.get("virtualization-type"), self.vm_class.virtualization_type) def test_should_set_correct_virtualization_setup_type(self): self.assertEquals(self.vm_params.get("virtualization-setup-type"), self.vm_class.xen_configuration.virtualization_setup_type) def test_should_set_correct_project_name(self): self.assertEquals(self.vm_params.get("server-id"), self.vm_class.server_id) def test_should_set_correct_memory(self): self.assertEquals(self.vm_params.get("memory-mb"), self.vm_class.xen_configuration.memory_mb) def test_should_set_correct_hd_setup_type(self): self.assertEquals(self.vm_params.get("hd-setup-type"), self.vm_class.xen_configuration.hd_setup_type) def test_should_set_correct_project_name(self): self.assertEquals(self.vm_params.get("hd-origin-path"), self.vm_class.xen_configuration.hd_origin_path)
def __init__(self): self.__driver = VTAMDriver() self.START_ACTION = "START" self.STOP_ACTION = "STOP" self.REBOOT_ACTION = "REBOOT" self.DELETE_ACTION = "DELETE"
class VTAMRM(ResourceManagerBase): def __init__(self): self.__driver = VTAMDriver() self.START_ACTION = "START" self.STOP_ACTION = "STOP" self.REBOOT_ACTION = "REBOOT" self.DELETE_ACTION = "DELETE" def get_version(self): return {} def get_resources(self, urns=None, geni_available=False): servers = list() if urns: for urn in urns: server = self.__driver.get_specific_server_and_vms(urn, geni_available) if type(server) == list: servers.extend(server) else: servers.append(server) return servers else: servers = self.__driver.get_all_servers(geni_available) return servers def create_resources(self, urns, expiration=None, users=list(), geni_best_effort=False): created_resources = list() for urn in urns: resource = self.__driver.create_vms(urn, expiration, users, geni_best_effort) if type(resource) == list: created_resources.extend(resource) else: created_resources.append(resource) return created_resources def reserve_resources(self, slice_urn, reservations, expiration=None, users=list()): reserved_resources = list() for r in reservations: reserved_resource = self.__driver.reserve_vms(slice_urn, r, expiration, users) if type(reserved_resource) == list(): reserved_resources.extend(reserved_resource) else: reserved_resources.append(reserved_resource) #reserved_resources = self.__update_reservation(reserved_resources) #TODO # Ignore those resources not reserved for manifest reserved_resources = filter(lambda x: x is not None, reserved_resources) return reserved_resources def delete_resources(self, urns, geni_best_effort=False): return self.__crud_resources(urns, geni_best_effort, self.DELETE_ACTION) def start_resources(self, urns, geni_best_effort=False): return self.__crud_resources(urns, geni_best_effort, self.START_ACTION) def stop_resources(self, urns, geni_best_effort=False): return self.__crud_resources(urns, geni_best_effort, self.STOP_ACTION) def reboot_resources(self, urns, geni_best_effort=False): return self.__crud_resources(urns, geni_best_effort, self.REBOOT_ACTION) def update_resources_users(self, urns, geni_best_effort=False, options=dict()): """ geni_update_users: Refresh the set of user accounts and installed SSH keys on the resource. Takes the option geni_users. This action creates any users specified that do not already exist, and sets the SSH keys for all users per the list of keys specified - including removing keys not explicitly listed. The geni_users option can be supplied using the --optionsfile argument. If not supplied that way, then users are read from the omni_config or clearinghouse slice members, as documented under createsliver. Note: the --optionsfile argument requires a file. Expected format: { "geni_users": [ { "urn": "urn:publicid:IDN+ch.geni.net+user+jdoe", "keys": ["ssh-rsa jdoegoodkey"] }, { "urn": "urn:publicid:IDN+ch.geni.net+user+jsmith", "keys": ["somekey", "someotherkey"] } ] } """ # NOTE that the user and keys can be passed in two ways: # a) the '--optionsfile' option # b) directly read from the OMNI config file # In any case, both will be available under 'options["geni_users"]' geni_users = options.get("geni_users", None) if not geni_users: # This translates into a BADARGS exception in the handler raise Exception("Missing user and keys (maybe config file not present, or --optionsfile argument not present") return self.__driver.update_keys(urns, geni_users, geni_best_effort) def cancel_update_resources_users(self, urns, geni_best_effort=False): return self.__driver.cancel_update_keys(urns, geni_best_effort) def retrieve_resources_url(self, urns, geni_best_effort=False): """ Return URI or way to access the VM. """ return self.__driver.retrieve_access_data(urns, geni_best_effort) def renew_resources(self, urns, expiration, geni_best_effort=False): resources = list() self.__driver.set_geni_best_effort_mode(geni_best_effort) for urn in urns: try: resource = self.__driver.renew_vms(urn, expiration) except Exception as e: raise e if type(resource) == list: resources.extend(resource) else: resources.append(resource) return resources def __crud_resources(self, urns, geni_best_effort, action): self.__driver.set_geni_best_effort_mode(geni_best_effort) resources = list() for urn in urns: if action == self.START_ACTION: resource = self.__driver.start_vm(urn) elif action == self.STOP_ACTION: resource = self.__driver.stop_vm(urn) elif action == self.REBOOT_ACTION: resource = self.__driver.reboot_vm(urn) elif action == self.DELETE_ACTION: resource = self.__driver.delete_vm(urn) if type(resource) == list: resources.extend(resource) else: resources.append(resource) return resources def get_driver(self): return self.__driver def set_driver(self, value): self.__driver = value