2016-12-11 23:05:07 +03:00
/* -------------------------------------------------------------------------- */
2024-07-29 15:25:20 +03:00
/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */
2016-12-11 23:05:07 +03:00
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
# ifndef VIRTUAL_MACHINE_ATTRIBUTE_H_
# define VIRTUAL_MACHINE_ATTRIBUTE_H_
2017-04-10 19:41:43 +03:00
# include "ExtendedAttribute.h"
2016-12-11 23:05:07 +03:00
/**
* This class represents a generic VirtualMachine attribute , it exposes the
* basic VectorAttribute interface and can be decorated with functionality
* for an specific class , ( e . g . disks or nics ) .
*
* The attribute operates directly on the VirtualMachineTemplate attribute . IT
* IS NOT CLONED OR COPIED
*/
2017-04-10 19:41:43 +03:00
class VirtualMachineAttribute : public ExtendedAttribute
2016-12-11 23:05:07 +03:00
{
protected :
/**
* Creates the attribute with a reference to a VectorAttribute . The object
* is shared and WILL BE modified through this interface .
* @ param va pointer to the VectorAttribute .
*/
VirtualMachineAttribute ( VectorAttribute * _va ) :
2024-06-03 12:40:24 +03:00
ExtendedAttribute ( _va ) { } ;
2016-12-11 23:05:07 +03:00
VirtualMachineAttribute ( VectorAttribute * _va , int _id ) :
2017-04-10 19:41:43 +03:00
ExtendedAttribute ( _va , _id ) { } ;
2016-12-11 23:05:07 +03:00
2024-06-03 12:40:24 +03:00
virtual ~ VirtualMachineAttribute ( ) { } ;
2016-12-11 23:05:07 +03:00
/* ---------------------------------------------------------------------- */
/* VirtualMachineAttribute Interface */
/* ---------------------------------------------------------------------- */
/**
* Sets the flag in the attribute in the form ( FLAG = " YES " )
*/
2020-07-02 23:42:10 +03:00
void set_flag ( const std : : string & flag )
2016-12-11 23:05:07 +03:00
{
replace ( flag , true ) ;
} ;
/**
* Clears a previously set flag
*/
2020-07-02 23:42:10 +03:00
void clear_flag ( const std : : string & flag )
2016-12-11 23:05:07 +03:00
{
remove ( flag ) ;
} ;
2020-07-02 23:42:10 +03:00
bool is_flag ( const std : : string & flag ) const
2016-12-11 23:05:07 +03:00
{
bool value ;
2017-04-10 19:41:43 +03:00
vector_value ( flag , value ) ;
2016-12-11 23:05:07 +03:00
return value ;
}
private :
friend class VirtualMachineAttributeSet ;
} ;
/**
* This class represents a set of VirtualMachineAttributes it provides fast
* access to individual elements ( by ID ) and implement collective operations
*/
2017-04-10 19:41:43 +03:00
class VirtualMachineAttributeSet : public ExtendedAttributeSet
2016-12-11 23:05:07 +03:00
{
protected :
/**
2016-12-12 12:26:55 +03:00
* Creates the VirtualMachineAttribute set
* @ param dispose elements upon set destruction
2016-12-11 23:05:07 +03:00
*/
2024-06-03 12:40:24 +03:00
VirtualMachineAttributeSet ( bool _dispose ) : ExtendedAttributeSet ( _dispose ) { } ;
2016-12-11 23:05:07 +03:00
2024-06-03 12:40:24 +03:00
virtual ~ VirtualMachineAttributeSet ( ) { } ;
2016-12-11 23:05:07 +03:00
/* ---------------------------------------------------------------------- */
/* Methods to access attributes */
/* ---------------------------------------------------------------------- */
/**
* @ return attribute by id or 0 if not found
*/
2017-04-10 19:41:43 +03:00
VirtualMachineAttribute * get_attribute ( int id ) const
{
2017-05-26 15:45:35 +03:00
return static_cast < VirtualMachineAttribute * > (
2024-06-03 12:40:24 +03:00
ExtendedAttributeSet : : get_attribute ( id ) ) ;
2017-04-10 19:41:43 +03:00
}
2016-12-11 23:05:07 +03:00
/**
* @ return attribute with the given flag set or 0 if not found
*/
2020-07-02 23:42:10 +03:00
VirtualMachineAttribute * get_attribute ( const std : : string & flag ) const ;
2016-12-11 23:05:07 +03:00
/**
* Deletes the attribute with the given flag set .
* @ return Pointer to the attribute or 0 if not found
*/
2020-07-02 23:42:10 +03:00
VirtualMachineAttribute * remove_attribute ( const std : : string & flag ) ;
2016-12-11 23:05:07 +03:00
/**
* Sets flag in a VirtualMachineAttribute
* @ param a_id of the attribute
* @ param flag_name
* @ return 0 on success
*/
2020-07-02 23:42:10 +03:00
int set_flag ( int a_id , const std : : string & flag_name ) ;
2016-12-11 23:05:07 +03:00
/**
* Clears the flag from the VirtualMachineAttributes in the set .
* @ return the attribute for which the flag was cleared , 0 if none
*/
2020-07-02 23:42:10 +03:00
VirtualMachineAttribute * clear_flag ( const std : : string & flag_name ) ;
2016-12-11 23:05:07 +03:00
} ;
# endif /*VIRTUAL_MACHINE_ATTRIBUTE_H_*/