Package: packet-python
Equinix MetalA Python client for the Equinix Metal API.This repository isMaintainedmeaning that this software is supported by Equinix Metal and its community - available to use in production environments.Table of ContentsInstallationDocumentationAuthenticationExamplesList ProjectsList PlansCreating a DeviceChecking the Status and Rebooting a DeviceListing all Devices Limiting to 50 per PageUpdating a DeviceDeleting a DeviceCreating a Device BatchCreating a VolumeAttaching and Detaching a VolumeCreating and Restoring a Volume SnapshotListing Project IP AddressesCreating a Project for an OrganizationCreating a VLANContributingCopyrightChangesInstallationThe Equinix Metal python api library can be installed using pip:pip install packet-pythonPackage information available here:https://pypi.python.org/pypi/packet-pythonDocumentationFull Equinix Metal API documenation is available here:https://metal.equinix.com/developers/api/AuthenticationProvide your credentials when instantiating client:importpacketmanager=packet.Manager(auth_token="yourapiauthtoken")ExamplesList Projectsimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")projects=manager.list_projects()forprojectinprojects:print(project)List Plansimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")plans=manager.list_plans()forplaninplans:print(plan)if'cpus'inplan.specs:print(plan.specs['cpus'][0]['count'])Creating a Deviceimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")device=manager.create_device(project_id='project-id',hostname='node-name-of-your-choice',plan='baremetal_1',metro='sv',operating_system='ubuntu_18_04')print(device)Checking the Status and Rebooting a Deviceimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")device=manager.get_device('device-id')print(device.state)device.reboot()Listing all Devices Limiting to 50 per PageEquinix Metal API defaults to a limit of 10 per pageimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")params={'per_page':50}devices=manager.list_devices(project_id='project_id',params=params)print(devices)Updating a Deviceimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")device=manager.get_device('device-id')device.hostname="test02"device.description="new description"device.update()Deleting a Deviceimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")device=manager.get_device('device-id')device.delete()Creating a Device Batchimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")batch01=packet.DeviceBatch({"hostname":"batch01","quantity":2,"facility":"ams1","operating_system":"centos_7","plan":"baremetal_0",})device_batch=manager.create_batch(project_id="project_id",params=[batch01])print(device_batch)Creating a Volumeimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")volume=manager.create_volume(project_id="project-id",description="volume description",plan="storage_1",size="100",facility="ewr1",snapshot_count=7,snapshot_frequency="1day")print(volume)Attaching and Detaching a Volumeimportpacketimporttimemanager=packet.Manager(auth_token="yourapiauthtoken")volume=manager.get_volume("volume_id")volume.attach("device_id")whileTrue:ifmanager.get_device("device_id").state=="active":breaktime.sleep(2)volume.detach()Creating and Restoring a Volume Snapshotimportpacketimporttimemanager=packet.Manager(auth_token="yourapiauthtoken")volume=manager.get_volume("volume_id")volume.create_snapshot()whileTrue:ifmanager.get_volume(volume.id).state=="active":breaktime.sleep(2)snapshots=manager.get_snapshots(volume.id)volume.restore(snapshots[0].timestamp)Listing Project IP Addressesimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")ips=manager.list_project_ips("project_id")foripinips:print(ip.address)Creating a Project for an Organizationimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")project=manager.create_organization_project(org_id="organization_id",name="Integration Tests",customdata={"tag":"QA"})print(project)Creating a VLANimportpacketmanager=packet.Manager(auth_token="yourapiauthtoken")vlan=manager.create_vlan(project_id="project_id",facility="ewr1")print(vlan)ContributingCheck out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.Fork the project.Start a feature/bugfix branch.Commit and push until you are happy with your contribution.You can test your changes with thetox, which is what GitHub Actions use to check builds.CreditsCargoCulted with much gratitude from:https://github.com/koalalorenzo/python-digitaloceanChangesSee theChangelogfor further details.ChangelogAll notable changes to this project will be documented in this file.The format is based onKeep a Changelog.
This project adheres toSemantic Versioning.[1.45.0] - UnreleasedAddedChangedFixed[1.44.3] - 2022-07-27FixedFix handling non-dict error data in ResponseError #128 #129[1.44.2] - 2021-11-18FixedFix logic behindvalidate_metro_capacity#125[1.44.1] - 2021-09-20FixedFix metros URL used in Metro API lists #122Catch TypeError when HardwareReservations do not have a device assignment #120[1.44.0] - 2021-05-19AddedUser-Agent header added to client requests #113Metroclass added (https://feedback.equinixmetal.com/changelog/new-metros-feature-live) #110Addsmetroproperty toDeviceBatch,Device,IPAddress,VLan#110Addsmetrotocreate_device,reserve_ip_address,create_vlan,create_connection#110Addslist_metros,validate_metro_capacitytoManager#110AddsCODE_OF_CONDUCT.md,SUPPORT.md,OWNERS.md#102, #101, #100Adds package metadata forauthor,author_email,copyright#114Changedfacilityis now optional increate_device,reserve_ip_address,create_vlan,create_connection#110CI is using GH Actions instead of Drone #115FixedHandles when IPAddress Facility is null in API responses #117[1.43.1] - 2020-09-04FixedResponseError fixed for Python2.7 compatibility[1.43.0] - 2020-07-14AddedSupport for reinstalling the operating system to a device, including changing the operating system.Manager.create_vlannow includes a description argumentChangedResponseErrorwill now be raised when an API call results in an errorFixedManager.validate_capacitynow considers availabilityManager.create_project_ssh_keywill retry when it encounters 404 responses following a successful creation.API responses with{"error":""}keys were not handled well, and will now be handled just like{"errors":[""]}keys.[1.42.0] - 2020-02-14AddedCapturing ofavailable_into PlanCapturing ofhardware_reservation,spot_price_max,termination_time, andprovisioning_percentagetoDeviceSupport for creating project ssh keysSupport for passingcustom_datawhen creating a deviceFixedBlack not building for CI and thus failing[1.41.0] - 2019-10-16AddedSupport for retrieval of hardware reservationsCPR support at device creation[1.40.0] - 2019-10-14AddedIntegration tests are only run ifPACKET_PYTHON_TEST_ACTUAL_APIenvvar is setRescue action and along with testMissing SPDX and source encoding meta commentsRemovedUse of Travis CI[1.39.1] - 2019-09-17AddedSupport forhardware_reservation_id[1.39.0] - 2019-08-26AddedSupport for Organizations, Events, Emails, VLAN, Snapshot Policies, Batches, Ports, VPN and IPs.Live tests[1.38.2] - 2019-05-30AddedTest fixtures to sdist[1.38.1] - 2019-05-30FixedChangelog[1.38.0] - 2019-05-30AddedSupport for python3.7legacyparam toget_capacityfunctionRemovedSupport for python3.3Changedsetup.py no longer converts markdown to reST because pypi now supports markdown, woop.[1.37.1] - 2018-01-08FixedVersion number in setup.py[1.37.0] - 2018-01-08AddedSpot Market SupportAbility to specify ssh keys on device creation[1.36.0] - 2017-10-16AddedBetter tests using PacketMockManagerTest on 2.7 and 3.[3-6]ChangelogChangedUse tox for testing[1.35] - 2017-08-04FixedSome tests were broken[1.35]Addedpublic_ipv4_subnet_size[1.34] - 2017-08-04AddedCustom iPXE andalways_pxesettingVolume coloningDevice TagsFixedHandling of error messages from api response[1.33] - 2017-03-15FixedDefault payment method