def _update_resource(self, context, transaction): """Actual Implementation that will Update the given Resource""" #Update the Attributes on each of the VIO Servers for vios in self.vioservers: vios_id = vios._get_resource_identifer() values = vios._get_resource_values(changes_only=True) db_api.vios_update(self._context, vios_id, values) #Retrieve the existing SEA's for the Host to figure out differences dbseas = db_api.sea_find_all(self._context, dict(host=self.host_name)) exist_seas = dict([(sea['id'], sea) for sea in dbseas]) new_seas = dict([(sea['id'], sea) for sea in self.seas]) #Determine whether the SEA needs to be Created or updated for sea in new_seas: #If the SEA already exists, we just want to update what changed if exist_seas.get(sea['id']) is not None: values = sea._get_resource_values(changes_only=True) db_api.sea_update(self._context, {'sea_id': sea['id']}, values, transaction) #If the SEA is new, then we want to create it in the database else: values = sea._get_resource_values(changes_only=False) db_api.sea_create(self._context, values) #Now we want to clean up any SEA's that no longer exist in the topology for sea in exist_seas: if new_seas.get(sea['id']) is None: db_api.sea_delete(self._context, sea['id']) #Retrieve the existing VEA's for the Host to figure out differences dbveas = db_api.vea_find_all(self._context, dict(host=self.host_name)) exist_veas = dict([(vea['id'], vea) for vea in dbveas]) new_veas = dict([(vea['id'], vea) for vea in self.veas]) #Determine whether the VEA needs to be Created or updated for vea in new_veas: #If the VEA already exists, we just want to update what changed if exist_veas.get(vea['id']) is not None: values = vea._get_resource_values(changes_only=True) db_api.vea_update(self._context, vea['id'], values, transaction) #If the VEA is new, then we want to create it in the database else: values = vea._get_resource_values(changes_only=False) db_api.vea_create(self._context, values) #Now we want to clean up any VEA's that no longer exist in the topology for vea in exist_veas: if new_veas.get(vea['id']) is None: db_api.vea_delete(self._context, vea['id'])
def _create_resource(self, context, transaction): """Actual Implementation that will Create the given Resource""" values = self._get_resource_values() sea = db_api.sea_create(context, values, transaction) self._hydrate_all_resource_attributes(sea)