Esempio n. 1
0
def _dlr_create(client_session, vccontent, datacenter_name, edge_datastore,
                edge_cluster, **kwargs):
    if not (kwargs['dlr_name'] and kwargs['dlr_pwd'] and kwargs['dlr_size']
            and datacenter_name and kwargs['ha_ls_name']
            and kwargs['uplink_ls_name'] and kwargs['uplink_ip']
            and kwargs['uplink_subnet'] and edge_datastore and edge_cluster):
        print(
            'You are missing a mandatory parameter, those are [-n NAME] [-p DLRPASSWORD] [-s DLRSIZE] '
            '[--ha_ls HA_LS] [--uplink_ls UPLINK_LS] [--uplink_ip UPLINK_IP] [--uplink_subnet UPLINK_SUBNET] '
            'and the ini file options datacenter_name,edge_datastore and edge_cluster'
        )
        return None
    dlr_name = kwargs['dlr_name']
    dlr_pwd = kwargs['dlr_pwd']
    dlr_size = kwargs['dlr_size']

    datacentermoid = get_datacentermoid(vccontent, datacenter_name)
    datastoremoid = get_datastoremoid(vccontent, edge_datastore)
    resourcepoolid = get_edgeresourcepoolmoid(vccontent, edge_cluster)

    ha_ls_name = kwargs['ha_ls_name']
    # find ha_ls_id in vDS port groups or NSX logical switches
    ha_ls_id = get_vdsportgroupid(vccontent, ha_ls_name)
    if not ha_ls_id:
        ha_ls_id, ha_ls_switch_params = get_logical_switch(
            client_session, ha_ls_name)
        if not ha_ls_id:
            print 'ERROR: DLR HA switch {} does NOT exist as VDS port group nor NSX logical switch'.format(
                ha_ls_name)
            return None

    uplink_ls_name = kwargs['uplink_ls_name']
    uplink_ip = kwargs['uplink_ip']
    uplink_subnet = kwargs['uplink_subnet']
    uplink_dgw = kwargs['uplink_dgw']
    # find uplink_ls_id in vDS port groups or NSX logical switches
    uplink_ls_id = get_vdsportgroupid(vccontent, uplink_ls_name)
    if not uplink_ls_id:
        uplink_ls_id, uplink_ls_switch_params = get_logical_switch(
            client_session, uplink_ls_name)
        if not uplink_ls_id:
            print 'ERROR: DLR uplink switch {} does NOT exist as VDS port group ' \
                  'nor NSX logical switch'.format(uplink_ls_name)
            return None

    dlr_id, dlr_params = dlr_create(client_session, dlr_name, dlr_pwd,
                                    dlr_size, datacentermoid, datastoremoid,
                                    resourcepoolid, ha_ls_id, uplink_ls_id,
                                    uplink_ip, uplink_subnet, uplink_dgw)
    if kwargs['verbose']:
        print dlr_params
    else:
        print 'Distributed Logical Router {} created with the Edge-ID {}'.format(
            dlr_name, dlr_id)
Esempio n. 2
0
def _dlr_add_interface(client_session, vccontent, **kwargs):
    if not (kwargs['dlr_name'] and kwargs['interface_ls_name']
            and kwargs['interface_ip'] and kwargs['interface_subnet']):
        print(
            'Mandatory parameters missing, [-n NAME] [--interface_ls INTERFACE_LS] [--interface_ip INTERFACE_IP] '
            '[--interface_subnet INTERFACE_SUBNET]')
        return None
    dlr_name = kwargs['dlr_name']
    interface_ls_name = kwargs['interface_ls_name']
    interface_ip = kwargs['interface_ip']
    interface_subnet = kwargs['interface_subnet']

    dlr_id, dlr_params = dlr_read(client_session, dlr_name)
    if dlr_id:
        # find interface_ls_id in vDS port groups or NSX logical switches
        interface_ls_id = get_vdsportgroupid(vccontent, interface_ls_name)
        if not interface_ls_id:
            interface_ls_id, interface_ls_params = get_logical_switch(
                client_session, interface_ls_name)
            if not interface_ls_id:
                print 'ERROR: DLR interface logical switch {} does NOT exist as VDS port ' \
                      'group nor NSX logical switch'.format(interface_ls_name)
                return None

        dlr_add_int = dlr_add_interface(client_session, dlr_id,
                                        interface_ls_id, interface_ip,
                                        interface_subnet)
        if dlr_add_int and kwargs['verbose']:
            print json.dumps(dlr_add_int)
        else:
            print 'Interface {} added to dlr_name {} / dlr_id {}'.format(
                interface_ls_name, dlr_name, dlr_id)
Esempio n. 3
0
def _dlr_add_interface(client_session, vccontent, **kwargs):
    if not (kwargs['dlr_name'] and kwargs['interface_ls_name'] and kwargs['interface_ip']
            and kwargs['interface_subnet']):
        print ('Mandatory parameters missing, [-n NAME] [--interface_ls INTERFACE_LS] [--interface_ip INTERFACE_IP] '
               '[--interface_subnet INTERFACE_SUBNET]')
        return None
    dlr_name = kwargs['dlr_name']
    interface_ls_name = kwargs['interface_ls_name']
    interface_ip = kwargs['interface_ip']
    interface_subnet = kwargs['interface_subnet']

    dlr_id, dlr_params = dlr_read(client_session, dlr_name)
    if dlr_id:
        # find interface_ls_id in vDS port groups or NSX logical switches
        interface_ls_id = get_vdsportgroupid(vccontent, interface_ls_name)
        if not interface_ls_id:
            interface_ls_id, interface_ls_params = get_logical_switch(client_session, interface_ls_name)
            if not interface_ls_id:
                print 'ERROR: DLR interface logical switch {} does NOT exist as VDS port ' \
                      'group nor NSX logical switch'.format(interface_ls_name)
                return None

        dlr_add_int = dlr_add_interface(client_session, dlr_id, interface_ls_id, interface_ip, interface_subnet)
        if dlr_add_int and kwargs['verbose']:
            print json.dumps(dlr_add_int)
        else:
            print 'Interface {} added to dlr_name {} / dlr_id {}'.format(interface_ls_name, dlr_name, dlr_id)
Esempio n. 4
0
def _dlr_create(client_session, vccontent, datacenter_name, edge_datastore, edge_cluster, **kwargs):
    if not (kwargs['dlr_name'] and kwargs['dlr_pwd'] and kwargs['dlr_size'] and datacenter_name
            and kwargs['ha_ls_name'] and kwargs['uplink_ls_name'] and kwargs['uplink_ip'] and kwargs['uplink_subnet']
            and edge_datastore and edge_cluster):
        print ('You are missing a mandatory parameter, those are [-n NAME] [-p DLRPASSWORD] [-s DLRSIZE] '
               '[--ha_ls HA_LS] [--uplink_ls UPLINK_LS] [--uplink_ip UPLINK_IP] [--uplink_subnet UPLINK_SUBNET] '
               'and the ini file options datacenter_name,edge_datastore and edge_cluster')
        return None
    dlr_name = kwargs['dlr_name']
    dlr_pwd = kwargs['dlr_pwd']
    dlr_size = kwargs['dlr_size']

    datacentermoid = get_datacentermoid(vccontent, datacenter_name)
    datastoremoid = get_datastoremoid(vccontent, edge_datastore)
    resourcepoolid = get_edgeresourcepoolmoid(vccontent, edge_cluster)

    ha_ls_name = kwargs['ha_ls_name']
    # find ha_ls_id in vDS port groups or NSX logical switches
    ha_ls_id = get_vdsportgroupid(vccontent, ha_ls_name)
    if not ha_ls_id:
        ha_ls_id, ha_ls_switch_params = get_logical_switch(client_session, ha_ls_name)
        if not ha_ls_id:
            print 'ERROR: DLR HA switch {} does NOT exist as VDS port group nor NSX logical switch'.format(ha_ls_name)
            return None

    uplink_ls_name = kwargs['uplink_ls_name']
    uplink_ip = kwargs['uplink_ip']
    uplink_subnet = kwargs['uplink_subnet']
    uplink_dgw = kwargs['uplink_dgw']
    # find uplink_ls_id in vDS port groups or NSX logical switches
    uplink_ls_id = get_vdsportgroupid(vccontent, uplink_ls_name)
    if not uplink_ls_id:
        uplink_ls_id, uplink_ls_switch_params = get_logical_switch(client_session, uplink_ls_name)
        if not uplink_ls_id:
            print 'ERROR: DLR uplink switch {} does NOT exist as VDS port group ' \
                  'nor NSX logical switch'.format(uplink_ls_name)
            return None

    dlr_id, dlr_params = dlr_create(client_session, dlr_name, dlr_pwd, dlr_size, datacentermoid, datastoremoid,
                                    resourcepoolid, ha_ls_id, uplink_ls_id, uplink_ip, uplink_subnet, uplink_dgw)
    if kwargs['verbose']:
        print dlr_params
    else:
        print 'Distributed Logical Router {} created with the Edge-ID {}'.format(dlr_name, dlr_id)
