Skip to content

Instantly share code, notes, and snippets.

@bpceee
Last active August 29, 2015 14:06
Show Gist options
  • Save bpceee/ce49be7551ef6b56251c to your computer and use it in GitHub Desktop.
Save bpceee/ce49be7551ef6b56251c to your computer and use it in GitHub Desktop.
qingcloud update router
import qingcloud.iaas
from qingcloud.iaas.router_static import RouterStaticFactory
access_key = 'xxx'
secret_key = 'xxx'
conn = qingcloud.iaas.connect_to_zone('gd1', access_key, secret_key)
router = 'rtr-xxxxxxxx'
# add port forwarding static
static = RouterStaticFactory.create(RouterStaticFactory.TYPE_PORT_FORWARDING,
router_static_name='test port forwarding', protocol='tcp',
src_port='80', dst_ip='192.168.1.2', dst_port=80)
statics = [static.to_json()]
ret = conn.add_router_statics(router, statics)
if ret['ret_code'] == 0:
print 'successfully add router statics'
# update router
conn.update_routers([router])
if ret['ret_code'] == 0:
print 'successfully update router'
# describe statics
ret = conn.describe_router_statics(router=router)
statics = [s['router_static_id'] for s in ret['router_static_set']]
print 'router statis:', statics
# delete statics
conn.delete_router_statics(statics)
if ret['ret_code'] == 0:
print 'successfully delete router statics'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment