def secgroup_update(call=None, kwargs=None):
    '''
    Replaces the security group template contents.

    .. versionadded:: 2016.3.0

    secgroup_id
        The ID of the security group to update. Can be used instead of
        ``secgroup_name``.

    secgroup_name
        The name of the security group to update. Can be used instead of
        ``secgroup_id``.

    path
        The path to a file containing the template of the security group. Syntax
        within the file can be the usual attribute=value or XML. Can be used instead
        of ``data``.

    data
        The template data of the security group. Syntax can be the usual attribute=value
        or XML. Can be used instead of ``path``.

    update_type
        There are two ways to update a security group: ``replace`` the whole template
        or ``merge`` the new template with the existing one.

    CLI Example:

    .. code-block:: bash

        salt-cloud --function secgroup_update opennebula secgroup_id=100 \\
            path=/path/to/secgroup_update_file.txt \\
            update_type=replace
        salt-cloud -f secgroup_update opennebula secgroup_name=my-secgroup update_type=merge \\
            data="Name = test RULE = [PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 1000:2000]"
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The secgroup_allocate function must be called with -f or --function.'
        )

    if kwargs is None:
        kwargs = {}

    secgroup_id = kwargs.get('secgroup_id', None)
    secgroup_name = kwargs.get('secgroup_name', None)
    path = kwargs.get('path', None)
    data = kwargs.get('data', None)
    update_type = kwargs.get('update_type', None)
    update_args = ['replace', 'merge']

    if update_type is None:
        raise SaltCloudSystemExit(
            'The secgroup_update function requires an \'update_type\' to be provided.'
        )

    if update_type == update_args[0]:
        update_number = 0
    elif update_type == update_args[1]:
        update_number = 1
    else:
        raise SaltCloudSystemExit(
            'The update_type argument must be either {0} or {1}.'.format(
                update_args[0],
                update_args[1]
            )
        )

    if secgroup_id:
        if secgroup_name:
            log.warning(
                'Both the \'secgroup_id\' and \'secgroup_name\' arguments were provided. '
                '\'secgroup_id\' will take precedence.'
            )
    elif secgroup_name:
        secgroup_id = get_secgroup_id(kwargs={'name': secgroup_name})
    else:
        raise SaltCloudSystemExit(
            'The secgroup_update function requires either a \'secgroup_id\' or a '
            '\'secgroup_name\' to be provided.'
        )

    if data:
        if path:
            log.warning(
                'Both the \'data\' and \'path\' arguments were provided. '
                '\'data\' will take precedence.'
            )
    elif path:
        with salt.utils.files.fopen(path, mode='r') as rfh:
            data = rfh.read()
    else:
        raise SaltCloudSystemExit(
            'The secgroup_update function requires either \'data\' or a file \'path\' '
            'to be provided.'
        )

    server, user, password = _get_xml_rpc()
    auth = ':'.join([user, password])
    response = server.one.secgroup.update(auth, int(secgroup_id), data, int(update_number))

    ret = {
        'action': 'secgroup.update',
        'updated': response[0],
        'secgroup_id': response[1],
        'error_code': response[2],
    }

    return ret
def secgroup_update ( call = None , kwargs = None ) : if call != 'function' : raise SaltCloudSystemExit ( 'The secgroup_allocate function must be called with -f or --function.' ) if kwargs is None : kwargs = { } secgroup_id = kwargs . get ( 'secgroup_id' , None ) secgroup_name = kwargs . get ( 'secgroup_name' , None ) path = kwargs . get ( 'path' , None ) data = kwargs . get ( 'data' , None ) update_type = kwargs . get ( 'update_type' , None ) update_args = [ 'replace' , 'merge' ] if update_type is None : raise SaltCloudSystemExit ( 'The secgroup_update function requires an \'update_type\' to be provided.' ) if update_type == update_args [ 0 ] : update_number = 0 elif update_type == update_args [ 1 ] : update_number = 1 else : raise SaltCloudSystemExit ( 'The update_type argument must be either {0} or {1}.' . format ( update_args [ 0 ] , update_args [ 1 ] ) ) if secgroup_id : if secgroup_name : log . warning ( 'Both the \'secgroup_id\' and \'secgroup_name\' arguments were provided. ' '\'secgroup_id\' will take precedence.' ) elif secgroup_name : secgroup_id = get_secgroup_id ( kwargs = { 'name' : secgroup_name } ) else : raise SaltCloudSystemExit ( 'The secgroup_update function requires either a \'secgroup_id\' or a ' '\'secgroup_name\' to be provided.' ) if data : if path : log . warning ( 'Both the \'data\' and \'path\' arguments were provided. ' '\'data\' will take precedence.' ) elif path : with salt . utils . files . fopen ( path , mode = 'r' ) as rfh : data = rfh . read ( ) else : raise SaltCloudSystemExit ( 'The secgroup_update function requires either \'data\' or a file \'path\' ' 'to be provided.' ) server , user , password = _get_xml_rpc ( ) auth = ':' . join ( [ user , password ] ) response = server . one . secgroup . update ( auth , int ( secgroup_id ) , data , int ( update_number ) ) ret = { 'action' : 'secgroup.update' , 'updated' : response [ 0 ] , 'secgroup_id' : response [ 1 ] , 'error_code' : response [ 2 ] , } return ret
Replaces the security group template contents.

    .. versionadded:: 2016.3.0

    secgroup_id
        The ID of the security group to update. Can be used instead of
        ``secgroup_name``.

    secgroup_name
        The name of the security group to update. Can be used instead of
        ``secgroup_id``.

    path
        The path to a file containing the template of the security group. Syntax
        within the file can be the usual attribute=value or XML. Can be used instead
        of ``data``.

    data
        The template data of the security group. Syntax can be the usual attribute=value
        or XML. Can be used instead of ``path``.

    update_type
        There are two ways to update a security group: ``replace`` the whole template
        or ``merge`` the new template with the existing one.

    CLI Example:

    .. code-block:: bash

        salt-cloud --function secgroup_update opennebula secgroup_id=100 \\
            path=/path/to/secgroup_update_file.txt \\
            update_type=replace
        salt-cloud -f secgroup_update opennebula secgroup_name=my-secgroup update_type=merge \\
            data="Name = test RULE = [PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 1000:2000]"