def __bind_passthrough_tunnel(self, port, segmentation_id, ofport):
        port_num = port[2:]
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr
        sharedNonByocVFC = self.config['sharedNonByocVFC']

        corsavfc.port_modify_tunnel_mode(headers, url_switch, port_num,
                                         'passthrough')

        # get the bridge from segmentation_id
        byocVFC = corsavfc.get_bridge_by_segmentation_id(
            headers, url_switch, str(segmentation_id))
        if not byocVFC == None:
            br_id = byocVFC
        else:
            br_id = sharedNonByocVFC

        LOG.info("PRUTH: __bind_passthrough_tunnel - br_id: " + str(br_id) +
                 " segmentation_id: " + str(segmentation_id) + " port_num: " +
                 str(port_num) + " ofport: " + str(ofport))
        corsavfc.bridge_attach_tunnel_passthrough(headers,
                                                  url_switch,
                                                  br_id,
                                                  port_num,
                                                  ofport,
                                                  tc=None,
                                                  descr=None,
                                                  shaped_rate=None)
Esempio n. 2
0
 def _get_global_flags(self):
     """Get global flags."""
     # Good location to add_argument() global options like --verbose
     self.parser.add_argument('--json',
                              action='store_true',
                              help='JSON formatted output')
     self.parser.add_argument('-k', '--insecure',
                              action='store_true',
                              help='Explicitly allow the client to perform'
                                   ' \"insecure SSL\" (https) requests.'
                                   ' The server\'s certificate will not be'
                                   ' verified against any certificate'
                                   ' authorities. This option should be'
                                   ' used with caution.')
     self.parser.add_argument('-d', '--debug',
                              action='store_true',
                              help='Print out request and response '
                                   'details.')
     args, _ = self.parser.parse_known_args()
     if args.json:
         self.json_output = True
     if args.insecure:
         self.verify = False
     if args.debug:
         logging.basicConfig(
             format="%(levelname)s (%(module)s) %(message)s",
             level=logging.DEBUG)
         logging.getLogger('iso8601').setLevel(logging.WARNING)
         urllibpool = 'urllib3.connectionpool'
         logging.getLogger(urllibpool).setLevel(logging.WARNING)