Esempio n. 5
0
def _esg_cfg_interface(client_session, vccontent, **kwargs):
    needed_params = ['vnic_index', 'esg_name']
    if not check_for_parameters(needed_params, kwargs):
        return None

    if kwargs['logical_switch'] and kwargs['portgroup']:
        print 'Both a logical switch and a portgroup were specified, please only specify one of these values'
        return None

    if kwargs['logical_switch']:
        lsid, lsparams = get_logical_switch(client_session, kwargs['logical_switch'])
        portgroup = lsid
    elif kwargs['portgroup']:
        pgid = get_vdsportgroupid(vccontent, kwargs['portgroup'])
        portgroup = pgid
    else:
        portgroup = None

    if kwargs['vnic_ip']:
        if not kwargs['vnic_mask']:
            print 'You need to specify a netmask when configuring an IP Address on the Interface'
            return None
        try:
            pflen_int = int(kwargs['vnic_mask'])
            prefixlen = pflen_int
            netmask = None
        except ValueError:
            netmask = kwargs['vnic_mask']
            prefixlen = None
    else:
        netmask = None
        prefixlen = None

    secondary_ips = None
    if kwargs['vnic_secondary_ips']:
        secondary_ips = kwargs['vnic_secondary_ips'].split(',')

    result = esg_cfg_interface(client_session, kwargs['esg_name'], kwargs['vnic_index'], name=kwargs['vnic_name'],
                               vnic_type=kwargs['vnic_type'], portgroup_id=portgroup, is_connected=kwargs['vnic_state'],
                               ipaddr=kwargs['vnic_ip'], netmask=netmask,
                               prefixlen=prefixlen, secondary_ips=secondary_ips, enable_send_redirects='false')
    if result:
        print 'Edge Services Router {} vnic{} has been configured'.format(kwargs['esg_name'], kwargs['vnic_index'])
    else:
        print 'Edge Services Router {} vnic{} configuration failed'.format(kwargs['esg_name'], kwargs['vnic_index'])
Esempio n. 6
0
def _esg_cfg_interface(client_session, vccontent, **kwargs):
    needed_params = ['vnic_index', 'esg_name']
    if not check_for_parameters(needed_params, kwargs):
        return None

    if kwargs['logical_switch'] and kwargs['portgroup']:
        print 'Both a logical switch and a portgroup were specified, please only specify one of these values'
        return None

    if kwargs['logical_switch']:
        lsid, lsparams = get_logical_switch(client_session, kwargs['logical_switch'])
        portgroup = lsid
    elif kwargs['portgroup']:
        pgid = get_vdsportgroupid(vccontent, kwargs['portgroup'])
        portgroup = pgid
    else:
        portgroup = None

    if kwargs['vnic_ip']:
        if not kwargs['vnic_mask']:
            print 'You need to specify a netmask when configuring an IP Address on the Interface'
            return None
        try:
            pflen_int = int(kwargs['vnic_mask'])
            prefixlen = pflen_int
            netmask = None
        except ValueError:
            netmask = kwargs['vnic_mask']
            prefixlen = None
    else:
        netmask = None
        prefixlen = None

    secondary_ips = None
    if kwargs['vnic_secondary_ips']:
        secondary_ips = kwargs['vnic_secondary_ips'].split(',')

    result = esg_cfg_interface(client_session, kwargs['esg_name'], kwargs['vnic_index'], name=kwargs['vnic_name'],
                               vnic_type=kwargs['vnic_type'], portgroup_id=portgroup, is_connected=kwargs['vnic_state'],
                               ipaddr=kwargs['vnic_ip'], netmask=netmask,
                               prefixlen=prefixlen, secondary_ips=secondary_ips)
    if result:
        print 'Edge Services Router {} vnic{} has been configured'.format(kwargs['esg_name'], kwargs['vnic_index'])
    else:
        print 'Edge Services Router {} vnic{} configuration failed'.format(kwargs['esg_name'], kwargs['vnic_index'])
Esempio n. 7
0
def _esg_create(client_session, vccontent, **kwargs):
    needed_params = ['esg_name', 'esg_size', 'esg_pwd', 'datacenter_name', 'edge_datastore', 'edge_cluster',
                     'portgroup']
    if not check_for_parameters(needed_params, kwargs):
        return None
    datacentermoid = get_datacentermoid(vccontent, kwargs['datacenter_name'])
    datastoremoid = get_datastoremoid(vccontent, kwargs['edge_datastore'])
    resourcepoolid = get_edgeresourcepoolmoid(vccontent, kwargs['edge_cluster'])
    portgroupmoid = get_vdsportgroupid(vccontent, kwargs['portgroup'])

    esg_id, esg_params = esg_create(client_session, kwargs['esg_name'], kwargs['esg_pwd'], kwargs['esg_size'],
                                    datacentermoid, datastoremoid, resourcepoolid, portgroupmoid,
                                    esg_remote_access=kwargs['esg_remote_access'])
    if kwargs['verbose'] and esg_id:
        edge_id, esg_details = esg_read(client_session, esg_id)
        print json.dumps(esg_details)
    elif esg_id:
        print 'Edge Service Gateway {} created with the ID {}'.format(kwargs['esg_name'], esg_id)
    else:
        print 'Edge Service Gateway {} creation failed'.format(kwargs['esg_name'])
Esempio n. 8
0
def _esg_create(client_session, vccontent, **kwargs):
    needed_params = ['esg_name', 'esg_size', 'esg_pwd', 'datacenter_name', 'edge_datastore', 'edge_cluster',
                     'portgroup']
    if not check_for_parameters(needed_params, kwargs):
        return None
    datacentermoid = get_datacentermoid(vccontent, kwargs['datacenter_name'])
    datastoremoid = get_datastoremoid(vccontent, kwargs['edge_datastore'])
    resourcepoolid = get_edgeresourcepoolmoid(vccontent, kwargs['edge_cluster'])
    portgroupmoid = get_vdsportgroupid(vccontent, kwargs['portgroup'])

    esg_id, esg_params = esg_create(client_session, kwargs['esg_name'], kwargs['esg_pwd'], kwargs['esg_size'],
                                    datacentermoid, datastoremoid, resourcepoolid, portgroupmoid,
                                    esg_remote_access=kwargs['esg_remote_access'])
    if kwargs['verbose'] and esg_id:
        edge_id, esg_details = esg_read(client_session, esg_id)
        print json.dumps(esg_details)
    elif esg_id:
        print 'Edge Service Gateway {} created with the ID {}'.format(kwargs['esg_name'], esg_id)
    else:
        print 'Edge Service Gateway {} creation failed'.format(kwargs['esg_name'])