""" Transport Example For example: python -m examples.transport \ https://region-a.geo-1.identity.hpcloudsvc.com:35357/ """ import sys from examples import common from openstack import transport def make_transport(opts): return transport.Transport(verify=opts.verify) def run_transport(opts): """Create a transport given some options.""" argument = opts.argument trans = make_transport(opts) print("transport: %s" % trans) print(trans.get(argument).text) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_transport))
return session.Session.create( username=opts.username, password=opts.password, token=opts.token, auth_url=opts.auth_url, version=opts.identity_api_version, project_name=opts.project_name, domain_name=opts.domain_name, project_domain_name=opts.project_domain_name, user_domain_name=opts.user_domain_name, verify=opts.verify, user_agent='SDKExample', region=opts.region_name, ) def run_session(opts): argument = opts.argument if argument is None: raise Exception("A path argument must be specified") sess = make_session(opts) filtration = service_filter.ServiceFilter(service_type='Identity') print("Session: %s" % sess) print(sess.get(argument, service=filtration).text) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_session))
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Find Command For example: python -m examples.find openstack/network/v2/network.py \ --data '{"id": "a1369557-748f-429c-bd3e-fc385aacaec7"}' """ import sys from examples import common from examples import session def run_find(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) obj = cls.find(sess, opts.data) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_find))
from examples.keypair import delete as keypair from examples import network def delete_jenkins(conn, name, opts): server = conn.compute.find_server(name) if server is not None: server = conn.get(server) print(str(server)) ips = server.get_floating_ips() for ip in ips: print(str(ip)) ip = conn.network.find_ip(ip) conn.network.remove_ip_from_port(ip) conn.delete(ip) conn.delete(server) keypair.delete(conn, name) network.delete(conn, name) def run_jenkins(opts): conn = connection.make_connection(opts) name = opts.data.pop('name', 'jenkins') return(delete_jenkins(conn, name, opts)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_jenkins))
For example: python -m examples.session /tenants """ import sys from examples import common from examples import connection from openstack.identity import identity_service def make_session(opts): return connection.make_connection(opts).session def run_session(opts): argument = opts.argument if argument is None: raise Exception("A path argument must be specified") sess = make_session(opts) filtration = identity_service.IdentityService() print("Session: %s" % sess) print(sess.get(argument, service=filtration).text) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_session))
if router: try: conn.network.router_remove_interface(router, subnet.id) except Exception: pass for port in conn.network.get_subnet_ports(subnet.id): print(str(port)) conn.network.delete_port(port) if router is not None: conn.network.delete_router(router) if subnet: conn.network.delete_subnet(subnet) network = conn.network.find_network(name) if network is not None: print(str(network)) conn.network.delete_network(network) def run_network(opts): name = opts.data.pop('name', 'netty') conn = connection.make_connection(opts) return (delete(conn, name)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_network))
def make_connection(opts): args = { 'auth_plugin': opts.auth_plugin, 'auth_url': opts.auth_url, 'project_name': opts.project_name, 'domain_name': opts.domain_name, 'project_domain_name': opts.project_domain_name, 'user_domain_name': opts.user_domain_name, 'user_name': opts.user_name, 'password': opts.password, 'verify': opts.verify, 'token': opts.token, } conn = connection.Connection(preference=opts.user_preferences, **args) return conn def run_connection(opts): conn = make_connection(opts) print("Connection: %s" % conn) for flavor in conn.compute.list_flavors(): print(flavor.id + " " + flavor.name) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_connection))
def get_token(self, transport, **kwargs): return self.token def get_endpoint(self, transport, service, **kwargs): return self.endpoint def make_authenticate(opts): return authenticator.create( username=opts.username, password=opts.password, token=opts.token, auth_url=opts.auth_url, version=opts.identity_api_version, project_name=opts.project_name, domain_name=opts.domain_name, project_domain_name=opts.project_domain_name, user_domain_name=opts.user_domain_name, ) def run_authenticate(opts): auth = make_authenticate(opts) xport = transport.make_transport(opts) print(auth.authorize(xport)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_authenticate))
filenamepub = filename + '.pub' args = {'name': name} pubkey = None try: with open(filenamepub, 'r') as f: pubkey = f.read() args['public_key'] = pubkey except IOError: pass kp = conn.compute.create_keypair(**args) if pubkey is None: with open(filename, 'w') as f: f.write("%s" % kp.private_key) with open(filenamepub, 'w') as f: f.write("%s" % kp.public_key) os.chmod(filename, 0o640) os.chmod(filenamepub, 0o644) print(str(kp)) return kp def run_keypair(opts): name = opts.data.pop('name', 'pare') conn = connection.make_connection(opts) return(create(conn, name)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_keypair))
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Create Command For example: python -m examples.create openstack/network/v2/network.py \ --data '{"name": "foo"}' """ import sys from examples import common from examples import session def run_create(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) obj = cls.new(**common.get_data_option(opts)) obj.create(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_create))
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Find Command For example: python -m examples.find openstack/network/v2_0/network.py \ --data '{"id": "a1369557-748f-429c-bd3e-fc385aacaec7"}' """ import sys from examples import common from examples import session def run_find(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) obj = cls.find(sess, opts.data) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_find))
# a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import sys from examples import common from examples import session def run_list(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) path_args = None if opts.data: path_args = common.get_data_option(opts) for obj in cls.list(sess, path_args=path_args): print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_list))
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Create Command For example: python -m examples.create openstack/network/v2_0/network.py \ --data '{"name": "foo"}' """ import sys from examples import common from examples import session def run_create(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) obj = cls.new(**common.get_data_option(opts)) obj.create(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_create))
filenamepub = filename + '.pub' args = {'name': name} pubkey = None try: with open(filenamepub, 'r') as f: pubkey = f.read() args['public_key'] = pubkey except IOError: pass kp = conn.compute.create_keypair(**args) if pubkey is None: with open(filename, 'w') as f: f.write("%s" % kp.private_key) with open(filenamepub, 'w') as f: f.write("%s" % kp.public_key) os.chmod(filename, 0o640) os.chmod(filenamepub, 0o644) print(str(kp)) return kp def run_keypair(opts): name = opts.data.pop('name', 'pare') conn = connection.make_connection(opts) return (create(conn, name)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_keypair))
# License for the specific language governing permissions and limitations # under the License. """ Example Delete Command For example: python -m examples.delete openstack/network/v2_0/network.py \ --data '{"id": "a1369557-748f-429c-bd3e-fc385aacaec7"}' """ import sys from examples import common from examples import session def run_delete(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) data = common.get_data_option(opts) obj = cls.new(**data) obj.delete(sess) print('Deleted: %s' % str(data)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_delete))
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Get Command For example: python -m examples.get openstack/network/v2/network.py \ --data '{"id": "a1369557-748f-429c-bd3e-fc385aacaec7"}' """ import sys from examples import common from examples import session def run_get(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) data = common.get_data_option(opts) obj = cls.new(**data) obj.get(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_get))
from examples.keypair import delete as keypair from examples.network import delete as network def delete_jenkins(conn, name, opts): server = conn.compute.find_server(name) if server is not None: server = conn.get(server) print(str(server)) ips = server.get_floating_ips() for ip in ips: print(str(ip)) ip = conn.network.find_ip(ip) conn.network.remove_ip_from_port(ip) conn.delete(ip) conn.delete(server) keypair.delete(conn, name) network.delete(conn, name) def run_jenkins(opts): conn = connection.make_connection(opts) name = opts.data.pop('name', 'jenkins') return (delete_jenkins(conn, name, opts)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_jenkins))
# License for the specific language governing permissions and limitations # under the License. """ Example Connection Command Make sure you can authenticate before running this command. For example: python -m examples.thin """ import sys from examples import common from examples import connection from openstack.network.v2 import thin def run_thin(opts): session = connection.make_connection(opts).session request = thin.Thin() for objay in request.list_networks(session): print(objay['id']) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_thin))
def invoke_method(target, method_name, params): action = getattr(target, method_name) filtered_args = filter_args(action, params) reply = action(**filtered_args) return reply def run_action(options): sess = session.make_session(options) cls = common.find_resource_cls(options) data = common.get_data_option(options) action = data.pop('action') if 'action_args' in data: args = data.pop('action_args') else: args = {} args.update(session=sess) obj = cls.new(**data) reply = invoke_method(obj, action, args) print(str(reply)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_action))
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Update Command For example: python -m examples.update openstack/network/v2/network.py \ --data '{"name": "foo"}' """ import sys from examples import common from examples import session def run_update(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) obj = cls.new(**common.get_data_option(opts)) obj.update(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_update))
# License for the specific language governing permissions and limitations # under the License. """ Example Head Command For example: python -m examples.head openstack/image/v1/image.py \ --data 9d7d22d0-7d43-481f-a7eb-d93ea2791409 """ import sys from examples import common from examples import session def run_head(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) data = common.get_data_option(opts) obj = cls.new(**data) obj.head(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_head))
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Update Command For example: python -m examples.update openstack/network/v2_0/network.py \ --data '{"name": "foo"}' """ import sys from examples import common from examples import session def run_update(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) obj = cls.new(**common.get_data_option(opts)) obj.update(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_update))
def make_connection(opts): args = { 'auth_plugin': opts.auth_plugin, 'auth_url': opts.auth_url, 'project_name': opts.project_name, 'domain_name': opts.domain_name, 'project_domain_name': opts.project_domain_name, 'user_domain_name': opts.user_domain_name, 'username': opts.username, 'password': opts.password, 'trust_id': opts.trust_id, 'verify': opts.verify, 'token': opts.token, } conn = connection.Connection(preference=opts.user_preferences, **args) return conn def run_connection(opts): conn = make_connection(opts) print("Connection: %s" % conn) for flavor in conn.compute.list_flavors(): print(flavor.id + " " + flavor.name) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_connection))
router = conn.network.find_router(name) if router is None: args = { "name": name, "external_gateway_info": {"network_id": extnet.id} } router = conn.network.create_router(**args) conn.network.router_add_interface(router, subnet.id) print(str(router)) sg = conn.network.find_security_group(name) if sg is None: sg = conn.network.create_security_group(name=name) for port in ports_to_open: conn.network.security_group_open_port(sg.id, port) conn.network.security_group_allow_ping(sg.id) print(str(sg)) return network def run_network(opts): name = opts.data.pop('name', 'netty') conn = connection.make_connection(opts) return(create(conn, name, opts)) if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_network))
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ Example Head Command For example: python -m examples.head openstack/image/v1/image.py \ --data 9d7d22d0-7d43-481f-a7eb-d93ea2791409 """ import sys from examples import common from examples import session def run_head(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) data = common.get_data_option(opts) obj = cls.new(**data) obj.head(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_head))
# License for the specific language governing permissions and limitations # under the License. """ Example Get Command For example: python -m examples.get openstack/network/v2_0/network.py \ --data '{"id": "a1369557-748f-429c-bd3e-fc385aacaec7"}' """ import sys from examples import common from examples import session def run_get(opts): sess = session.make_session(opts) cls = common.find_resource_cls(opts) data = common.get_data_option(opts) obj = cls.new(**data) obj.get(sess) print(str(obj)) return if __name__ == "__main__": opts = common.setup() sys.exit(common.main(opts, run_get))