Exemplo n.º 1
0
    def sync_with_hypervisor(vmachineguid, storagedriver_id=None):
        """
        Updates a given vmachine with data retrieved from a given pmachine
        :param vmachineguid: Guid of the virtual machine
        :param storagedriver_id: Storage Driver hosting the vmachine
        """
        try:
            vmachine = VMachine(vmachineguid)
        except Exception as ex:
            VMachineController._logger.info('Cannot get VMachine object: {0}'.format(str(ex)))
            raise

        vm_object = None
        if vmachine.pmachine.mgmtcenter and storagedriver_id is not None and vmachine.devicename is not None:
            try:
                mgmt_center = Factory.get_mgmtcenter(vmachine.pmachine)
                storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
                VMachineController._logger.info('Syncing vMachine (name {0}) with Management center {1}'.format(vmachine.name, vmachine.pmachine.mgmtcenter.name))
                vm_object = mgmt_center.get_vm_agnostic_object(devicename=vmachine.devicename,
                                                               ip=storagedriver.storage_ip,
                                                               mountpoint=storagedriver.mountpoint)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from management center: {0}'.format(str(ex)))

        if vm_object is None and storagedriver_id is None and vmachine.hypervisor_id is not None and vmachine.pmachine is not None:
            try:
                # Only the vmachine was received, so base the sync on hypervisor id and pmachine
                hypervisor = Factory.get(vmachine.pmachine)
                VMachineController._logger.info('Syncing vMachine (name {0})'.format(vmachine.name))
                vm_object = hypervisor.get_vm_agnostic_object(vmid=vmachine.hypervisor_id)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from hypervisor: {0}'.format(str(ex)))

        if vm_object is None and storagedriver_id is not None and vmachine.devicename is not None:
            try:
                # Storage Driver id was given, using the devicename instead (to allow hypervisor id updates
                # which can be caused by re-adding a vm to the inventory)
                pmachine = PMachineList.get_by_storagedriver_id(storagedriver_id)
                storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
                hypervisor = Factory.get(pmachine)
                if not hypervisor.file_exists(storagedriver, hypervisor.clean_vmachine_filename(vmachine.devicename)):
                    return
                vmachine.pmachine = pmachine
                vmachine.save()

                VMachineController._logger.info('Syncing vMachine (device {0}, ip {1}, mountpoint {2})'.format(vmachine.devicename,
                                                                                                               storagedriver.storage_ip,
                                                                                                               storagedriver.mountpoint))
                vm_object = hypervisor.get_vm_object_by_devicename(devicename=vmachine.devicename,
                                                                   ip=storagedriver.storage_ip,
                                                                   mountpoint=storagedriver.mountpoint)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from hypervisor using devicename: {0}'.format(str(ex)))

        if vm_object is None:
            message = 'Not enough information to sync vmachine'
            VMachineController._logger.info('Error: {0}'.format(message))
            raise RuntimeError(message)

        VMachineController.update_vmachine_config(vmachine, vm_object)
Exemplo n.º 2
0
    def sync_with_hypervisor(vmachineguid, storagedriver_id=None):
        """
        Updates a given vmachine with data retrieved from a given pmachine
        :param vmachineguid: Guid of the virtual machine
        :param storagedriver_id: Storage Driver hosting the vmachine
        """
        try:
            vmachine = VMachine(vmachineguid)
        except Exception as ex:
            VMachineController._logger.info('Cannot get VMachine object: {0}'.format(str(ex)))
            raise

        vm_object = None
        if vmachine.pmachine.mgmtcenter and storagedriver_id is not None and vmachine.devicename is not None:
            try:
                mgmt_center = Factory.get_mgmtcenter(vmachine.pmachine)
                storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
                VMachineController._logger.info('Syncing vMachine (name {0}) with Management center {1}'.format(vmachine.name, vmachine.pmachine.mgmtcenter.name))
                vm_object = mgmt_center.get_vm_agnostic_object(devicename=vmachine.devicename,
                                                               ip=storagedriver.storage_ip,
                                                               mountpoint=storagedriver.mountpoint)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from management center: {0}'.format(str(ex)))

        if vm_object is None and storagedriver_id is None and vmachine.hypervisor_id is not None and vmachine.pmachine is not None:
            try:
                # Only the vmachine was received, so base the sync on hypervisor id and pmachine
                hypervisor = Factory.get(vmachine.pmachine)
                VMachineController._logger.info('Syncing vMachine (name {0})'.format(vmachine.name))
                vm_object = hypervisor.get_vm_agnostic_object(vmid=vmachine.hypervisor_id)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from hypervisor: {0}'.format(str(ex)))

        if vm_object is None and storagedriver_id is not None and vmachine.devicename is not None:
            try:
                # Storage Driver id was given, using the devicename instead (to allow hypervisor id updates
                # which can be caused by re-adding a vm to the inventory)
                pmachine = PMachineList.get_by_storagedriver_id(storagedriver_id)
                storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
                hypervisor = Factory.get(pmachine)
                if not hypervisor.file_exists(storagedriver, hypervisor.clean_vmachine_filename(vmachine.devicename)):
                    return
                vmachine.pmachine = pmachine
                vmachine.save()

                VMachineController._logger.info('Syncing vMachine (device {0}, ip {1}, mountpoint {2})'.format(vmachine.devicename,
                                                                                                               storagedriver.storage_ip,
                                                                                                               storagedriver.mountpoint))
                vm_object = hypervisor.get_vm_object_by_devicename(devicename=vmachine.devicename,
                                                                   ip=storagedriver.storage_ip,
                                                                   mountpoint=storagedriver.mountpoint)
            except Exception as ex:
                VMachineController._logger.info('Error while fetching vMachine info from hypervisor using devicename: {0}'.format(str(ex)))

        if vm_object is None:
            message = 'Not enough information to sync vmachine'
            VMachineController._logger.info('Error: {0}'.format(message))
            raise RuntimeError(message)

        VMachineController.update_vmachine_config(vmachine, vm_object)
Exemplo n.º 3
0
    def update_vdisk_name(volume_id, old_name, new_name):
        """
        Update a vDisk name using Management Center: set new name
        """
        vdisk = None
        for mgmt_center in MgmtCenterList.get_mgmtcenters():
            mgmt = Factory.get_mgmtcenter(mgmt_center = mgmt_center)
            try:
                disk_info = mgmt.get_vdisk_device_info(volume_id)
                device_path = disk_info['device_path']
                vpool_name = disk_info['vpool_name']
                vp = VPoolList.get_vpool_by_name(vpool_name)
                file_name = os.path.basename(device_path)
                vdisk = VDiskList.get_by_devicename_and_vpool(file_name, vp)
                if vdisk:
                    break
            except Exception as ex:
                logger.info('Trying to get mgmt center failed for disk {0} with volume_id {1}. {2}'.format(old_name, volume_id, ex))
        if not vdisk:
            logger.error('No vdisk found for name {0}'.format(old_name))
            return

        vpool = vdisk.vpool
        mutex = VolatileMutex('{}_{}'.format(old_name, vpool.guid if vpool is not None else 'none'))
        try:
            mutex.acquire(wait=5)
            vdisk.name = new_name
            vdisk.save()
        finally:
            mutex.release()
Exemplo n.º 4
0
    def update_vdisk_name(volume_id, old_name, new_name):
        """
        Update a vDisk name using Management Center: set new name
        """
        vdisk = None
        for mgmt_center in MgmtCenterList.get_mgmtcenters():
            mgmt = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
            try:
                disk_info = mgmt.get_vdisk_device_info(volume_id)
                device_path = disk_info['device_path']
                vpool_name = disk_info['vpool_name']
                vp = VPoolList.get_vpool_by_name(vpool_name)
                file_name = os.path.basename(device_path)
                vdisk = VDiskList.get_by_devicename_and_vpool(file_name, vp)
                if vdisk:
                    break
            except Exception as ex:
                logger.info(
                    'Trying to get mgmt center failed for disk {0} with volume_id {1}. {2}'
                    .format(old_name, volume_id, ex))
        if not vdisk:
            logger.error('No vdisk found for name {0}'.format(old_name))
            return

        vpool = vdisk.vpool
        mutex = VolatileMutex('{}_{}'.format(
            old_name, vpool.guid if vpool is not None else 'none'))
        try:
            mutex.acquire(wait=5)
            vdisk.name = new_name
            vdisk.save()
        finally:
            mutex.release()
Exemplo n.º 5
0
 def create(self, request):
     """
     Creates a Management Center
     """
     serializer = FullSerializer(
         MgmtCenter,
         instance=MgmtCenter(),
         data=request.DATA,
         allow_passwords=True)
     if serializer.is_valid():
         mgmt_center = serializer.object
         duplicate = MgmtCenterList.get_by_ip(mgmt_center.ip)
         if duplicate is None:
             try:
                 mgmt_center_client = Factory.get_mgmtcenter(
                     mgmt_center=mgmt_center)
                 is_mgmt_center = mgmt_center_client.test_connection()
             except Exception as ex:
                 logger.debug('Management center testing: {0}'.format(ex))
                 raise NotAcceptable('The given information is invalid.')
             if not is_mgmt_center:
                 raise NotAcceptable(
                     'The given information is not for a Management center.'
                 )
             mgmt_center.save()
             return Response(
                 serializer.data, status=status.HTTP_201_CREATED)
         else:
             raise NotAcceptable(
                 'A Mangement Center with this ip already exists.')
     else:
         return Response(
             serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 6
0
 def _hosts(self):
     """
     Returns all hosts (not only those known to OVS) managed by the Management center
     """
     mgmt_center = Factory.get_mgmtcenter(mgmt_center=self)
     if mgmt_center is not None:
         return mgmt_center.get_hosts()
     else:
         return {}
Exemplo n.º 7
0
 def _hosts(self):
     """
     Returns all hosts (not only those known to OVS) managed by the Management center
     """
     mgmt_center = Factory.get_mgmtcenter(mgmt_center=self)
     if mgmt_center is not None:
         return mgmt_center.get_hosts()
     else:
         return {}
Exemplo n.º 8
0
 def unconfigure_vpool_for_host(pmachine_guid, vpool_guid):
     pmachine = PMachine(pmachine_guid)
     mgmt_center_client = None
     try:
         mgmt_center_client = Factory.get_mgmtcenter(pmachine=pmachine)
     except Exception as ex:
         logger.error('Cannot get management center client: {0}'.format(ex))
     if mgmt_center_client is not None:
         logger.info('Unconfiguring vPool {0} on host {1}'.format(vpool_guid, pmachine.name))
         mgmt_center_client.unconfigure_vpool_for_host(vpool_guid, False, pmachine.ip)
Exemplo n.º 9
0
 def _host_status(self):
     """
     Returns the host status as reported by the management center (e.g. vCenter Server)
     """
     mgmtcentersdk = Factory.get_mgmtcenter(self)
     if mgmtcentersdk:
         if self.hypervisor_id:
             return mgmtcentersdk.get_host_status_by_pk(self.hypervisor_id)
         if self.ip:
             return mgmtcentersdk.get_host_status_by_ip(self.ip)
     return 'UNKNOWN'
Exemplo n.º 10
0
 def _host_status(self):
     """
     Returns the host status as reported by the management center (e.g. vCenter Server)
     """
     mgmtcentersdk = hvFactory.get_mgmtcenter(self)
     if mgmtcentersdk:
         if self.hypervisor_id:
             return mgmtcentersdk.get_host_status_by_pk(self.hypervisor_id)
         if self.ip:
             return mgmtcentersdk.get_host_status_by_ip(self.ip)
     return 'UNKNOWN'
Exemplo n.º 11
0
 def unconfigure_vpool_for_host(pmachine_guid, vpool_guid):
     pmachine = PMachine(pmachine_guid)
     mgmt_center_client = None
     try:
         mgmt_center_client = Factory.get_mgmtcenter(pmachine=pmachine)
     except Exception as ex:
         logger.error('Cannot get management center client: {0}'.format(ex))
     if mgmt_center_client is not None:
         logger.info('Unconfiguring vPool {0} on host {1}'.format(
             vpool_guid, pmachine.name))
         mgmt_center_client.unconfigure_vpool_for_host(
             vpool_guid, False, pmachine.ip)
Exemplo n.º 12
0
    def is_host_configured(pmachine_guid):
        pmachine = PMachine(pmachine_guid)
        mgmt_center_client = None
        try:
            mgmt_center_client = Factory.get_mgmtcenter(pmachine=pmachine)
        except Exception as ex:
            if pmachine.mgmtcenter_guid:
                logger.error('Cannot get management center client: {0}'.format(ex))

        if mgmt_center_client is not None:
            return mgmt_center_client.is_host_configured(pmachine.ip)
        return False
Exemplo n.º 13
0
    def is_host_configured(pmachine_guid):
        pmachine = PMachine(pmachine_guid)
        mgmt_center_client = None
        try:
            mgmt_center_client = Factory.get_mgmtcenter(pmachine=pmachine)
        except Exception as ex:
            if pmachine.mgmtcenter_guid:
                MgmtCenterController._logger.error(
                    'Cannot get management center client: {0}'.format(ex))

        if mgmt_center_client is not None:
            return mgmt_center_client.is_host_configured(pmachine.ip)
        return False
Exemplo n.º 14
0
 def unconfigure_host(pmachine_guid, mgmtcenter_guid, update_link):
     pmachine = PMachine(pmachine_guid)
     mgmt_center = MgmtCenter(mgmtcenter_guid)
     mgmt_center_client = None
     try:
         mgmt_center_client = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
     except Exception as ex:
         logger.error('Cannot get management center client: {0}'.format(ex))
     if mgmt_center_client is not None:
         logger.info('Unconfiguring host {0} from management center {1}'.format(pmachine.name, mgmt_center.name))
         mgmt_center_client.unconfigure_host(pmachine.ip)
         if update_link is True:
             pmachine.mgmtcenter = None
             pmachine.save()
Exemplo n.º 15
0
    def sync_with_mgmtcenter(disk, pmachine, storagedriver):
        """
        Update disk info using management center (if available)
         If no management center, try with hypervisor
         If no info retrieved, use devicename
        @param disk: vDisk hybrid (vdisk to be updated)
        @param pmachine: pmachine hybrid (pmachine running the storagedriver)
        @param storagedriver: storagedriver hybrid (storagedriver serving the vdisk)
        """
        disk_name = None
        if pmachine.mgmtcenter is not None:
            logger.debug(
                'Sync vdisk {0} with management center {1} on storagedriver {2}'
                .format(disk.name, pmachine.mgmtcenter.name,
                        storagedriver.name))
            mgmt = Factory.get_mgmtcenter(mgmt_center=pmachine.mgmtcenter)
            volumepath = disk.devicename
            mountpoint = storagedriver.mountpoint
            devicepath = '{0}/{1}'.format(mountpoint, volumepath)
            try:
                disk_mgmt_center_info = mgmt.get_vdisk_model_by_devicepath(
                    devicepath)
                if disk_mgmt_center_info is not None:
                    disk_name = disk_mgmt_center_info.get('name')
            except Exception as ex:
                logger.error(
                    'Failed to sync vdisk {0} with mgmt center {1}. {2}'.
                    format(disk.name, pmachine.mgmtcenter.name, str(ex)))

        if disk_name is None:
            logger.info('Sync vdisk with hypervisor on {0}'.format(
                pmachine.name))
            try:
                hv = Factory.get(pmachine)
                info = hv.get_vm_agnostic_object(disk.vmachine.hypervisor_id)
                for disk in info['disks']:
                    if disk['filename'] == disk.devicename:
                        disk_name = disk['name']
                        break
            except Exception as ex:
                logger.error('Failed to get vdisk info from hypervisor. %s' %
                             ex)

        if disk_name is None:
            logger.info('No info retrieved from hypervisor, using devicename')
            disk_name = disk.devicename.split('/')[-1].split('.')[0]

        if disk_name is not None:
            disk.name = disk_name
            disk.save()
Exemplo n.º 16
0
 def test_connection(mgmt_center_guid):
     """
     Test management center connection
     """
     mgmt_center = MgmtCenter(mgmt_center_guid)
     try:
         mgmt_center_client = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
     except Exception as ex:
         logger.error('Cannot get mgmt center client: {0}'.format(ex))
         return None
     try:
         is_mgmt_center = mgmt_center_client.test_connection()
     except Exception as ex:
         logger.error('Cannot test connection: {0}'.format(ex))
         return False
     return is_mgmt_center
Exemplo n.º 17
0
 def configure_host(pmachine_guid, mgmtcenter_guid, update_link):
     pmachine = PMachine(pmachine_guid)
     mgmt_center = MgmtCenter(mgmtcenter_guid)
     mgmt_center_client = None
     try:
         mgmt_center_client = Factory.get_mgmtcenter(
             mgmt_center=mgmt_center)
     except Exception as ex:
         logger.error('Cannot get management center client: {0}'.format(ex))
     if mgmt_center_client is not None:
         logger.info('Configuring host {0} on management center {1}'.format(
             pmachine.name, mgmt_center.name))
         mgmt_center_client.configure_host(pmachine.ip)
         if update_link is True:
             pmachine.mgmtcenter = mgmt_center
             pmachine.save()
Exemplo n.º 18
0
 def test_connection(mgmt_center_guid):
     """
     Test mgmtcenter connection
     """
     mgmt_center = MgmtCenter(mgmt_center_guid)
     try:
         mgmt_center_client = Factory.get_mgmtcenter(
             mgmt_center=mgmt_center)
     except Exception as ex:
         logger.error('Cannot get mgmt center client: %s' % ex)
         return None
     try:
         is_mgmt_center = mgmt_center_client.test_connection()
     except Exception as ex:
         logger.error('Cannot test connection: %s' % ex)
         return False
     return is_mgmt_center
Exemplo n.º 19
0
    def update_vmachine_name(instance_id, old_name, new_name):
        """
        Update a vMachine name: find vmachine by management center instance id, set new name
        :param instance_id: ID for the virtual machine known by management center
        :param old_name: Old name of the virtual machine
        :param new_name: New name for the virtual machine
        """
        vmachine = None
        for mgmt_center in MgmtCenterList.get_mgmtcenters():
            mgmt = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
            try:
                machine_info = mgmt.get_vmachine_device_info(instance_id)
                file_name = machine_info['file_name']
                host_name = machine_info['host_name']
                vpool_name = machine_info['vpool_name']
                storage_router = StorageRouterList.get_by_name(host_name)
                machine_id = storage_router.machine_id
                device_name = '{0}/{1}'.format(machine_id, file_name)
                vp = VPoolList.get_vpool_by_name(vpool_name)
                vmachine = VMachineList.get_by_devicename_and_vpool(
                    device_name, vp)
                if vmachine:
                    break
                vmachine = VMachineList.get_by_devicename_and_vpool(
                    device_name, None)
                if vmachine:
                    break
            except Exception as ex:
                logger.info(
                    'Trying to get mgmt center failed for vmachine {0}. {1}'.
                    format(old_name, ex))
        if not vmachine:
            logger.error('No vmachine found for name {0}'.format(old_name))
            return

        vpool = vmachine.vpool
        mutex = VolatileMutex('{0}_{1}'.format(
            old_name, vpool.guid if vpool is not None else 'none'))
        try:
            mutex.acquire(wait=5)
            vmachine.name = new_name
            vmachine.save()
        finally:
            mutex.release()
Exemplo n.º 20
0
 def test_connection(mgmt_center_guid):
     """
     Test management center connection
     """
     mgmt_center = MgmtCenter(mgmt_center_guid)
     try:
         mgmt_center_client = Factory.get_mgmtcenter(
             mgmt_center=mgmt_center)
     except Exception as ex:
         MgmtCenterController._logger.error(
             'Cannot get mgmt center client: {0}'.format(ex))
         return None
     try:
         is_mgmt_center = mgmt_center_client.test_connection()
     except Exception as ex:
         MgmtCenterController._logger.error(
             'Cannot test connection: {0}'.format(ex))
         return False
     return is_mgmt_center
Exemplo n.º 21
0
    def sync_with_mgmtcenter(disk, pmachine, storagedriver):
        """
        Update disk info using management center (if available)
         If no management center, try with hypervisor
         If no info retrieved, use devicename
        @param disk: vDisk hybrid (vdisk to be updated)
        @param pmachine: pmachine hybrid (pmachine running the storagedriver)
        @param storagedriver: storagedriver hybrid (storagedriver serving the vdisk)
        """
        disk_name = None
        if pmachine.mgmtcenter is not None:
            logger.debug('Sync vdisk {0} with management center {1} on storagedriver {2}'.format(disk.name, pmachine.mgmtcenter.name, storagedriver.name))
            mgmt = Factory.get_mgmtcenter(mgmt_center = pmachine.mgmtcenter)
            volumepath = disk.devicename
            mountpoint = storagedriver.mountpoint
            devicepath = '{0}/{1}'.format(mountpoint, volumepath)
            try:
                disk_mgmt_center_info = mgmt.get_vdisk_model_by_devicepath(devicepath)
                if disk_mgmt_center_info is not None:
                    disk_name = disk_mgmt_center_info.get('name')
            except Exception as ex:
                logger.error('Failed to sync vdisk {0} with mgmt center {1}. {2}'.format(disk.name, pmachine.mgmtcenter.name, str(ex)))

        if disk_name is None:
            logger.info('Sync vdisk with hypervisor on {0}'.format(pmachine.name))
            try:
                hv = Factory.get(pmachine)
                info = hv.get_vm_agnostic_object(disk.vmachine.hypervisor_id)
                for disk in info['disks']:
                    if disk['filename'] == disk.devicename:
                        disk_name = disk['name']
                        break
            except Exception as ex:
                logger.error('Failed to get vdisk info from hypervisor. %s' % ex)

        if disk_name is None:
            logger.info('No info retrieved from hypervisor, using devicename')
            disk_name = disk.devicename.split('/')[-1].split('.')[0]

        if disk_name is not None:
            disk.name = disk_name
            disk.save()
Exemplo n.º 22
0
    def update_vmachine_name(instance_id, old_name, new_name):
        """
        Update a vMachine name: find vmachine by management center instance id, set new name
        :param instance_id: ID for the virtual machine known by management center
        :param old_name: Old name of the virtual machine
        :param new_name: New name for the virtual machine
        """
        vmachine = None
        for mgmt_center in MgmtCenterList.get_mgmtcenters():
            mgmt = Factory.get_mgmtcenter(mgmt_center = mgmt_center)
            try:
                machine_info = mgmt.get_vmachine_device_info(instance_id)
                file_name = machine_info['file_name']
                host_name = machine_info['host_name']
                vpool_name = machine_info['vpool_name']
                storage_router = StorageRouterList.get_by_name(host_name)
                machine_id = storage_router.machine_id
                device_name = '{0}/{1}'.format(machine_id, file_name)
                vp = VPoolList.get_vpool_by_name(vpool_name)
                vmachine = VMachineList.get_by_devicename_and_vpool(device_name, vp)
                if vmachine:
                    break
                vmachine = VMachineList.get_by_devicename_and_vpool(device_name, None)
                if vmachine:
                    break
            except Exception as ex:
                VMachineController._logger.info('Trying to get mgmt center failed for vmachine {0}. {1}'.format(old_name, ex))
        if not vmachine:
            VMachineController._logger.error('No vmachine found for name {0}'.format(old_name))
            return

        vpool = vmachine.vpool
        mutex = volatile_mutex('{0}_{1}'.format(old_name, vpool.guid if vpool is not None else 'none'))
        try:
            mutex.acquire(wait=5)
            vmachine.name = new_name
            vmachine.save()
        finally:
            mutex.release()
Exemplo n.º 23
0
 def create(self, request):
     """
     Creates a Management Center
     """
     serializer = FullSerializer(MgmtCenter, instance=MgmtCenter(), data=request.DATA, allow_passwords=True)
     if serializer.is_valid():
         mgmt_center = serializer.object
         duplicate = MgmtCenterList.get_by_ip(mgmt_center.ip)
         if duplicate is None:
             try:
                 mgmt_center_client = Factory.get_mgmtcenter(mgmt_center=mgmt_center)
                 is_mgmt_center = mgmt_center_client.test_connection()
             except Exception as ex:
                 logger.debug('Management center testing: {0}'.format(ex))
                 raise NotAcceptable('The given information is invalid.')
             if not is_mgmt_center:
                 raise NotAcceptable('The given information is not for a Management center.')
             mgmt_center.save()
             return Response(serializer.data, status=status.HTTP_201_CREATED)
         else:
             raise NotAcceptable('A Mangement Center with this ip already exists.')
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)