def main(self): cacontroller = Service( "cacontroller", self.options.host, enable_auth_detection=False, supports_auth_basic=False, supports_auth_oauth=True, auth=OAuth(self.options.access_code), override_auth_info_api='/api/common/1.0.0/auth_info', override_oauth_token_api='/api/common/1.0.0/oauth/token', override_services_api='/api/appliance/1.0.0/services') print("\n********** Services **********\n") path = '/api/appliance/1.0.0/services' content_dict = cacontroller.conn.json_request('GET', path) print(content_dict) print("\n********** License **********\n") path = '/api/appliance/1.0.0/status/license' content_dict = cacontroller.conn.json_request('GET', path) print(content_dict) del cacontroller.conn del cacontroller
def main(self, module): try: netprofiler = Service("netprofiler", self._host, auth=OAuth(self._access_code), supports_auth_basic=False, supports_auth_oauth=True) hostgroup_id = self.get_hostgroup_id(netprofiler, self.get_hostgroup_name()) contents = open(self._json_file, 'rb').read() content_dict = netprofiler.conn.upload( self._api_url + '/' + str(hostgroup_id), contents, method="PUT", extra_headers={'Content-Type': 'application/json'}) del netprofiler if content_dict is None: result = "Hostgroup " + self.get_hostgroup_name( ) + " successfully updated" module.exit_json(changed=False, output=result) except RvbdHTTPException as e: results = "Error retrieving information on '{}'".format( self.api_url) module.fail_json(changed=False, msg=results, reason=str(e))
def main(self): """ Get a report of all devices in the SCC inventory """ scc = SCC(host=self.options.scc, auth=OAuth(self.options.access_code)) report = AppliancesReport(scc) report.run() devices = [] for device in report.data: if device['product_code'] == 'SH' or device['product_code'] == 'EX': ip = self.appliance_report_get_primary_interface(device) try: devices.append((ip, device['hostname'])) #self.process_steelhead((ip, device['hostname'])) except KeyError: pass print('Starting with ' + str(self.options.threads) + ' at a time.') try: pool = mp.Pool(processes=self.options.threads, initializer=process_init) pool_outputs = pool.map(unwrap_self_process_steelhead, zip([self] * len(devices), devices)) pool.close() pool.join() except KeyboardInterrupt: pool.terminate() pool.join()
def main(self): cac = Service("appliance", self.host, auth=OAuth(self.access_code)) path = self.api_url content_dict = cac.conn.json_request('GET', path) del cac return content_dict
def main(self, module): try: cac = Service("cac", self.host, auth=OAuth(self.access_code)) path = self.api_url content_dict = cac.conn.json_request('GET', path) del cac module.exit_json(changed=False, output=content_dict) except RvbdHTTPException as e: results = "Error retrieving information on '{}'".format( self.api_url) module.fail_json(changed=False, msg=results, reason=str(e))
def main(self): cac = Service("appliance", self.options.host, auth=OAuth(self.options.oauth)) print("\n********** Services **********\n") path = '/api/appliance/1.0.0/services' content_dict = cac.conn.json_request('GET', path) print(content_dict) print("\n********** License **********\n") path = '/api/appliance/1.0.0/status/license' content_dict = cac.conn.json_request('GET', path) print(content_dict) del cac
def main(self, module): try: netprofiler = Service("netprofiler",self.host, auth=OAuth(self.access_code),supports_auth_basic=False,supports_auth_oauth=True) contents = open(self.json_file, 'rb').read() content_dict = netprofiler.conn.upload(self.api_url, contents, extra_headers={'Content-Type': 'application/json'}) del netprofiler result = content_dict['Location-Header'].replace("/api/profiler/1.14/host_group_types/", '') module.exit_json(changed=True,output="Hostgroup created with id: "+result) except RvbdHTTPException as e: if e.status == 409: results="EPG hostgroup already exists!" module.fail_json(changed=False,msg=results,reason=str(e)) else: results = "Error retrieving information on '{}'".format(self.api_url) module.fail_json(changed=False, msg=results, reason=str(e))
def validate_args(self): """ Hook for subclasses to add their own option/argument validation """ super(Application, self).validate_args() if self.has_standard_options: if self.options.oauth and (self.options.username or self.options.password): self.parser.error('Username/Password are mutually exclusive ' 'from OAuth tokens, please choose only ' 'one method.') elif self.options.oauth: self.auth = OAuth(self.options.oauth) else: self.auth = UserAuth(self.options.username, self.options.password) steelscript.common.connection.Connection.HTTPLIB_DEBUGLEVEL = ( self.options.httplib_debuglevel) steelscript.common.connection.Connection.DEBUG_MSG_BODY = ( self.options.debug_msg_body)
def validate_args(self): """ Hook for subclasses to add their own option/argument validation """ super(Application, self).validate_args() if self.has_conn_options: if self.options.oauth and (self.options.username or self.options.password): self.parser.error('Username/Password are mutually exclusive ' 'from OAuth tokens, please choose only ' 'one method.') elif self.options.oauth: self.auth = OAuth(self.options.oauth) else: self.auth = UserAuth(self.options.username, self.options.password) if self.has_log_options: steelscript.common.connection.Connection.REST_DEBUG = ( self.options.rest_debug) steelscript.common.connection.Connection.REST_BODY_LINES = ( self.options.rest_body_lines)
def validate_args(self): """ Hook for subclasses to add their own option/argument validation """ super(Application, self).validate_args() if self.has_conn_options: # check to see if we've added credentials to the class # itself, and use those as defaults if nothing passed in via # the command line options if self.username and not self.options.username: self.options.username = self.username if self.password and not self.options.password: self.options.password = self.password if self.oauth and not self.options.oauth: self.options.oauth = self.oauth if self.options.oauth and (self.options.username or self.options.password): self.parser.error('Username/Password are mutually exclusive ' 'from OAuth tokens, please choose only ' 'one method.') elif self.options.oauth: self.auth = OAuth(self.options.oauth) elif not self.options.username or not self.options.password: self.parser.error('Authentication credentials required: ' 'either username/password or OAuth token.') else: self.auth = UserAuth(self.options.username, self.options.password) if self.has_log_options: steelscript.common.connection.Connection.REST_DEBUG = ( self.options.rest_debug) steelscript.common.connection.Connection.REST_BODY_LINES = ( self.options.rest_body_lines)
def setup(self): super(SCCApp, self).setup() self.scc = SCC(host=self.options.host, auth=OAuth(self.options.access_code))