def main():

    with open(os.path.join(os.pardir, "api/api_credentials.json"),
              "r") as creds:
        # Reads the api_credentials.json file for authentication
        keys = json.load(creds)

        # Defines the plain text API key generated in the Meraki portal
        apikey = keys[0]["apikey"]

        # Defines the root Organization id for the networks in question
        orgid = keys[0]["orgid"]

        with open(os.path.join(os.pardir, 'data/') + 'createNetwork.csv',
                  "r") as networks:
            reader = csv.reader(networks)
            next(reader, None)  # Skips the row containing headers
            for row in reader:
                name = row[1]
                tags = row[3]
                nettype = row[4]
                tz = row[2]

                # PUT - Update an administrator
                meraki.addnetwork(apikey,
                                  orgid,
                                  name,
                                  nettype=nettype,
                                  tags=tags,
                                  tz=tz)
示例#2
0
文件: merakihelper.py 项目: jda/rdnt
    def clone_net_with_devices(self, curr_net_id: str, new_net_name: str,
                               devs: List[str], kind, timezone):
        """
        create a new network by cloning network and adding/moving devices to it
        """

        org_id = self.get_my_org_id()
        res = meraki.addnetwork(self.apikey,
                                org_id,
                                new_net_name,
                                kind,
                                "",
                                timezone,
                                cloneid=curr_net_id)

        try:
            net_id = res.get("id", None)
        except AttributeError:
            # because error returns a list...
            raise NetworkNotFound(res[0])

        if not net_id:
            raise NetworkNotFound()
        for dev in devs:
            print(
                f"adding device {dev} to network {new_net_name} and removing from old network"
            )
            self.remove_device_from_network(dev)
            devaddstat = meraki.adddevtonet(self.apikey, net_id, dev)
            print(devaddstat)

        return res
示例#3
0
# Was my_name changed from default 'First Last'?
if my_name == 'First Last':
    sys.exit('Part 1: please edit your name\n')
# Have tags been added?
elif my_tags == '':
    sys.exit(('Part 1: please add some tags\n'))
# Does the network already exist?
elif my_name in network_names:
    my_netid = current_networks[network_names.index(my_name)]['id']
    print('Part 1: the network {0} already exists with ID {1}\n'.format(
        my_name, my_netid))
# Add the new network
else:
    # Call to create a newtork
    my_network = meraki.addnetwork(my_key, my_org, my_name, 'wireless',
                                   my_tags, my_time)
    my_netid = my_network['id']
    print('Part 1: created network {0} with network ID {1}\n'.format(
        my_name, my_netid))

# 2. Return the inventory for an organization

#########################
##### START EDITING #####
# Call to return the inventory for an organization
# One line similar to above line 33's call on meraki.getnetworklist()
inventory = meraki.getorginventory()
###### END EDITING ######
#########################

# Filter out used devices already allocated to networks
示例#4
0
        devices.append(line)

##valdiate the CVS contains proper information by displying the list of serials
print("Running...")
print(len(devices), "devices found!!\n----------------------")

for device in devices:
    print(device['serial'], " ", device['type'])

##Create a new network

net_name = input('Enter Network Name: ')

print('Adding network', net_name)
new_net = meraki.addnetwork(apikey, orgid, net_name,
                            'appliance wireless switch', None,
                            'America/Phoenix')

#network id of newly added network is returned in addnetwork function in a dictionary under the key 'id'

##Add all the devices to network
for dev in devices:
    meraki.adddevtonet(apikey, new_net['id'], dev['serial'])

##Update attributes
#For each device apply address, move map marker (api has a way to do this)
#APs do not  get named, however address and map marker are updated

for dev in devices:
    #if device is AP, don't update name
    if dev['type'] == '':
nettype = "wireless switch"
tz = 'America/Chicago'

#add tags for ADP Code, State, and City.
tags = adpcode + ' APITEST'


#Prompt for settings

#Search for Site first based on tags and name
print(bcolors.ACTION + 'Creating network with the name of ',bcolors.VARIABLE + name, '.', bcolors.ENDC)

#Confirm and submit


newnetwork = mer.addnetwork(apikey,selectedOrg,networkname,nettype,tags,tz,suppressprint=True)

# Get your id/name and print.
newnetworkid = newnetwork.get('id')
newnetworkname = newnetwork.get('name')
newnetworkorg = newnetwork.get('organizationId')
newnetworktag = newnetwork.get('tags')
newnetworktz = newnetwork.get('timeZone')
newnetworktype = newnetwork.get('type')

print(bcolors.RESULT, '\nYour new netowrk id is:\t',bcolors.VARIABLE, newnetworkid, bcolors.ENDC)
print(bcolors.RESULT,'It is part of the organizationId with',bcolors.VARIABLE, newnetworkorg, bcolors.ENDC)
print(bcolors.RESULT,'The following tags were assigned to the network',bcolors.VARIABLE, newnetworktag, bcolors.ENDC)
print(bcolors.RESULT,'The network is set to the ',bcolors.VARIABLE, newnetworktz, bcolors.RESULT,'timezone', bcolors.ENDC)
print(bcolors.RESULT,'Network Type is now',bcolors.VARIABLE, newnetworktype, bcolors.ENDC)