Esempio n. 3
0
    def __init__(self,
                 file,
                 disable_update_pre=False,
                 disable_update_post=False,
                 enable_chart_cleanup=False,
                 dry_run=False,
                 wait=False,
                 timeout=DEFAULT_TIMEOUT,
                 tiller_host=None,
                 tiller_port=44134,
                 debug=False):
        '''
        Initialize the Armada Engine and establish
        a connection to Tiller
        '''

        self.disable_update_pre = disable_update_pre
        self.disable_update_post = disable_update_post
        self.enable_chart_cleanup = enable_chart_cleanup
        self.dry_run = dry_run
        self.wait = wait
        self.timeout = timeout
        self.tiller = Tiller(tiller_host=tiller_host, tiller_port=tiller_port)
        self.documents = list(yaml.safe_load_all(file))
        self.config = None
        self.debug = debug

        # Set debug value
        # Define a default handler at INFO logging level
        if self.debug:
            logging.basicConfig(level=logging.DEBUG)
    def get_ofcontroller_ip_address(self, bridge):
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr

        ofcontroller_ip = None
        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):
                br_num = bridge.replace(bridge, "")
                ofcontroller = corsavfc.get_bridge_controller(
                    headers, url_switch, bridge_number=br_num)
        except Exception as e:
            LOG.error("failed get ofcontroller ip address: " +
                      traceback.format_exc())
            raise e
        # OF Controllers have the name as CONTbr<N>
        ofcontroller_name = 'CONT' + str(bridge)
        ofcontroller_href = ofcontroller.json(
        )['links'][ofcontroller_name]['href']
        ofcontroller_details = corsavfc.get_info(headers, url_switch,
                                                 ofcontroller_details)
        ofcontroller_ip = ofcontroller_details.json().get("ip")
        return ofcontroller_ip
    def del_network(self, segmentation_id, project_id):
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr

        sharedNonByocVFC = self.config['sharedNonByocVFC']

        isVFCHost = True
        if not 'VFCHost' in self.config or not self.config['VFCHost'] == 'True':
            LOG.info("PRUTH: Skipping VFC Deletion: isVFCHost " +
                     str(isVFCHost))
            isVFCHost = False
            return

        bridge = None
        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):
                bridge = corsavfc.get_bridge_by_segmentation_id(
                    headers, url_switch, str(segmentation_id))
                if not bridge == None:
                    LOG.info("PRUTH: del_network - network in ByocVfc: " +
                             str(bridge))
                    br_descr = corsavfc.get_bridge_descr(
                        headers, url_switch, bridge)
                    # br_descr format: <PROJECT_ID>-<VFC_NAME>-VLAN-<TAG1>-<TAG2>
                    VLAN_tags = br_descr.split('-')[3:]
                    if (len(VLAN_tags) > 1):
                        br_descr = br_descr.replace("-" + str(segmentation_id),
                                                    "")
                        ofport = segmentation_id
                        corsavfc.bridge_modify_descr(headers, url_switch,
                                                     bridge, br_descr)
                        corsavfc.bridge_detach_tunnel(headers, url_switch,
                                                      bridge, ofport)
                    else:
                        output = corsavfc.bridge_delete(
                            headers, url_switch, str(bridge))
                else:
                    LOG.info(
                        "PRUTH: del_network - network in sharedNonByocVfc")
                    ofport = int(str(segmentation_id)[-3:])
                    sharedNonByocVfc_tunnel = corsavfc.get_tunnel_by_bridge_and_ofport(
                        headers, url_switch, sharedNonByocVFC, ofport)
                    corsavfc.bridge_detach_tunnel(headers, url_switch,
                                                  sharedNonByocVFC,
                                                  int(sharedNonByocVfc_tunnel))

        except Exception as e:
            LOG.error("failed delete network : " + traceback.format_exc())
            raise e
    def add_network_to_sharedNonByoc_vfc(self, segmentation_id, network_id):
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr

        c_vlan = segmentation_id
        c_uplink_ports = self.config['uplink_ports']

        c_br = self.config['sharedNonByocVFC']

        isVFCHost = True
        if not 'VFCHost' in self.config or not self.config['VFCHost'] == 'True':
            LOG.info("PRUTH: Skipping VFC Creation: isVFCHost " +
                     str(isVFCHost))
            isVFCHost = False
            return

        LOG.info("PRUTH: --- add_network_to_sharedNonByoc_vfc: " + str(c_br))

        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):

                LOG.info("About to get_ofport: c_br: " + str(c_br) +
                         ", c_uplink_ports: " + str(c_uplink_ports))
                for uplink in c_uplink_ports.split(','):
                    # Attach the uplink tunnel
                    LOG.info("About to get_ofport: c_br: " + str(c_br) +
                             ", uplink: " + str(uplink))
                    # Logical port number of an uplink port is last 3 digits of VLAN tag
                    ofport = str(c_vlan)[-3:]
                    LOG.info("ofport: " + str(ofport))
                    corsavfc.bridge_attach_tunnel_ctag_vlan(headers,
                                                            url_switch,
                                                            br_id=c_br,
                                                            ofport=int(ofport),
                                                            port=int(uplink),
                                                            vlan_id=c_vlan)

        except Exception as e:
            LOG.error("Failed add network. attempting to cleanup bridge: " +
                      str(e) + ", " + traceback.format_exc())
            raise e
    def __delete_port(self, port, segmentation_id):
        # OpenStack requires port ids to not be numbers
        # Corsa uses numbers
        # We are lying to OpenStack by adding a 'p ' to the beging of each port number.
        # We need to strip the 'p ' off of the port number.
        port_num = port[2:]

        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr
        sharedNonByocVFC = self.config['sharedNonByocVFC']

        LOG.info("PRUTH: delete port: switch: " + self.config['name'] +
                 ", port: " + str(port) + ", segmentation_id: " +
                 str(segmentation_id))

        ofport = None
        if port in self.config:
            LOG.info("PRUTH: delete port " + str(port) + " maps to " +
                     str(self.config[port]))
            ofport = str(int(self.config[port]) + 10000)

        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):
                # get the bridge from segmentation_id
                byocVFC = corsavfc.get_bridge_by_segmentation_id(
                    headers, url_switch, segmentation_id)
                if not byocVFC == None:
                    br_id = byocVFC
                else:
                    br_id = sharedNonByocVFC

                # unbind the port
                # openflow port was mapped to the physical port with the same port number in plug_port_to_network
                #ofport = self.get_ofport(br_id,port)
                corsavfc.bridge_detach_tunnel(headers, url_switch, br_id,
                                              ofport)

        except Exception as e:
            LOG.error("Failed delete_port: " + traceback.format_exc())
            raise e
    def __bind_ctag_tunnel(self,
                           segmentation_id,
                           node_vlan,
                           dst_switch_name,
                           ofport=None):
        LOG.info(
            "PRUTH: __bind_ctag_tunnel - adding to vfc_host: __bind_ctag_tunnel"
        )
        LOG.info("PRUTH: __bind_ctag_tunnel - switch: " + self.config['name'] +
                 ", VFCHost: " + str(segmentation_id) + ", " + str(node_vlan) +
                 ", " + str(dst_switch_name))

        #port_num=port[2:]
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr
        sharedNonByocVFC = self.config['sharedNonByocVFC']

        dst_port = None
        if dst_switch_name in self.config:
            dst_port = self.config[dst_switch_name]

        LOG.info("PRUTH: __bind_ctag_tunnel - About to dst_port: " +
                 str(dst_port))
        byocVFC = corsavfc.get_bridge_by_segmentation_id(
            headers, url_switch, segmentation_id)
        if not byocVFC == None:
            br_id = byocVFC
        else:
            br_id = sharedNonByocVFC

        if not ofport:
            ofport = str(int(str(node_vlan)) + 10000)
        LOG.info("PRUTH: __bind_ctag_tunnel - ofport: " + str(ofport))
        LOG.info("PRUTH: __bind_ctag_tunnel - br_id : " + str(br_id))
        corsavfc.bridge_attach_tunnel_ctag_vlan(headers,
                                                url_switch,
                                                br_id=br_id,
                                                ofport=ofport,
                                                port=int(dst_port),
                                                vlan_id=node_vlan)
