Esempio n. 1
0
 def _get_device_uuid(mgmt, proxy_to):
     dg = mgmt.shared.resolver.device_groups
     collection = dg.cm_cloud_managed_devices.devices_s.get_collection(
         requests_params=dict(
             params="$filter=hostname+eq+'{0}'&$select=uuid".format(
                 proxy_to)))
     if len(collection) > 1:
         raise F5SDKError(
             "More that one managed device was found with this hostname. "
             "Proxied devices must be unique.")
     elif len(collection) == 0:
         raise F5SDKError("No device was found with that hostname")
     else:
         resource = collection.pop()
         return resource.pop('uuid', None)
Esempio n. 2
0
    def _get_identifier(mgmt, proxy_to):
        if proxy_to is None:
            raise F5SDKError(
                "An identifier to a device to proxy to must be provided.")

        if re.search(r'([0-9-a-z]+\-){4}[0-9-a-z]+', proxy_to, re.I):
            return proxy_to
        return ManagementProxy._get_device_uuid(mgmt, proxy_to)
Esempio n. 3
0
 def _mutate_name(self, kwargs):
     slot = kwargs.pop('slot', None)
     if slot is not None:
         try:
             kwargs['name'] = '{0}/{1}'.format(kwargs['name'], int(slot))
         except ValueError:
             raise F5SDKError("The provided 'slot' must be a number")
     return kwargs
Esempio n. 4
0
def ClusterMgrF5SDKError():
    template_dict = mock_template()
    rsrc_def = create_resource_definition(template_dict)
    f5_cm_cluster.ClusterManager.__init__ = mock.MagicMock()
    f5_cm_cluster.ClusterManager.__init__.side_effect = ResourceFailure(
        F5SDKError('test'), None, action='Create'
    )
    return f5_cm_cluster.F5CmCluster(
        "cluster", rsrc_def, mock.MagicMock()
    )
Esempio n. 5
0
    def delete(self, **kwargs):
        """Deletes a member from a license pool

        You need to be careful with this method. When you use it, and it
        succeeds on the remote BIG-IP, the configuration of the BIG-IP
        will be reloaded. During this process, you will not be able to
        access the REST interface.

        This method overrides the Resource class's method because it requires
        that extra json kwargs be supplied. This is not a behavior that is
        part of the normal Resource class's delete method.

        :param kwargs:
        :return:
        """
        if 'id' not in kwargs:
            # BIG-IQ requires that you provide the ID of the members to revoke
            # a license from. This ID is already part of the deletion URL though.
            # Therefore, if you do not provide it, we enumerate it for you.
            delete_uri = self._meta_data['uri']
            if delete_uri.endswith('/'):
                delete_uri = delete_uri[0:-1]
                kwargs['id'] = os.path.basename(delete_uri)
            uid = uuid.UUID(kwargs['id'], version=4)
            if uid.hex != kwargs['id'].replace('-', ''):
                raise F5SDKError(
                    "The specified ID is invalid"
                )

        requests_params = self._handle_requests_params(kwargs)
        kwargs = self._check_for_python_keywords(kwargs)
        kwargs = self._prepare_request_json(kwargs)

        delete_uri = self._meta_data['uri']
        session = self._meta_data['bigip']._meta_data['icr_session']

        # Check the generation for match before delete
        force = self._check_force_arg(kwargs.pop('force', True))
        if not force:
            self._check_generation()

        response = session.delete(delete_uri, json=kwargs, **requests_params)
        if response.status_code == 200:
            self.__dict__ = {'deleted': True}

        # This sleep is necessary to prevent BIG-IQ from being able to remove
        # a license. It happens in certain cases that assignments can be revoked
        # (and license deletion started) too quickly. Therefore, we must introduce
        # an artificial delay here to prevent revoking from returning before
        # BIG-IQ would be ready to remove the license.
        time.sleep(1)
Esempio n. 6
0
    def create(self, **kwargs):
        required_one_of = ['name', 'fullPath']
        has_any = [x for x in iterkeys(kwargs) if x in required_one_of]

        if 'partition' in kwargs and 'name' in kwargs and 'fullPath' not in kwargs:
            partition = kwargs.pop('partition', None)
            name = kwargs.pop('name', None)
            if partition is not None and not partition.startswith('/'):
                kwargs['fullPath'] = '/{0}/{1}'.format(partition, name)
            elif partition is None:
                raise F5SDKError(
                    "The partition name, if specified, cannot be none")
            elif partition.startswith('/'):
                kwargs['fullPath'] = '{0}/{1}'.format(partition, name)

        if len(has_any) == 1:
            return self._create(**kwargs)

        raise RequiredOneOf(required_one_of)
Esempio n. 7
0
    def __new__(cls, *args, **kwargs):
        proxy_to = kwargs.pop('proxy_to', None)
        device_group = kwargs.pop('device_group', 'cm-cloud-managed-devices')

        mgmt = ManagementRoot(args[0], args[1], args[2], **kwargs)
        uuid = cls._get_identifier(mgmt, proxy_to)
        if uuid is None:
            raise F5SDKError("The specified device was missing a UUID. "
                             "This should not happen!")
        bigip = BigipBaseManagement(mgmt.args['hostname'],
                                    mgmt.args['username'],
                                    mgmt.args['password'],
                                    port=mgmt.args['port'],
                                    auth_provider=mgmt.args['auth_provider'])
        bigip.icrs = mgmt.icrs
        uri = ''.join([
            'https://{0}:{1}/mgmt/shared/resolver/device-groups/',
            '{2}/devices/{3}/rest-proxy/mgmt/'
        ])
        bigip._meta_data['uri'] = uri.format(mgmt.args['hostname'],
                                             mgmt.args['port'], device_group,
                                             uuid)
        bigip.post_configuration_setup()
        return bigip
 def update(self, **kwargs):
     raise F5SDKError(
         'Auto Deploy items can be created or deleted, not updated')