<commit_before>/*
 * TNLibvirtDomainOSType.j
 *
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@import <Foundation/Foundation.j>
@import <StropheCappuccino/TNXMLNode.j>

TNLibvirtDomainOSTypeTypeLinux  = @"linux";
TNLibvirtDomainOSTypeTypeHVM    = @"hvm";

@import "TNLibvirtBase.j";


/*! @ingroup virtualmachinedefinition
    Model for OS Type
*/
@implementation TNLibvirtDomainOSType : TNLibvirtBase
{
    CPString    _architecture       @accessors(property=architecture);
    CPString    _machine            @accessors(property=machine);
    CPString    _type               @accessors(property=type);
}


#pragma mark -
#pragma mark Initialization

/*! initialize the object with a given XML node
    @param aNode the node to use
*/
- (id)initWithXMLNode:(TNXMLNode)aNode
{
    if (self = [super initWithXMLNode:aNode])
    {
        if ([aNode name] != @"type")
            [CPException raise:@"XML not valid" reason:@"The TNXMLNode provided is not a valid os type"];

        _architecture       = [aNode valueForAttribute:@"arch"];
        _machine            = [aNode valueForAttribute:@"machine"];
        _type               = [aNode text];
    }

    return self;
}


#pragma mark -
#pragma mark Generation

/*! return a TNXMLNode representing the object
    @return TNXMLNode
*/
- (TNXMLNode)XMLNode
{
    var node = [TNXMLNode nodeWithName:@"type"];

    if (_machine)
        [node setValue:_machine forAttribute:@"machine"];

    if (_architecture)<commit_msg>Intercept DomainTypeOS and fake the return (tranform hvm into hvm + xen + xenfv and linux into xen + xen + xenpv)<commit_after>/*
 * TNLibvirtDomainOSType.j
 *
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@import <Foundation/Foundation.j>
@import <StropheCappuccino/TNXMLNode.j>

TNLibvirtDomainOSTypeTypeLinux  = @"linux";
TNLibvirtDomainOSTypeTypeHVM    = @"hvm";

@import "TNLibvirtBase.j";


/*! @ingroup virtualmachinedefinition
    Model for OS Type
*/
@implementation TNLibvirtDomainOSType : TNLibvirtBase
{
    CPString    _architecture       @accessors(property=architecture);
    CPString    _machine            @accessors(property=machine);
    CPString    _type               @accessors(property=type);
}


#pragma mark -
#pragma mark Initialization

/*! initialize the object with a given XML node
    @param aNode the node to use
*/
- (id)initWithXMLNode:(TNXMLNode)aNode
{
    if (self = [super initWithXMLNode:aNode])
    {
        if ([aNode name] != @"type")
            [CPException raise:@"XML not valid" reason:@"The TNXMLNode provided is not a valid os type"];

        _architecture       = [aNode valueForAttribute:@"arch"];
        _machine            = [aNode valueForAttribute:@"machine"];
        _type               = [aNode text];

        // We have to fake a good return from libvirt for Xen as some informations are missing
        // For HVM if we set <type machine='xenfv' arch='x86_64|i686'>hvm</type> we dump <type>hvm</type>
        // For PVM if we set <type machine='xenpv' arch='x86_64|i686'>xen</type> we dump <type>linux</type>
        // No way to get the arch for Xen Guest domain as in HVM it boot's on 16bits real mode
        // Regarding PVM, no way to know if we boot a kernel in 32/64b too

        if (_type == TNLibvirtDomainOSTypeTypeLinux)
        {
            _architecture       = @"i686";
            _machine            = @"xenpv";
            _type               = @"xen";
        }

        if (_type == TNLibvirtDomainOSTypeTypeHVM)
        {
            _architecture       = @"i686";
            _machine            = @"xenfv";
            _type               = TNLibvirtDomainOSTypeTypeHVM;
        }

    }

    return self;
}


#pragma mark -
#pragma mark Generation

/*! return a TNXMLNode representing the object
    @return TNXMLNode
*/
- (TNXMLNode)XMLNode
{
    var node = [TNXMLNode nodeWithName:@"type"];

    if (_machine)
        [node setValue:_machine forAttribute:@"machine"];

    if (_architecture)
{'fraction_non_alphanumeric': 0.09422894985808893, 'fraction_numerical': 0.006811731315042573, 'mean_word_length': 2.8782098312545856, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6964813', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1497, 'n_words': 533}