Esempio n. 9
0
def log_init():
    import logging
    import os
    FILE = os.getcwd()

    #format='%(asctime)s:%(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
    logging.basicConfig(level=logging.INFO,
                        datefmt='[%Y %H:%M:%S]',
                        filename=os.path.join(FILE, 'all.log'),
                        filemode='a+')

    formatter = logging.Formatter(
        '%(levelname)s [%(asctime)s] [%(name)s]:%(pathname)s line=%(lineno)d [message="%(message)s"]'
    )
    logging.info('log system init')

    ch = logging.StreamHandler()
    ch.setLevel(logging.INFO)
    ch.setFormatter(formatter)
    def find_named_vfc(self, vfc_name):
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr

        bridge = None
        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):
                bridge = corsavfc.get_bridge_by_vfc_name(
                    headers, url_switch, str(vfc_name))
        except Exception as e:
            LOG.error("failed get bridge by vfc name: " +
                      traceback.format_exc())
            raise e

        return bridge
Esempio n. 11
0
        """
        Uploads a validated cookbook to the official Github repo
        Authentication must be enabled via external shared keys
        :param path: cookbook path
        :return: status message
        """
        dest_url = None
        if chef_client.check_chef_cookbook(path):
            dest_url = CONF.clients_chef.github_url
        elif puppet_client.check_puppet_module(path):
            dest_url = CONF.clients_puppet.github_url
        elif murano_client.check_murano_blueprint(path):
            dest_url = CONF.clients_murano.github_url
        if dest_url:
            LOG.info("Pushing cookbook to %s" % dest_url)
            dest = self.repo.create_remote(self.user, dest_url)
            self.repo.create_head('remote', dest.refs.master).set_tracking_branch(dest.refs.master)
            message = dest.push()
        else:
            LOG.warning("Error detecting cookbook type for %s" % path)
            message = "Error"
        return message

if __name__ == '__main__':
    import logging; logging.basicConfig(); LOG.logger.setLevel(logging.DEBUG)
    from bork_api.common import config




    def add_network(self,
                    segmentation_id,
                    network_id,
                    project_id=None,
                    of_controller=None,
                    vfc_name=None):
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr

        #./create-vfc.py br1 5 openflow VFC-1 192.168.201.164 6653 100-105
        c_br_res = self.config['defaultVFCRes']
        c_br_type = self.config['VFCType']

        c_vlan = segmentation_id
        c_uplink_ports = self.config['uplink_ports']

        c_br_type = self.config['VFCType']

        cont_ip = self.config['defaultControllerIP']
        cont_port = self.config['defaultControllerPort']
        c_controller_namespace = 'default'
        c_vfc_name = self.config['defaultVFCName']

        if of_controller:
            cont_ip, cont_port = of_controller
            if 'controllerNamespace' in self.config:
                c_controller_namespace = self.config['controllerNamespace']

        if vfc_name:
            c_vfc_name = str(vfc_name)
        else:
            c_vfc_name = project_id + "-" + c_vfc_name

        c_br_descr = c_vfc_name + "-VLAN-" + str(segmentation_id)

        isVFCHost = True
        if not 'VFCHost' in self.config or not self.config['VFCHost'] == 'True':
            LOG.info("PRUTH: Skipping VFC Creation: isVFCHost " +
                     str(isVFCHost))
            isVFCHost = False
            return

        LOG.info("controller:  cont_ip =  " + str(cont_ip) + ", cont_port = " +
                 str(cont_port) + ", c_controller_namespace = " +
                 str(c_controller_namespace))
        LOG.info("segmentation_id    " + str(segmentation_id))
        LOG.info("provisioning vlan  " + str(self.config['provisioningVLAN']))
        LOG.info("PRUTH: isVFCHost " + str(isVFCHost))
        LOG.info("PRUTH: --- vfc_name " + str(c_vfc_name))

        try:
            if self.config.has_key('provisioningVLAN'):
                if str(segmentation_id) == self.config['provisioningVLAN']:
                    LOG.info("Creating provisioning network on VLAN " +
                             self.config['provisioningVLAN'] +
                             " with controller " +
                             self.config['provisioningControllerPort'] + ":" +
                             self.config['provisioningControllerPort'])
                    c_br_type = self.config['provisioningVFCType']
                    cont_ip = self.config['provisioningControllerIP']
                    cont_port = self.config['provisioningControllerPort']
        except Exception as e:
            LOG.error(
                "Failed to find provisioning network controller.  Using default controller"
            )

        c_br = None
        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):
                c_br = corsavfc.get_free_bridge(headers, url_switch)
                cont_id = 'CONT' + str(c_br)

                #Create the bridge
                corsavfc.bridge_create(headers,
                                       url_switch,
                                       c_br,
                                       br_subtype=c_br_type,
                                       br_resources=c_br_res,
                                       br_descr=c_br_descr,
                                       br_namespace=c_controller_namespace)
                #Add the controller
                LOG.info("Attaching of_controller " + str(cont_ip) + ":" +
                         str(cont_port) + " to bridge " + str(c_br))
                corsavfc.bridge_add_controller(headers,
                                               url_switch,
                                               br_id=c_br,
                                               cont_id=cont_id,
                                               cont_ip=cont_ip,
                                               cont_port=cont_port)

                LOG.info("About to get_ofport: c_br: " + str(c_br) +
                         ", c_uplink_ports: " + str(c_uplink_ports))
                for uplink in c_uplink_ports.split(','):
                    #Attach the uplink tunnel
                    LOG.info("About to get_ofport: c_br: " + str(c_br) +
                             ", uplink: " + str(uplink))
                    #The logical port number of an uplink is assumed to be the VLAN id
                    ofport = c_vlan
                    LOG.info("ofport: " + str(ofport))
                    corsavfc.bridge_attach_tunnel_ctag_vlan(headers,
                                                            url_switch,
                                                            br_id=c_br,
                                                            ofport=ofport,
                                                            port=int(uplink),
                                                            vlan_id=c_vlan)

        except Exception as e:
            LOG.error("Failed add network. attempting to cleanup bridge: " +
                      str(e) + ", " + traceback.format_exc())
            try:
                output = corsavfc.bridge_delete(headers, url_switch, str(c_br))
            except Exception as e2:
                LOG.error(
                    " Failed to cleanup bridge after failed add_network: " +
                    str(segmentation_id) + ", bridge: " + str(bridge) +
                    ", Error: " + str(e2))
            raise e
    def add_network_to_existing_vfc(self,
                                    segmentation_id,
                                    network_id,
                                    bridge,
                                    vfc_name,
                                    of_controller=None):
        token = self.config['token']
        headers = {'Authorization': token}

        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)

        protocol = 'https://'
        sw_ip_addr = self.config['switchIP']
        url_switch = protocol + sw_ip_addr

        c_vlan = segmentation_id
        c_uplink_ports = self.config['uplink_ports']

        c_vfc_name = vfc_name
        c_br = bridge

        LOG.info("PRUTH: --- add_network_to_existing_vfc: " + str(c_br))

        try:
            with ngs_lock.PoolLock(self.locker, **self.lock_kwargs):

                c_br_descr = corsavfc.get_bridge_descr(headers, url_switch,
                                                       c_br)
                c_br_descr = c_br_descr + "-" + str(segmentation_id)
                corsavfc.bridge_modify_descr(headers, url_switch, c_br,
                                             c_br_descr)

                #if of_controller:
                #    cont_ip, cont_port = of_controller
                #    vfc_controller_ip = self.get_ofcontroller_ip_address(c_br)
                #    LOG.info("PRUTH: --- Controller Specified: " + str(cont_ip))
                #    LOG.info("PRUTH: --- Controller Current  : " + str(vfc_controller_ip))

                #    if vfc_controller_ip != cont_ip:
                #        cont_id = 'CONT' + str(c_br)
                #        corsavfc.bridge_detach_controller(headers, url_switch, br_id = c_br, cont_id = cont_id)
                #        corsavfc.bridge_add_controller(headers, url_switch, br_id = c_br, cont_id = cont_id, cont_ip = cont_ip, cont_port = cont_port)

                LOG.info("About to get_ofport: c_br: " + str(c_br) +
                         ", c_uplink_ports: " + str(c_uplink_ports))
                for uplink in c_uplink_ports.split(','):
                    #Attach the uplink tunnel
                    LOG.info("About to get_ofport: c_br: " + str(c_br) +
                             ", uplink: " + str(uplink))
                    #The logical port number of an uplink is assumed to be the VLAN id
                    ofport = c_vlan
                    LOG.info("ofport: " + str(ofport))
                    corsavfc.bridge_attach_tunnel_ctag_vlan(headers,
                                                            url_switch,
                                                            br_id=c_br,
                                                            ofport=ofport,
                                                            port=int(uplink),
                                                            vlan_id=c_vlan)

        except Exception as e:
            LOG.error("Failed add network. attempting to cleanup bridge: " +
                      str(e) + ", " + traceback.format_exc())
            try:
                output = corsavfc.bridge_delete(headers, url_switch, str(c_br))
            except Exception as e2:
                LOG.error(
                    " Failed to cleanup bridge after failed add_network: " +
                    str(segmentation_id) + ", bridge: " + str(bridge) +
                    ", Error: " + str(e2))
            raise e