<commit_before># Copyright (c) 2017 VMware, Inc.
#
# 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.

import logging

from vio.pub.msapi.extsys import get_vim_by_id
from vio.pub.vim.drivers.vimsdk import neutron_v2_0
from vio.pub.vim.vimapi.network.OperateNetwork import BaseNet, translate


logger = logging.getLogger(__name__)


class OperatePort(BaseNet):
    keys_mapping = {"tenantId": "project_id",
                    "networkId": "network_id",
                    "vnicType": "binding:vnic_type",
                    "securityGroups": "security_groups",
                    "macAddress": "mac_address",
                    "subnetId": "subnet_id",
                    "ip": "ip_address"
                    }

    def ___init__(self, params):
        super(OperatePort, self).__init__(params)

    def _convert(self, port):
        result = {}
        result['status'] = 'ok'
        result['id'] = port.id
        result['networkId'] = port.network_id
        result['name'] = port.name
        result['vnicType'] = port.binding_vnic_type
        result['macAddress'] = port.mac_address
        result['subnetId'] = port.subnet_id
        result['securityGroups'] = port.security_group_ids
        return result

    def create_port(self, vimid, tenantid, body):
        vim_info = self.get_vim_info(vimid)
        network = self.auth(vim_info)
        body = translate(self.keys_mapping, body)
        port = network.port_create(**body)<commit_msg>Fix port.subentId is null issue<commit_after># Copyright (c) 2017 VMware, Inc.
#
# 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.

import logging

from vio.pub.msapi.extsys import get_vim_by_id
from vio.pub.vim.drivers.vimsdk import neutron_v2_0
from vio.pub.vim.vimapi.network.OperateNetwork import BaseNet, translate


logger = logging.getLogger(__name__)


class OperatePort(BaseNet):
    keys_mapping = {"tenantId": "project_id",
                    "networkId": "network_id",
                    "vnicType": "binding:vnic_type",
                    "securityGroups": "security_groups",
                    "macAddress": "mac_address",
                    "subnetId": "subnet_id",
                    "ip": "ip_address"
                    }

    def ___init__(self, params):
        super(OperatePort, self).__init__(params)

    def _convert(self, port):
        result = {}
        result['status'] = 'ok'
        result['id'] = port.id
        result['networkId'] = port.network_id
        result['name'] = port.name
        result['vnicType'] = port.binding_vnic_type
        result['macAddress'] = port.mac_address
        result['subnetId'] = port.subnet_id or port.fixed_ips[0]['subnet_id']
        result['securityGroups'] = port.security_group_ids
        return result

    def create_port(self, vimid, tenantid, body):
        vim_info = self.get_vim_info(vimid)
        network = self.auth(vim_info)
        body = translate(self.keys_mapping, body)
        port = network.port_create(**body)
{'fraction_non_alphanumeric': 0.10756123535676251, 'fraction_numerical': 0.005591054313099041, 'mean_word_length': 2.730883813306852, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, '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': '7240609', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1083, 'n_words': 295}