# (C) Copyright 2019 Hewlett Packard Enterprise Development LP.

# 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.

# __author__ = "@netwookie"
# __credits__ = ["Rick Kauffman"]
# __license__ = "Apache2.0"
# __maintainer__ = "Rick Kauffman"
# __email__ = "rick.a.kauffman@hpe.com"

# A python script for formatting twitter data

import json
import requests
from st2common.runners.base_action import Action

class FormatVlans(Action):

    def run(self, networks):        # Get trigger dictionaary.
        net_out=[]
        for net in networks:
            name=net['name']
            if net['vlans'] == 0:
                continue
            vlans=net['vlanId']
            vlans=str(vlans)
            description=net['description']
            # check for empty variables
            if name == None:
                name='Auto generated by stackstorm'
            if description == None:
                description='Vlan assigned from OneView'
            # build line to export
            line={"name": name,"description":description,"vlans":vlans}
            net_out.append(line)

        return (True, net_out)
